Skip to content

Instantly share code, notes, and snippets.

@bitbay
Last active December 4, 2025 12:46
Show Gist options
  • Select an option

  • Save bitbay/a6f824d5d193ff13ccfafe9d29101964 to your computer and use it in GitHub Desktop.

Select an option

Save bitbay/a6f824d5d193ff13ccfafe9d29101964 to your computer and use it in GitHub Desktop.
`@fastify/otel` with `@opentelemetry/auto-instrumentations`

Bootstrap

$ fastify generate myapp --lang=typescript
$ cd myapp
$ npm install
# install otel dependencies
$ npm i @fastify/otel @opentelemetry/auto-instrumentations-node

Init plugin

import { FastifyOtelInstrumentation } from '@fastify/otel'

// ...
const app: FastifyPluginAsync<AppOptions> = async (
  fastify,
  opts
): Promise<void> => {
  // Place here your custom code!
  const fastifyOtelInstrumentation = new FastifyOtelInstrumentation();
  await fastify.register(fastifyOtelInstrumentation.plugin());
  // ...
}

export default app
export { app, options }

Run

# configure @opentelemetry/auto-instrumentations as usual (.env, ENV, etc...)
$ npm run dev -- --node-options="--require @opentelemetry/auto-instrumentations-node/register"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment