0.34.0 • Published 1 year ago

opentelemetry-instrumentation-socket.io v0.34.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

OpenTelemetry socket.io Instrumentation for Node.js

NPM version

This module provides automatic instrumentation for socket.io.

Installation

npm install --save opentelemetry-instrumentation-socket.io

Usage

For further automatic instrumentation instruction see the @opentelemetry/instrumentation package.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { SocketIoInstrumentation } = require('opentelemetry-instrumentation-socket.io');

registerInstrumentations({
  tracerProvider,
  instrumentations: [
    new SocketIoInstrumentation({
      // see under for available configuration
    })
  ]
});

socket.io Instrumentation Options

socket.io instrumentation has few options available to choose from. You can set the following:

OptionsTypeDescription
emitHookSocketIoHookFunctionhook for adding custom attributes before socket.io emits the event
emitIgnoreEventListstring[]names of emitted events to ignore tracing for
onHookSocketIoHookFunctionhook for adding custom attributes before the event listener (callback) is invoked
onIgnoreEventListstring[]names of listened events to ignore tracing for
traceReservedbooleanset to true if you want to trace socket.io reserved events (see https://socket.io/docs/v4/emit-cheatsheet/#Reserved-events)
filterHttpTransportHttpTransportInstrumentationConfigset if you want to filter out the HTTP traces when using HTTP polling as the transport (see below)

HttpTransportInstrumentationConfig

If you use opentelemetry-instrumentation-socket.io alongside instrumentation-http, socket.io might use HTTP polling as the transport method. Therefore, you will see an HTTP span created as the parent of the socket.io span. To filter out those spans; we use HttpTransportInstrumentationConfig.

HttpTransportInstrumentationConfig has a few options available to choose from. You can set the following:

OptionsTypeDescription
httpInstrumentationHttpInstrumentationthe instance of HttpInstrumentation you pass to registerInstrumentations
socketPathstringthe socket.io endpoint path (defaults to /socket.io/)

This extension (and many others) was developed by Aspecto with ❤️