import { Tracer } from '@opentelemetry/api'; import WebSocket from 'isomorphic-ws'; import { ISocket, SocketError, SocketMessage } from './socket.js'; import { GenericMiddleware, ISocketClient, MethodHandler, MethodHandlers, RequestContextBase, SocketTimeouts } from './types.js'; /** * @deprecated Use `TracedSocket` from `@superblocksteam/telemetry` instead. * This class will be removed in a future version. * * Migration: * ```typescript * // Before * import { TracedSocket } from '@superblocksteam/shared'; * * // After * import { TracedSocket, getTelemetryInstance } from '@superblocksteam/telemetry'; * const { policyEvaluator } = getTelemetryInstance(); * new TracedSocket(ws, handlers, middlewares, { requestHeaders, policyEvaluator }, options); * ``` */ export declare class TracedSocket extends ISocket { /** * The TracedSocket class extends the ISocket class to add tracing capabilities for each connection. It manages * spans for handler calls to provide detailed tracing information. * * Unlike Express, the ISocket handler call chain is fully recursive. This recursion makes it challenging to determine * when to create and end spans for specific handlers, as handlers may call other handlers before returning a result. * * An example span for recursive call * Main span ---------------------------------------------------------------------------------- * Handler1 ---------------------------------------------------------------------------- * Handler2 ---------------------------------------------------------------------- * * To manage this, we keep a reference to the most recently created span and complete that span when we go one step deeper into the recursion. * This approach works for now since we don't support much parallelism, but it will need to be updated when we start handling requests concurrently. * * An example span for recursive call after the above fixes * Main span ---------------------------------------------------------------------------------- * Handler1 ----------------------------- * Handler2 ------------------------------------------------ * */ private activeSpanByRequestId; private middlewareSpanByReqId; private lastActiveSpan; private tracer; constructor(ws: WebSocket, requestHandlers: MethodHandlers, globalMiddlewares: GenericMiddleware[], tracer: Tracer, options: { onClose: (event: WebSocket.CloseEvent) => void; timeouts?: SocketTimeouts; logger?: { error: (message?: string) => void; info: (message?: string) => void; warn: (message?: string) => void; }; getAbortSignal?: () => AbortSignal | undefined; }); protected callHandler(handler: MethodHandler, params: Params, ctx: RequestContext, client: ISocketClient, next: () => Promise): Promise; protected handleMessage(message: SocketMessage): Promise; request(method: string, params: Params, authorization?: string): Promise; protected decorateToSend(message: SocketMessage): SocketMessage; protected respond(requestId: number, result: Result): void; protected respondError(requestId: number, error: SocketError, exception?: Error): void; private addEvent; close(reason?: string): void; } //# sourceMappingURL=tracedSocket.d.ts.map