You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@fastify/otel: Ignoring or disabling a path does not affect sub-spans聽#1101
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.
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
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?
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.
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.
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.
Activity
metcoder95 commentedon Jun 25, 2025
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 thegetNodeAutoInstrumentationshogklint commentedon Jun 25, 2025
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
getNodeAutoInstrumentationsthen/userwon't have traces either. Unless you mean they need to be disabled in a similar manner to how@fastify/otelhasignorePaths, 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/otelonly 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?metcoder95 commentedon Jun 25, 2025
opentelemetry/httpprovides 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
readinzone that executes dependency check, and analiveone that just returns plain responses hinting is alive. Maybe is a path you can follow (unless you are already doing this)Yes, exactly; that's how the instrumentations (not only
fastify/otel) works.hogklint commentedon Jun 25, 2025
I'm using the
pgdb 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
hogklint commentedon Jul 30, 2025
Disabling a route in
@opentelemetry/instrumentation-httpsuppresses tracing (http.ts#L607) which achieve what I want. Sounds like something that would be useful for@fastify/oteltoo.A lot of the
opentelemetry-jsinstrumentation packages also has an option to require a parent span (E.g. mongoose) which is handy when@opentelemetry/instrumentation-httpcannot be used. Not all of them have this though.metcoder95 commentedon Aug 12, 2025
TIL of the
supressTracing, I believe that can be easily added if the route is set tootel: falseor within the ignore routes.would you lie to send a PR to address that?
hogklint commentedon Aug 20, 2025
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.
metcoder95 commentedon Aug 21, 2025
No pressure, if no one has submitted a PR by the time you are free, feel free to open one