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(instrumentation-koa): handle koa routes being of type RegExp #1754

Merged

Conversation

ramesius
Copy link
Contributor

@ramesius ramesius commented Oct 26, 2023

Which problem is this PR solving?

Koa route paths can be string | RegExp. RegExp is not a primitive type and thus results in the following logs from Otel when using the koa instrumentation:

  • Invalid attribute value set for key: http.route
  • Invalid attribute value set for key: koa.name

Short description of the changes

This change updates the typings package @types/koa__router that in-turn has been updated with the correct union type string | RegExp (See PR DefinitelyTyped/DefinitelyTyped#67194). The Koa instrumentation now properly handles the case when routes are of type RegExp.

I have also replaced the use of the deprecated SpanAttributes with Attributes.

@ramesius ramesius requested a review from a team October 26, 2023 23:40
@ramesius
Copy link
Contributor Author

ramesius commented Nov 3, 2023

@david-luna Is this something that you could look into?

@david-luna
Copy link
Contributor

@david-luna Is this something that you could look into?

I can give you feedback on this PR for now but nothing more since I don't have the required role/access for actioning on PRs.

So PR LGTM but I was wondering if its necessary to send KOA_TYPE and HTTP_ROUTE attributes if layerPath is not defined (not passed in the function call)

@blumamir
Copy link
Member

blumamir commented Nov 7, 2023

@ramesius Thank you for the contribution. the fix LGTM.
Can you please add a test for this case?

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Merging #1754 (30b2133) into main (24ffb3b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1754   +/-   ##
=======================================
  Coverage   91.42%   91.42%           
=======================================
  Files         143      143           
  Lines        7299     7301    +2     
  Branches     1458     1460    +2     
=======================================
+ Hits         6673     6675    +2     
  Misses        626      626           
Files Coverage Δ
...lemetry-instrumentation-koa/src/instrumentation.ts 97.53% <100.00%> (ø)
...ode/opentelemetry-instrumentation-koa/src/utils.ts 100.00% <100.00%> (ø)

@ramesius
Copy link
Contributor Author

ramesius commented Nov 9, 2023

@blumamir Sure, just pushed up a test for the functionality 👍🏻

@ramesius
Copy link
Contributor Author

ramesius commented Nov 9, 2023

@david-luna Probably makes sense. I can raise a seperate PR with that feedback if you don't mind.

Copy link
Member

@blumamir blumamir left a comment

Choose a reason for hiding this comment

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

Thanks! 🥇

@pichlermarc pichlermarc changed the title fix: handle koa routes being of type RegExp fix(instrumentation-koa): handle koa routes being of type RegExp Nov 9, 2023
@ramesius
Copy link
Contributor Author

CI was failing due to linting, just fixed that up 🤞🏻

@blumamir blumamir merged commit e313938 into open-telemetry:main Nov 12, 2023
15 checks passed
@dyladan dyladan mentioned this pull request Nov 12, 2023
jmcdo29 pushed a commit to jmcdo29/opentelemetry-js-contrib that referenced this pull request Nov 13, 2023
…n-telemetry#1754)

* chore: replace deprecated SpanAttributes type with Attributes

* fix: handle layer path being a string or regex

* chore: add test for RegExp koa route

* fix: single quote string due to linting

---------

Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
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.

3 participants