Node

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/instrumentation-node"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/e83f395d-758c-4410-97b0-5ab78302196d/social-card.svg?v=3e7ae33eec8b" alt="Node" width="600" height="315"></a>

<!-- status: ga language: node -->

Node.js: zero-code instrumentation

@opentelemetry/auto-instrumentations-node registers instrumentations for http, express, fastify, pg, mysql, redis, grpc and more before your code loads, with no code change. Nothing Watchtower-specific is installed: it reads the standard OTEL_* variables.

  1. Create a project, then an ingestion key (wti_...) with the ingest:traces scope. The key is shown once.

  2. Point the instrumentation at the gateway and pass the key in the x-watchtower-key header:

export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.example.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS=x-watchtower-key=wti_YOUR_KEY
export OTEL_SERVICE_NAME=my-service
  1. Install the package and preload it:

npm install @opentelemetry/auto-instrumentations-node
node --require @opentelemetry/auto-instrumentations-node/register app.js

For containers set NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" instead of editing the command line.

  1. Send one request to the service, then open the project's onboarding screen: it turns green when the first span arrives.

Updated