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(plugin-express): fix double span end #908 #910

Merged
merged 2 commits into from
Apr 15, 2020

Conversation

vmarchaud
Copy link
Member

The "fix" is quite simple but i've added a big comments to explain what's happening inside express.
I've stated that it's would be quite memory consuming to listen for end event because we would keep the context alive for each middleware while waiting for the response to be sent. In this case we are only keep it for one tick which should be fine in terms of impact.
What do you guys think ?

@codecov-io
Copy link

codecov-io commented Mar 28, 2020

Codecov Report

Merging #910 into master will not change coverage.
The diff coverage is 95.00%.

@@           Coverage Diff           @@
##           master     #910   +/-   ##
=======================================
  Coverage   94.75%   94.75%           
=======================================
  Files         248      248           
  Lines       11288    11288           
  Branches     1079     1081    +2     
=======================================
  Hits        10696    10696           
  Misses        592      592           
Impacted Files Coverage Δ
...ckages/opentelemetry-plugin-express/src/express.ts 97.89% <94.11%> (-0.96%) ⬇️
packages/opentelemetry-plugin-express/src/utils.ts 97.22% <100.00%> (+1.76%) ⬆️
...ckages/opentelemetry-plugin-express/src/version.ts 100.00% <100.00%> (ø)
.../opentelemetry-plugin-express/test/express.test.ts 99.18% <100.00%> (ø)

@vmarchaud vmarchaud added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 30, 2020
@mayurkale22
Copy link
Member

I don't have a super strong opinion on this fix, going to leave it to @open-telemetry/javascript-approvers to chime in.

@markwolff
Copy link
Member

markwolff commented Mar 30, 2020

Does express expose a different async behavior than the standard http module? AFAIK the span should be ended before the followup callback is called anyways. Or callbackHasBeenCalled = true be changed to call a function ending the span?

@vmarchaud
Copy link
Member Author

@markwolff

Does express expose a different async behavior than the standard http module

Yes, because the express is implemented as a stack of function, each of them requiring to call the next with the next callback. But it can also end the whole request using the standard http module.

AFAIK the span should be ended before the followup callback is called anyways

The issue is when the user code doesnt callback when it send the http response.

@vmarchaud
Copy link
Member Author

@open-telemetry/javascript-approvers This one require some reviews please :)

@@ -45,6 +45,10 @@ const provider = new NodeTracerProvider();

See [examples/express](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/express) for a short example.

### Caveats

Because of the way express works, it's hard to correctly compute the time took that each span took to complete. For this reason the time you'll see reported for each span will **not** represent the time it really took.
Copy link
Member

Choose a reason for hiding this comment

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

Only for asynchronous spans

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't why but at some point i though that it wasn't possible for sync callback too so i'd removed the acurate reporting for all spans, but you are right. I've repushed the previous implementation that report accurate duration for sync middlewares

@vmarchaud vmarchaud force-pushed the fix-double-end-express branch 2 times, most recently from b8f94e0 to cafbde7 Compare April 12, 2020 12:25
@vmarchaud vmarchaud requested a review from dyladan April 12, 2020 12:27
packages/opentelemetry-plugin-express/README.md Outdated Show resolved Hide resolved
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

@dyladan dyladan added the bug Something isn't working label Apr 15, 2020
@dyladan dyladan merged commit 7412d9b into open-telemetry:master Apr 15, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
)

Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants