Defjs
OpenTelemetry Server

OpenTelemetryServerWebSocketOptions

Options for the WebSocket transport — the shared options plus queryPropagation.

@defjs/opentelemetry-server · Type

Signature

interface OpenTelemetryServerWebSocketOptions extends OpenTelemetryServerTransportOptions<WebSocketSessionLike> {
  queryPropagation?: boolean;
}

Set on webSocket in OpenTelemetryServerOptions. enabled, startSpanHook, requestHook and responseHook come from OpenTelemetryServerTransportOptions; responseHook(span, session, req) receives the opened WebSocketSessionLike and the original HttpRequest.

queryPropagation defaults to false: the WebSocket query string is left unchanged and no trace context or baggage is written into the URL. Browser WebSocket clients usually cannot set headers, so enabling it writes the propagated context to the end of the query string, replacing any parameter of the same name. Query strings can be recorded by proxies, access logs and APM tools, and baggage values can be sensitive. Turn it on only after you accept that exposure.

WebSocket is traced at connection level. The span stays open until session.closed settles. It records websocket.connected, then websocket.closed for a normal close or websocket.error. A close frame from the server counts as normal with any code, including 1011. An abrupt drop without a close frame (1006) is normal only where the runtime reports no socket error before close (Bun); where it does (Node.js), the session ends in error and logs once. A caller abort of an open session is also websocket.error: the span ends ERROR and no log is emitted. error.type follows the abort reason: AbortError for a default abort(), the Error.name of an Error reason, string for a string reason. An abort while the WebSocket is still connecting ends the span ERROR with error.type DefjsFault. No per-message spans are created.

Pass { enabled: false } to skip WebSocket instrumentation. Span hooks run only when a tracer is supplied.

Members

Prop

Type

queryPropagation? boolean | undefined

Inject trace context into the WebSocket URL query string. Defaults to false; enable only after reviewing URL propagation exposure.

enabled? boolean | undefined

Whether this transport's instrumentation is enabled. Defaults to true.

startSpanHook? ((request: HttpRequest) => Attributes) | undefined

Add application attributes when the client span is created.

requestHook? ((span: Span, req: HttpRequest) => Promise<void> | void) | undefined

Customize the client span before the request is sent.

responseHook? ((span: Span, res: WebSocketSessionLike, req: HttpRequest) => Promise<void> | void) | undefined

Customize the client span after the transport result is returned.

Edit this page on GitHub
Released under the MIT License. · Copyright © 2026 MunMunMiao