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

fix(express): span name if middleware on nested router is used #2682

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

RigoTamas
Copy link

Which problem is this PR solving?

Short description of the changes

  • A flag is passed down in the storeLayerPath function, which tells the caller wether a new item has been added to the layer store. This is needed, because we only want to pop from the req[_LAYERS_STORE_PROPERTY] list if we added something to it. Popping from this list in case we did not push anything to it will result in popping a parent entry, which will skew the layers store. Hence this unnecessary popping will result in a malformed http.route tag.
  • This can be reproduced by adding a middleware to a nested router.
  • The nested router unit test has been updated to reflect this behavior. The unit test now breaks without this change, which reflects the need for this change.

@RigoTamas RigoTamas requested a review from a team as a code owner January 27, 2025 18:32
Copy link

linux-foundation-easycla bot commented Jan 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@bsiedleckiallegro
Copy link

That is a pretty significant improvement, good job!
@pkanal @JamieDanielson could you please take a look at the changes suggested by @RigoTamas ? Much appreciated :)

@allegro-dbargowski
Copy link

allegro-dbargowski commented Feb 19, 2025

Hey there, just wanted to share that I've tried out the changes from this PR by tweaking the OTEL libraries in node_modules for our app, and it sorted out the issues we were facing with http_route values in our Prometheus metrics. @pkanal @JamieDanielson @raphael-theriault-swi , it would be awesome if you could take a look at this PR soon. Thanks a bunch!

Copy link
Member

@raphael-theriault-swi raphael-theriault-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback but I don't feel it's important enough to warrant not approving. Thanks for the contribution !

Comment on lines 34 to +39
* @param [value] the value to push into the array
*/
export const storeLayerPath = (request: PatchedRequest, value?: string) => {
export const storeLayerPath = (
request: PatchedRequest,
value?: string
): { isLayerPathStored: boolean } => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extremely minor but I can't really think of any other information that could be returned by this, so personally I'd rather see this skip the object and just return a boolean, the meaning of which can be documented in the docstring.

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.48%. Comparing base (b520d04) to head (f724e82).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2682      +/-   ##
==========================================
- Coverage   91.53%   91.48%   -0.05%     
==========================================
  Files         171      171              
  Lines        8172     8174       +2     
  Branches     1660     1660              
==========================================
- Hits         7480     7478       -2     
- Misses        692      696       +4     
Files with missing lines Coverage Δ
...try-instrumentation-express/src/instrumentation.ts 98.61% <100.00%> (ø)
...opentelemetry-instrumentation-express/src/utils.ts 98.50% <100.00%> (+0.04%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RigoTamas
Copy link
Author

Thanks for approving @raphael-theriault-swi! Who is part of the open-telemetry/javascript-approvers group? I see somebody from that group still needs to approve in order to merge this.

@raphael-theriault-swi
Copy link
Member

@open-telemetry/javascript-approvers ready for workflow approval

@allegro-dbargowski
Copy link

Hey @raphael-theriault-swi, @pkanal, and @JamieDanielson! Just checking in to see if there's any chance this fix will be merged soon. We're using OTEL for monitoring and alerting based on Prometheus metrics for our app, which is critical for our on-call engineers. Right now, we're seeing issues with invalid http_route label values (which in turn makes differentiating endpoints impossible sometimes). If the merge will take a while, we'll consider using a forked version with this fix applied. Any updates would be greatly appreciated—thanks a bunch! 🙏

@pichlermarc pichlermarc added the has:owner-approval Approved by Component Owner label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@opentelemetry/instrumentation-express - incorrect route set to span, if middlewares are being used
7 participants