Node.js
Integration
Section titled “Integration”Instrument your Node.js applications to send traces and logs to Kopai.
Installation
Section titled “Installation”npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-nodeBasic Setup
Section titled “Basic Setup”Create an instrumentation.mjs file:
import { NodeSDK } from "@opentelemetry/sdk-node";import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
const sdk = new NodeSDK({ instrumentations: [getNodeAutoInstrumentations()],});
sdk.start();The SDK automatically reads configuration from standard OpenTelemetry environment variables.
Running Your Application
Section titled “Running Your Application”Set the required environment variables and run:
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp.kopai.app"export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_TOKEN"export OTEL_SERVICE_NAME="my-service"node --import ./instrumentation.mjs app.js| Variable | Description |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | Kopai OTLP endpoint |
OTEL_EXPORTER_OTLP_HEADERS | Auth header with your backend token |
OTEL_SERVICE_NAME | Name shown in Kopai UI |
Auto-Instrumentation
Section titled “Auto-Instrumentation”The @opentelemetry/auto-instrumentations-node package provides automatic instrumentation for:
- HTTP/HTTPS
- Express, Fastify, Koa
- MongoDB, PostgreSQL, MySQL
- Redis, Memcached
- gRPC
- And more
Working Example
Section titled “Working Example”For a complete working example: