-
Notifications
You must be signed in to change notification settings - Fork 619
feat(instrumentation-express)!: propagate context and measure full handler spans #2638
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
feat(instrumentation-express)!: propagate context and measure full handler spans #2638
Conversation
|
cc @pichlermarc fixes discussed wednesday |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2638 +/- ##
=======================================
Coverage 91.52% 91.52%
=======================================
Files 171 171
Lines 8150 8153 +3
Branches 1653 1653
=======================================
+ Hits 7459 7462 +3
Misses 691 691
|
pichlermarc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good, thank you for working on this. 🙌
cc @JamieDanielson and @pkanal (component owners) for comments :)
|
Apologies for the outsider coming in on this PR, but reporting that I've manually applied this PR into a local working copy to validate it works with my sample apps and it worked! In fact, it already helped me catch a case or two where I was missing an |
|
Waiting for the merge... 🤞 |
| } | ||
|
|
||
| let spanHasEnded = false; | ||
| // TODO: Fix router spans (getRouterPath does not work properly) to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on what you mean by not working properly or create an issue so this doesn't get lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see in the nested routers test that the created router spans never include the /posts section of the route. If I were to propagate context and nest them we'd end up with /api/user/:id -> /:postId -> /api/user/posts/:postId which is really confusing.
|
@JamieDanielson @pkanal Sorry, gonna bother you again for an approval on this one :) |
JamieDanielson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! Should we mark this as a breaking change (still experimental but mostly for signaling) since it updates parent span ID for some spans?
|
@JamieDanielson good point, I changed the title so that it's categorized as such. 🙂 |
Which problem is this PR solving?
Currently the Express instrumentation does not propagate context and does not properly instrument request handlers.
Short description of the changes
Context is propagated for middleware and request handler spans, while their
nextcallback is reset to the parent context to avoid extreme nesting as suggested in #2022. Request handler spans are also no longer ended prematurely.Router spans are kept as-is since they are broken and propagating context for them would make things even more confusing than they already are.
Example traces
Before
After
Related issues