Add distributed tracing to any Node.js application with the OpenTelemetry SDK. Auto-instrumentation captures Express, Fastify, database queries, and HTTP calls with no code changes.
npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node @opentelemetry/exporter-trace-otlp-http @opentelemetry/exporter-logs-otlp-http // tracing.ts — run with: node --import ./tracing.ts app.ts
import { NodeSDK } from "@opentelemetry/sdk-node";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
import { SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
const sdk = new NodeSDK({
traceExporter: new OTLPTraceExporter({
url: "https://ingest.maple.dev/v1/traces",
headers: { Authorization: "Bearer your-api-key" },
}),
logRecordProcessors: [
new SimpleLogRecordProcessor(
new OTLPLogExporter({
url: "https://ingest.maple.dev/v1/logs",
headers: { Authorization: "Bearer your-api-key" },
})
),
],
instrumentations: [getNodeAutoInstrumentations()],
});
sdk.start(); Automatic spans for every HTTP request with route pattern, method, and response status.
Database spans with query text, connection info, and execution duration via pg and mysql2.
Outgoing HTTP requests traced with context propagation across service boundaries.
Redis command spans with operation type, key patterns, and latency tracking.
Full client and server gRPC tracing with service name, method, and status attributes.
Spans for file reads, writes, and directory operations with path and size metadata.