OpenTelemetry instrumentation for the `ws` WebSocket library, providing automatic tracing of socket lifecycle events: opens, closes, sends, and optionally messages. Current version 0.5.0 is stable, released monthly. Differentiates from manual instrumentation by patching the `ws` module transparently, supporting both client (`WebSocket`) and server (`ws.Server`) sides, and offering hooks for custom attributes. Requires `ws@^8.5.0` as a peer dependency and the OpenTelemetry Node SDK.
npm install opentelemetry-instrumentation-wsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Setup auto-tracing for ws WebSocket client with send spans and message events enabled.
Move registerInstrumentations call to the very top of your entry file, before any imports that pull in 'ws'.
Set sendSpans: true and/or messageEvents: true in WSInstrumentation config if you need those spans.
Switch to ESM imports. For CommonJS projects, use dynamic import: const { WSInstrumentation } = await import('opentelemetry-instrumentation-ws');Ensure you use ws.Server and its handleUpgrade method for automatic tracing of upgrades.
Ensure you are using the 'ws' library version ^8.5.0 and not the browser-native WebSocket.
Use import syntax (ESM) or import dynamically: const { WSInstrumentation } = await import('opentelemetry-instrumentation-ws');Run 'npm install opentelemetry-instrumentation-ws' and ensure it's in your package.json dependencies.