JavaScript OpenTelemetry Auto-Instrumentation
You can instrument your JavaScript/NodeJS services by using either the official OpenTelemetry distribution (recommended) or the Sumo Logic Distribution for OpenTelemetry JS.
Option 1: Auto-instrumentation using official OpenTelemetry for JS
The OpenTelemetry-JS community supports all active versions of NodeJS. See a list of supported runtimes.
The instructions below apply to the OpenTelemetry JavaScript Instrumentation in version 1.9.0/0.48.0.
There are a few simple steps to instrument your application and obtain telemetry data.
Packages installation
You must install the packages listed below to apply the instrumentation and export telemetry data.
npm install --save @opentelemetry/api@1.9.0
npm install --save @opentelemetry/auto-instrumentations-node@0.48.0
Instrumentation configuration
After successful installation of the packages, it is important to properly configure instrumentation. Configuration is set through environment variables.
- Disables the metrics exporter:
OTEL_METRICS_EXPORTER=none
- Sets the exporter to OTLP:
OTEL_TRACES_EXPORTER=otlp
- Configures the endpoint where telemetry data will be sent:
This should be the OpenTelemetry Collector/Agent endpoint address or OTLP/HTTP source. For Kubernetes environments, see the available endpoints for a direct connection. For other environments, see endpoints and protocols.
OTEL_EXPORTER_OTLP_ENDPOINT=http://OTLP_ENDPOINT:4318
- Configures the service name. Ensure the string value represents its business logic, such as "FinanceServiceCall". This will appear as a tracing service name in Sumo Logic.
OTEL_SERVICE_NAME=SERVICE_NAME
- Configure the application name. This will appear as a tracing application name in Sumo Logic. Additional attributes can be added here as comma-separated key=value pairs.
OTEL_RESOURCE_ATTRIBUTES=application=APPLICATION_NAME
- Configure the resource detectors. Additional attributes related to environment are added to the spans.
OTEL_NODE_RESOURCE_DETECTORS="env,host,os"
Application execution
When everything is configured, it is very simple to run an instrumented application.
node --require @opentelemetry/auto-instrumentations-node/register your-js-script.js
Option 2: Auto-instrumentation using Sumo Logic OpenTelemetry for JS distro (Basic)
Sumo Logic provides its own distribution for OpenTelemetry (OT) JS tracing instrumentation. It is fully compatible with official OT package and free to use also with other vendor backends. This method is recommended as it makes installation easy, straightforward, and quick with a "just-works" scenario. It is provided as all-in-one runner for node.js projects used to enable OpenTelemetry auto-instrumentation with OTLP HTTP exporter.
Setup
Instead of running your script like node index.js
, use the following command:
npx @sumologic/opentelemetry-node index.js
Your index.js
file will run automatically with a started @opentelemetry/sdk-node
.
Remember to provide configuration using environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT
. Must be provided with the location of the OpenTelemetry Collector/Agent (recommended for production) or OTLP/HTTP source. If you haven't yet installed a collector, refer to the following setup instructions:OTEL_SERVICE_NAME
. A logical service name that represents its business logic.OTEL_RESOURCE_ATTRIBUTES
. Set "application" name attribute which should represent its business logic and extra attributes attached to all spans. Add thedeployment.environment=[environment-name]
tag as needed to allow for filtering by environment on dashboard panels. For more information, see Services Dashboard Panels.
Example:
OTEL_SERVICE_NAME=api
OTEL_RESOURCE_ATTRIBUTES="application=banking-app,deployment.environment=dev"
OTEL_EXPORTER_OTLP_ENDPOINT=http://examplehost:4318
npx @sumologic/opentelemetry-node index.js
To speed up the npx @sumologic/opentelemetry-node
command, you can do:
npm i -g @sumologic/opentelemetry-node
Instrumented packages
The Sumo Logic OpenTelemetry for JS instrumentation enables all officially supported core and contrib auto-instrumentation plugins defined in @opentelemetry/auto-instrumentations-node, including:
- opentelemetry/instrumentation-amqplib
- opentelemetry/instrumentation-aws-lambda
- opentelemetry/instrumentation-aws-sdk
- opentelemetry/instrumentation-bunyan
- [opentelemetry/instrumentation-cassandra-driver](https://www.npmjs.com/package/@opentelemetry/instrumentation-cassandra-driver
- opentelemetry/instrumentation-connect
- [opentelemetry/instrumentation-cucumber](https://www.npmjs.com/package/@opentelemetry/instrumentation-cucumber
- opentelemetry/instrumentation-dataloader
- opentelemetry/instrumentation-dns
- opentelemetry/instrumentation-express
- opentelemetry/instrumentation-fastify
- opentelemetry/instrumentation-fs
- opentelemetry/instrumentation-generic-pool
- opentelemetry/instrumentation-graphql
- opentelemetry/instrumentation-grpc
- opentelemetry/instrumentation-hapi
- opentelemetry/instrumentation-http
- opentelemetry/instrumentation-ioredis
- opentelemetry/instrumentation-knex
- opentelemetry/instrumentation-koa
- opentelemetry/instrumentation-lru-memoizer
- opentelemetry/instrumentation-memcached
- opentelemetry/instrumentation-mongodb
- opentelemetry/instrumentation-mongoose
- opentelemetry/instrumentation-mysql
- opentelemetry/instrumentation-mysql2
- opentelemetry/instrumentation-nestjs-core
- opentelemetry/instrumentation-net
- opentelemetry/instrumentation-pg
- opentelemetry/instrumentation-pino
- opentelemetry/instrumentation-redis
- opentelemetry/instrumentation-redis-4
- opentelemetry/instrumentation-restify
- opentelemetry/instrumentation-router
- opentelemetry/instrumentation-socket.io
- opentelemetry/instrumentation-tedious
- opentelemetry/instrumentation-undici
- opentelemetry/instrumentation-winston
Limitations
- Only OTLP/HTTP proto exporter is supported
- Only W3C context propagation is supported
- Support for logs and metrics requires instrumentation using official OpenTelemetry for JS