Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fastify instrumentation incorrectly sets middleware span as parent span to route handler with sync hooks #2619

Open
drewcorlin1 opened this issue Dec 31, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@drewcorlin1
Copy link
Contributor

drewcorlin1 commented Dec 31, 2024

What version of OpenTelemetry are you using?

  "dependencies": {
   "@opentelemetry/auto-instrumentations-node": "^0.55.0",
    "@opentelemetry/exporter-trace-otlp-proto": "^0.57.0",
    "@opentelemetry/sdk-node": "^0.57.0",
    "@opentelemetry/sdk-trace-base": "^1.30.0"
  }

What version of Node are you using?

20.18

What did you do?

Repo to reproduce with steps in the README: https://github.com/drewcorlin1/fastify-otel-bug-example

What did you expect to see?

The route handler as a child span of the GET /example from @opentelemetry/instrumentation-http (and thus, jaeger correctly identifying the critical path of the request)

What did you see instead?

The route handler has a child span of the first middleware span middleware - fastify -> @fastify/request-context from @opentelemetry/instrumentation-fastify (and thus jaeger incorrectly identifying the critical path of my trace)

Additional context

Screenshot of what I'm seeing and full JSON of the trace downloaded from jaeger attached
Screenshot 2024-12-30 at 11 12 19 PM

fastify-trace.json

@drewcorlin1 drewcorlin1 added the bug Something isn't working label Dec 31, 2024
@drewcorlin1 drewcorlin1 changed the title Fastify instrumentation incorrectly sets middleware are parent span to handler Fastify instrumentation incorrectly sets middleware span as parent span to route handler Dec 31, 2024
@drewcorlin1
Copy link
Contributor Author

drewcorlin1 commented Dec 31, 2024

More context: If I update my onRequest hook to be an async callback

app.addHook('onRequest', async (_req, _res) => {
  await new Promise((r) => setTimeout(r, 100));
});

instead of

app.addHook('onRequest', (_req, _res, done) => {
  new Promise((r) => setTimeout(r, 100)).then(done);
});

then I get the correct behavior as far as parent spans go, but the duration of the span is incorrect

Screenshot 2024-12-30 at 11 41 35 PM

@drewcorlin1 drewcorlin1 changed the title Fastify instrumentation incorrectly sets middleware span as parent span to route handler Fastify instrumentation incorrectly sets middleware span as parent span to route handler with sync hooks Dec 31, 2024
@drewcorlin1 drewcorlin1 mentioned this issue Jan 1, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant