2.0.0 • Published 1 year ago

@totalsoft/opentelemetry-instrumentation-ws v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

opentelemetry-instrumentation-ws

This package provides opentelemetry instrumentation for ws library.

Installation

npm i @totalsoft/opentelemetry-instrumentation-ws

or

yarn add @totalsoft/opentelemetry-instrumentation-ws

Usage

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { WSInstrumentation } = require('@totalsoft/opentelemetry-instrumentation-ws');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new WSInstrumentation(),
  ],
});

Config

The ws instrumentation has few options available to choose from. You can set the following:

OptionsTypeDescription
generateSendSpansbooleanshould the tracing library add spans for each sent message. Default: false
generateReceiveSpansbooleanshould the tracing library add spans for each incoming message. Default: false
sendHook(span: Span, hookInfo: HookInfo) => voidhook for adding custom attributes to the ws send span when a websocket sends a message
closeHook(span: Span, hookInfo: HookInfo) => voidhook for adding custom attributes to the ws close span when a websocket is imperatively closed
handleUpgradeHook(span: Span, hookInfo: HookInfo) => voidhook for adding custom attributes to the ws.Server handleUpgrade span when a socket is opened against a server
maxMessageLengthnumbermax message length in the message attribute. "..." is added to the end when the message is truncated. Set 0 to omit the message attribute. Default: 1022.