Express.js
The example below is using the Node.js guide for OpenTelemetry (opens in a new tab).
Libraries
First, install the required dependencies.
>_ Terminal
npm install --save @opentelemetry/api
npm install --save @opentelemetry/auto-instrumentations-node
Instrumentation
Method: Agent
Add auto instrumentation and bootstrap your service.
>_ Terminal
opentelemetry-bootstrap -a install
Run the agent
>_ Terminal
node --require @opentelemetry/auto-instrumentations-node/register app.js
Required configuration
The following environment variables are always required.
.env
OTEL_EXPORTER_OTLP_ENDPOINT="https://collect.smallhours.dev"
OTEL_EXPORTER_OTLP_HEADERS="small-hours-api-key=YOUR_API_KEY,small-hours-service-id=YOUR_SERVICE_ID"