opentelemetry-instrumentation-socket.io
TypeScript icon, indicating that this package has built-in type declarations

0.34.0 • Public • Published

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:

Options Type Description
emitHook SocketIoHookFunction hook for adding custom attributes before socket.io emits the event
emitIgnoreEventList string[] names of emitted events to ignore tracing for
onHook SocketIoHookFunction hook for adding custom attributes before the event listener (callback) is invoked
onIgnoreEventList string[] names of listened events to ignore tracing for
traceReserved boolean set to true if you want to trace socket.io reserved events (see https://socket.io/docs/v4/emit-cheatsheet/#Reserved-events)
filterHttpTransport HttpTransportInstrumentationConfig set 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:

Options Type Description
httpInstrumentation HttpInstrumentation the instance of HttpInstrumentation you pass to registerInstrumentations
socketPath string the socket.io endpoint path (defaults to /socket.io/)

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

Package Sidebar

Install

npm i opentelemetry-instrumentation-socket.io

Weekly Downloads

3,051

Version

0.34.0

License

Apache-2.0

Unpacked Size

79 kB

Total Files

16

Last publish

Collaborators

  • aspecto-release-bot