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 4 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 92.41%. Comparing base (8a5c214) to head (3829320).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2682   +/-   ##
=======================================
  Coverage   92.41%   92.41%           
=======================================
  Files         171      171           
  Lines        8150     8152    +2     
  Branches     1653     1653           
=======================================
+ Hits         7532     7534    +2     
  Misses        618      618           
Files with missing lines Coverage Δ
...try-instrumentation-express/src/instrumentation.ts 98.58% <100.00%> (ø)
...opentelemetry-instrumentation-express/src/utils.ts 98.50% <100.00%> (+0.04%) ⬆️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
6 participants