Skip to main content

Node.js Instrumentation

Use the OpenTelemetry auto-instrumentation libraries to automatically capture telemetry from popular libraries and frameworks for your Node.js application - without modifying your application code.

Overview

The OpenTelemetry Node.js auto-instrumentation can capture telemetry data at the "edges" of your application, such as:

  • Inbound HTTP requests
  • Outbound HTTP calls
  • Database calls (MongoDB, PostgreSQL, MySQL, etc.)
  • Express and other web framework operations
  • And many other popular frameworks and libraries

Prerequisites

  • Node.js 14 or higher
  • An active Oodle instance

Getting Started

Step 1: Get Your Oodle Configuration

In the Oodle UI, navigate to the Settings page and click on Connect in the Open Telemetry tile and copy the provided configuration snippet which includes your metrics endpoint and API key

Open Telemetry Configuration

Step 2: Choose Your Setup Approach

The simplest way to get started - no instrumentation code required. Just install the package and configure via environment variables.

Install the package:

npm install @opentelemetry/auto-instrumentations-node

Set environment variables:

export OTEL_SERVICE_NAME=<YOUR_SERVICE_NAME>
export OTEL_EXPORTER_OTLP_ENDPOINT=<OODLE_OTEL_ENDPOINT>
export OTEL_EXPORTER_OTLP_HEADERS="X-API-KEY=<OODLE_API_KEY>"
export OTEL_METRICS_EXPORTER=otlp
export OTEL_TRACES_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=none

Run your application:

node --require @opentelemetry/auto-instrumentations-node/register server.js

Or in package.json:

{
"scripts": {
"start": "node --require @opentelemetry/auto-instrumentations-node/register server.js"
}
}
Limitations

The zero-code approach uses default settings. For custom export intervals, selective instrumentation control, or advanced configuration, use the instrumentation.js file approach.

Supported Instrumentations

The Node.js auto-instrumentation package supports many popular libraries and frameworks:

  • HTTP/HTTPS: Express, Koa, Fastify, Hapi, Restify
  • Databases: MongoDB, PostgreSQL, MySQL, Redis, Cassandra
  • Messaging: Kafka, RabbitMQ, AWS SQS
  • Cloud Services: AWS SDK, Google Cloud, Azure

For a complete list, see the OpenTelemetry Node.js Instrumentation documentation.

Configuration Options

Enabling and Disabling Specific Instrumentations

Use environment variables to control which instrumentations are enabled:

# Disable specific instrumentations (comma-separated list)
export OTEL_NODE_DISABLED_INSTRUMENTATIONS="fs,dns"

# Or enable only specific instrumentations
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="http,express,mongodb"

Adjusting Export Interval

# Export metrics every 60 seconds (in milliseconds)
export OTEL_METRIC_EXPORT_INTERVAL=60000

Adding Custom Resource Attributes

export OTEL_RESOURCE_ATTRIBUTES="service.version=1.0.0,service.namespace=my-namespace,deployment.region=us-west-2"

Performance Considerations

The OpenTelemetry Node.js auto-instrumentation has minimal performance overhead:

  • Typical CPU overhead: < 5%
  • Memory overhead: < 50MB
  • No noticeable impact on application latency

For production use:

  • Start with conservative export intervals (30-60 seconds)
  • Monitor your application's resource usage
  • Disable unnecessary instrumentations

Support

If you have any questions or need assistance with Node.js instrumentation, please contact us via our help chat app available on the Support link in the sidebar, or by reaching out to support@oodle.ai.