@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
80 lines (79 loc) • 3.27 kB
TypeScript
import type { HealthMetrics } from "../types/index.js";
export declare class TelemetryService {
private static instance;
private tracerProvider?;
private enabled;
private initialized;
private usingExternalTracerProvider;
private meter?;
private tracer?;
private aiRequestCounter?;
private aiRequestDuration?;
private aiTokensUsed?;
private aiProviderErrors?;
private aiCostUsd?;
private mcpToolCalls?;
private connectionCounter?;
private responseTimeHistogram?;
private activeConnectionCount;
private errorCount;
private requestCount;
private totalResponseTime;
private responseTimeCount;
private static readonly MAX_PENDING_CALLS;
private pendingCalls;
private isReady;
private droppedPendingCallWarned;
/** The in-flight (or already-settled) async init. Never rejects — see
* initializeTelemetry()'s catch block, which always resolves normally.
* `initialize()`/`shutdown()` await it so they don't race construction. */
private readyPromise?;
private constructor();
static getInstance(): TelemetryService;
private isTelemetryEnabled;
private hasExternalTracerProvider;
private adoptExternalTracerProvider;
private initializeTelemetry;
private initializeMetrics;
private bufferPendingCall;
/** Instruments now exist — drain anything buffered while we waited, in
* order, then flip fully sync for every call after this one. */
private markReady;
private discardPendingCalls;
initialize(): Promise<void>;
/**
* @deprecated Vercel AI SDK's experimental_telemetry creates ai.generateText/ai.streamText
* spans automatically via OpenTelemetry. Using this method would create duplicate spans.
* Kept for potential future use with non-Vercel providers (e.g., Amazon Bedrock).
* See: TelemetryHandler.getTelemetryConfig() for the active telemetry path.
*/
traceAIRequest<T>(provider: string, operation: () => Promise<T>, operationType?: string): Promise<T>;
recordAIRequest(provider: string, model: string, tokens: number, duration: number, cost?: number): void;
private emitAIRequest;
recordAIError(provider: string, error: Error): void;
private emitAIError;
recordMCPToolCall(toolName: string, duration: number, success: boolean): void;
private emitMCPToolCall;
recordConnection(type: "websocket" | "sse" | "http"): void;
private emitConnection;
recordConnectionClosed(type: "websocket" | "sse" | "http"): void;
private emitConnectionClosed;
recordResponseTime(endpoint: string, method: string, duration: number): void;
private emitResponseTime;
recordCustomMetric(name: string, value: number, labels?: Record<string, string>): void;
private emitCustomMetric;
recordCustomHistogram(name: string, value: number, labels?: Record<string, string>): void;
private emitCustomHistogram;
getHealthMetrics(): Promise<HealthMetrics>;
isEnabled(): boolean;
getStatus(): {
enabled: boolean;
initialized: boolean;
endpoint?: string;
service?: string;
version?: string;
};
private getDurationBucket;
private getStatusBucket;
shutdown(): Promise<void>;
}