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

Bracket WAI middleware spans with detachContext #116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

velveteer
Copy link

@velveteer velveteer commented May 7, 2024

After updating to hs-opentelemetry-instrumentation-wai-0.1.0.0, I noticed our Datadog APM traces were starting to group unrelated requests together. Notably all of these sporadic groups shared the same GHC thread ID.

Further investigation led me to this commit: 34569fc. At first glance, removing this bracket would seem harmless, assuming each WAI request is served by a separate thread. But in fact warp uses some heuristics to enable the HTTP keep-alive optimization, which means a single thread can serve multiple requests. Without detaching the context from the thread after serving a request, the initial request context is re-used for subsequent requests, which means propagated OTel context will be inherited by those request spans.

I tested this small patch in our production application and it appears to have resolved our APM woes.

@velveteer
Copy link
Author

I believe that stripping W3C Trace Context headers can mask this issue. Which makes me wonder if this is related to https://www.iankduncan.com/articles/2023-08-28-opentelemetry-gotchas-phantom-spans.

@iand675
Copy link
Owner

iand675 commented May 29, 2024

Can you rebase this against main? I think this change makes sense and would like to merge it.

@velveteer
Copy link
Author

Not sure if you were notified but I rebased this.

@velveteer velveteer mentioned this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants