Skip to main content
Dual export from a Node.js service. Built from the example examples/otel-node-express: Express 5.3.0 with @opentelemetry/sdk-node 0.300.0, instrumentation-http 0.300.0 and instrumentation-express 0.72.0. tests/otelapps runs it against stock collectors in every export mode, and the apipath tag runs it against the real platform collector. Read the API quickstart first for the token and the environment variables.

Packages

Pin exact versions. @opentelemetry/api must be 1.10.0, because the 3.0.0 SDK packages declare the peer range >=1.10.0 <1.11.0; the overrides keep the shared core packages on one version:

The SDK setup

The whole setup is one file, loaded with node --require before the app so the HTTP and Express instrumentations can patch those modules when they are first required. Each signal gets two exporters: the one to your backend without a token, the one to the platform with it.
config.js next to it reads the environment variables and refuses unknown values at startup. Start the app with the file loaded first, as the example’s start script does:

Notes

  • Shut down cleanly. Call sdk.shutdown() after the server stopped accepting requests, so the last interval’s metrics are exported; the example does it on SIGTERM (src/server.js).
  • Routes. instrumentation-express sets http.route from the Express route (/accounts/:id); see http-route.md.
  • Health checks are excluded with ignoreIncomingRequestHook, so probes do not count as API traffic.
  • Logs are not exported by the example. If you export logs, send them only to your backend: the platform accepts and discards them.

Export modes the tests cover

The platform accepts all of these combinations; the defaults give exact numbers.