Instrumenting Express.js with OpenTelemetry

Prerequisites

  • Node.js v10+

Instrumenting Express.js app

git clone https://github.com/uptrace/uptrace-js.git
cd example/express
  • Step 2. Install the required dependencies:
yarn install
  • Step 3. Edit main.js to configure OpenTelemetry to export data to Uptrace:
const uptrace = require('@uptrace/node')

uptrace
  .configureOpentelemetry({
    // Set dsn or UPTRACE_DSN env var.
    dsn: '',

    serviceName: 'myservice',
    serviceVersion: '1.0.0',
  })
  .start()
  .then(main)
  • Step 4. Edit main.js to instrument the Express app:
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express')
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http')

uptrace
  .configureOpentelemetry({
    ...

    instrumentations: [new HttpInstrumentation(), new ExpressInstrumentation()],
  })
UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" node main.js

What is next?

By now, you should have a Django app with instrumented views. Next, instrumentopen in new window more operations (for example, database queries) or learn about OpenTelemetry API to create your own instrumentations.