OpenTelemetry for Express and Node.js

Trace an Express, Fastify or NestJS app with OpenTelemetry, and send it to Flowhawk with one flag or one line.

OpenTelemetry's Node.js auto-instrumentation covers HTTP, Express, Fastify, NestJS, the common database clients, Redis, gRPC and queues, loaded with a --require flag and no code change.

What you get

  • Every request as a trace, with its database calls and outgoing HTTP calls, in Traces.
  • Requests matched to your business flows by service and route on our side, so you see "checkout is failing at place order" rather than a list of endpoints.
  • Exceptions grouped into Issues, slow and N+1 database queries on each database's page, and deploys found from service.version.
  • Alerts, incidents and the on-call agent, which reads these traces when something breaks.

Set it up

1. Install

npm install @opentelemetry/api @opentelemetry/auto-instrumentations-node

2. Point it at Flowhawk

First create an ingest key: in the app, open Settings > API keys and pick Services. In the examples below, KEY stands for that key. Keep it out of your repository, like any other secret.

OTEL_SERVICE_NAME=orders
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20KEY
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.version=1.4.2

The space in the header is written %20. Set service.version to your release, so a deploy shows as a change next to the flows it made better or worse.

3. Start the app with the instrumentation loaded

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

Or set NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" where you can't change the start command.

Check it arrived

Open Setup in the app. It lists each service that sent data in the last 15 minutes. If yours isn't there, Help and troubleshooting says why telemetry can be refused (a wrong key, an empty balance) and how to see it.

Or use the Flowhawk SDK

The Flowhawk Node.js SDK (Node.js 18 or later) instruments HTTP, Express and outgoing fetch, tags each request with its business flow and step, carries the flow to the services it calls, and takes sampling settings from Flowhawk without a redeploy:

npm install @flowhawk/sdk-node
require("@flowhawk/sdk-node").init({ service: "orders" });   // first line of the entry file

It reads FLOWHAWK_API_KEY, FLOWHAWK_CONTROL_URL=https://api.flowhawk.dev, OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev and FLOWHAWK_ENVIRONMENT (Node.js guide).