-
Notifications
You must be signed in to change notification settings - Fork 545
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
base: main
Are you sure you want to change the base?
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 90.96% 90.97%
=======================================
Files 172 172
Lines 8137 8140 +3
Branches 1649 1649
=======================================
+ Hits 7402 7405 +3
Misses 735 735
|
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... 🤞 |
@@ -234,12 +237,15 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen | |||
} | |||
|
|||
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.
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
next
callback 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