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: enable root span to contain route #327

Merged
merged 7 commits into from Mar 20, 2021

Conversation

DinaYakovlev
Copy link
Contributor

@DinaYakovlev DinaYakovlev commented Jan 28, 2021

Which problem is this PR solving?

In addition to #176 PR and to #273 We should able to instrument the root span name. This way it would be clear from the beginning on what request the span is about, and if in the future there would be an option to remove layers (like in the express plugin) the route will be in the root span.

Short description of the changes

using koa plugin before the change:
Before
using koa plugin after the change:
After

@DinaYakovlev DinaYakovlev requested a review from a team as a code owner January 28, 2021 14:17
@codecov
Copy link

codecov bot commented Jan 28, 2021

Codecov Report

Merging #327 (c69ceec) into main (557d9a4) will not change coverage.
The diff coverage is n/a.

❗ Current head c69ceec differs from pull request most recent head 382e4c3. Consider uploading reports for the commit 382e4c3 to get more accurate results

@@           Coverage Diff           @@
##             main     #327   +/-   ##
=======================================
  Coverage   94.34%   94.34%           
=======================================
  Files          10       10           
  Lines         407      407           
  Branches       44       44           
=======================================
  Hits          384      384           
  Misses         23       23           

@@ -118,7 +121,8 @@ export class KoaInstrumentation extends BasePlugin<typeof koa> {
middlewareLayer[kLayerPatched] = true;
this._logger.debug('patching Koa middleware layer');
return async (context: KoaContext, next: koa.Next) => {
if (api.getSpan(api.context.active()) === undefined) {
const parent = api.getSpan(api.context.active()) as KoaPluginSpan;
Copy link
Member

Choose a reason for hiding this comment

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

i'm not sure why you are extending the span api, can't you use context() instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to find out somehow who is the root parent span.. I do it by checking that the parentSpanId is undefined..

Copy link
Member

Choose a reason for hiding this comment

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

I remembered that we do the same in the express plugin so thats fine

Copy link
Member

Choose a reason for hiding this comment

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

This isn't safe. An instrumentation may be used by a third party SDK which doesn't have the same private properties we do. The safer (but more roundabout) way to check if it is the root would be to check if there is a span in context before the first span is created

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks @dyladan
fixed

@shyimo
Copy link
Contributor

shyimo commented Feb 4, 2021

@vmarchaud Hi !
any news regrading the review ?

@vmarchaud
Copy link
Member

@shyimo sorry for the delay, could you rebase the PR ?

@DinaYakovlev
Copy link
Contributor Author

@vmarchaud rebased, please have another look :)

@obecny obecny added the enhancement New feature or request label Mar 16, 2021
@vmarchaud
Copy link
Member

@DinaYakovlev Thanks for the contribution and sorry for waiting so long

@vmarchaud vmarchaud merged commit 384482c into open-telemetry:main Mar 20, 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

5 participants