Skip to content

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

Open

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

Activity

  1. metcoder95 commented on Jun 25, 2025

    @metcoder95
    Member

    As you are using the auto instrumentation from opentelemetry, you need to also disable the HTTP one (and your database driver as well) directly at the getNodeAutoInstrumentations

  2. hogklint commented on Jun 25, 2025

    @hogklint
    Author

    Thank you for the reply. Yes, I'm using the auto instrumentation from @opentelemetry/auto-instrumentations-node.

    I'm not following your suggestion, though. Let's say I have two endpoints

    • /user - I want all the tracing I can get here. Any incoming request, outgoing requests, db calls etc
    • /healthz - I don't want any tracing here.

    If I disable HTTP and DB instrumentation in getNodeAutoInstrumentations then /user won't have traces either. Unless you mean they need to be disabled in a similar manner to how @fastify/otel has ignorePaths, on a per-route basis? I don't think all of them support it, and ...well, that seems to require a big effort that would be quite finicky.

    Is the conclusion that disabling a route in @fastify/otel only affects spans generated by @fastify/otel? I hate to be negative, but it doesn't seem very useful. Maybe it's a limitiation of how OpenTelemetry works?

  3. metcoder95 commented on Jun 25, 2025

    @metcoder95
    Member

    If I disable HTTP and DB instrumentation in getNodeAutoInstrumentations then /user won't have traces either. Unless you mean they need to be disabled in a similar manner to how @fastify/otel has ignorePaths, on a per-route basis? I don't think all of them support it, and ...well, that seems to require a big effort that would be quite finicky.

    opentelemetry/http provides some configuration to allow you ignore paths while endorsing requests.
    If you want to disable these spans, you'll need to do it in combination with fastify/otel.

    I'm unaware of what database driver you are using, tho I don't think you'll be able to disable it per-query.

    Usually is also common to use two different endpoints when it comes to health checks, having a readinz one that executes dependency check, and an alive one that just returns plain responses hinting is alive. Maybe is a path you can follow (unless you are already doing this)

    Is the conclusion that disabling a route in @fastify/otel only affects spans generated by @fastify/otel? I hate to be negative, but it doesn't seem very useful. Maybe it's a limitiation of how OpenTelemetry works?

    Yes, exactly; that's how the instrumentations (not only fastify/otel) works.

  4. hogklint commented on Jun 25, 2025

    @hogklint
    Author

    I'm using the pg db driver, but as you say the instrumentation could possibly do it per-query, but I want the deciding factor to be the endpoint.

    It sound like I would have to write a custom sampler together with a parent based sampler to discard whole traces, not just disabled spans from certain intstrumentation. Was hoping to avoid that.

    Thank you for the help

  5. hogklint commented on Jul 30, 2025

    @hogklint
    Author

    Disabling a route in @opentelemetry/instrumentation-http suppresses tracing (http.ts#L607) which achieve what I want. Sounds like something that would be useful for @fastify/otel too.

    A lot of the opentelemetry-js instrumentation packages also has an option to require a parent span (E.g. mongoose) which is handy when @opentelemetry/instrumentation-http cannot be used. Not all of them have this though.

  6. metcoder95 commented on Aug 12, 2025

    @metcoder95
    Member

    TIL of the supressTracing, I believe that can be easily added if the route is set to otel: false or within the ignore routes.

    would you lie to send a PR to address that?

  7. added
    enhancementNew feature or request
    and removed
    help wantedExtra attention is needed
    on Aug 12, 2025
  8. hogklint commented on Aug 20, 2025

    @hogklint
    Author

    I'm open to submitting a PR, but I'm not sure when I can get to it. I have no ETA for it at this point.

  9. metcoder95 commented on Aug 21, 2025

    @metcoder95
    Member

    No pressure, if no one has submitted a PR by the time you are free, feel free to open one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions