Skip to content

@fastify/otel: Ignoring or disabling a path does not affect sub-spans #1101

@hogklint

Description

@hogklint

💬 Question here

Hi,

I have a health endpoint that is often called and I want to disable all tracing for the endpoint and any sub-spans that may occor. I've tried using the ignorePaths and route config (config { otel: false }), and they do disable the endpoint in question, but any sub-spans are still registered, e.g. @opentelemetry/instrumentation-http and DB calls are still traced and are reported as root-spans. This creates more spam than just enabling the endpoint. I can't imagine this is the inteded way it should work, what am I doing wrong?

I tried using a parent based sampler but that has no affect.

export const fastifyOtelInstrumentation = new FastifyOtelInstrumentation({
  registerOnInitialization: true,
  ignorePaths: (opts) => {
    return opts.url.startsWith('/healthz');
  },
});

sdk = new NodeSDK({
  sampler: new ParentBasedSampler({
    root: new AlwaysOnSampler(),
  }),
  instrumentations: [
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-fastify': {
        enabled: false,
      },
    }),
  ],
})
sdk.start()

Your Environment

  • node version: 22.16
  • fastify version: 5.3.3
  • fastify/otel version: 0.9.1
  • os: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions