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

feat: router instrumentation #458

Merged
merged 39 commits into from May 19, 2021

Conversation

rauno56
Copy link
Member

@rauno56 rauno56 commented Apr 27, 2021

Which problem is this PR solving?

This adds auto instrumentation for pillarjs/router, which is almost identical to the router implementation used in Express.

Ideally, if possible, those two instrumentations should share code(thoughts on that?), but this is not currently the case because

  1. Router is more low level than Express, so the dependency makes sense to be other way around;
  2. Express' instrumentation is currently not measuring the execution time for handlers correctly.

Short description of the changes

Instead of wrapping each handler passed to the router, I'm patching two functions on Layer to plug into the core of the routers work.

@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #458 (9e8455e) into main (b7e0bdd) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #458   +/-   ##
=======================================
  Coverage   95.26%   95.26%           
=======================================
  Files         140      140           
  Lines        8399     8399           
  Branches      815      815           
=======================================
  Hits         8001     8001           
  Misses        398      398           

@rauno56 rauno56 force-pushed the feat/router-instrumentation branch from 8c5cb3a to da8b175 Compare May 7, 2021 09:24
@rauno56 rauno56 marked this pull request as ready for review May 7, 2021 09:24
@rauno56 rauno56 requested a review from a team as a code owner May 7, 2021 09:24
examples/router/package.json Outdated Show resolved Hide resolved
examples/router/package.json Show resolved Hide resolved
examples/router/package.json Outdated Show resolved Hide resolved
@rauno56 rauno56 force-pushed the feat/router-instrumentation branch from 3a7d6ae to ffa6735 Compare May 10, 2021 10:45
@obecny
Copy link
Member

obecny commented May 10, 2021

Please avoid force push after 1st review, it is impossible to track changes


utils.renameHttpSpan(parentSpan, layer.method, route);
// make sure spans are ended at least when response is finished
res.prependOnceListener('finish', () => span.end());
Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find the discussion in #416 but ending twice the span isn't technically a noop because its log a warning to the diag logger. Now that isn't enabled by default isn't a problem for all users but i suspect it will for people having it enabled (see #107 for exemple).


utils.renameHttpSpan(parentSpan, layer.method, route);
// make sure spans are ended at least when response is finished
res.prependOnceListener('finish', () => span.end());
Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find the discussion in #416 but ending twice the span isn't technically a noop because its log a warning to the diag logger.
Now that isn't enabled by default isn't a problem for all users but i suspect it will for people having it enabled (see #107 or open-telemetry/opentelemetry-js#2126 for exemple).

Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for the changes

Copy link
Member

@johnbley johnbley left a comment

Choose a reason for hiding this comment

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

lgtm, agree that renameHttpSpanName was a bit much.

const deepRouter = new Router();

deepRouter.use('/hello', helloRouter);
router.use('/deep', deepRouter);
Copy link
Member

Choose a reason for hiding this comment

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

I like the thinking behind this test (setup)!

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

lgtm

@iNikem
Copy link

iNikem commented May 19, 2021

@open-telemetry/javascript-maintainers Can this be merged now?

@vmarchaud vmarchaud merged commit 8677867 into open-telemetry:main May 19, 2021
@rauno56 rauno56 deleted the feat/router-instrumentation branch June 4, 2021 17:05
@dyladan dyladan added the enhancement New feature or request label Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants