NodeJS Instrumentation
OpenTelemetry trace instrumentation for the NodeJS application can be enabled either through auto instrumentation or manual instrumentation. It is recommended to use auto-instrumentation unless you have specific reasons not to do so.
We recommend using auto instrumentation. Please follow the steps mentioned below to enable auto instrumentation for NodeJS.
Please include the following dependency in the package.json
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/auto-instrumentations-node": "^0.36.0"
while launching the app please include the --require parameter as mentioned below
node --require @opentelemetry/auto-instrumentations-node/register
In case you have issues or you want to include only specific instrumentation you can do this by adding the following nodejs code into a file tracing.js
Please note that you may have to include the following dependency in your package.json incase you are adding the above code.
"@opentelemetry/auto-instrumentations-node": "^0.36.0", "@opentelemetry/exporter-trace-otlp-grpc": "^0.36.0"
While launching the nodejs application you add --require parameter as below
node --require tracing.js app.js
Please set the following environment variables
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=your-otel-collector-endpoint
OTEL_RESOURCE_ATTRIBUTES="service.name=your-service-name,service.namespace=your-service-namespace"
In case you need further details on nodejs instrumentation please refer here
Last updated