Skip to content

Fastify integration starts a span per hook on unsampled requests #26710

Open

Description

@JonasBa

Problem Statement

With fastifyIntegration, every instance hook, route hook and route handler is wrapped in startSpan, even when the request is not sampled. Those spans are non-recording and never sent, but each still forks the scope, sets an active span and builds its attributes. With 20 no-op hooks and tracesSampleRate: 0, a Fastify 5 request takes about 94 µs instead of about 16 µs in a local app.inject() benchmark.

Solution Brainstorm

In the hook wrapper, run the hook directly when the parent span (the request span, or the active span once it has ended) is not sampled. Sampled requests keep the same spans. The only visible difference is that the skipped spans no longer record a sample_rate client outcome.

Additional Context

I have a change with unit tests ready and would be happy to open a PR if this sounds good.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Activity

  1. linear-code commented on Nov 20, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions