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

Document that ZoneContextManager doesn't work with async/await code that targets ES2017+ #1502

Closed
ajbouh opened this issue Sep 4, 2020 · 4 comments · Fixed by #1616
Closed
Assignees
Labels
document Documentation-related pkg:context-zone

Comments

@ajbouh
Copy link

ajbouh commented Sep 4, 2020

ZoneContextManager is based on zone.js, which is a part of the Angular project.

Unfortunately, zone.js can't track context within an AsyncFunction in the web browser: angular/angular#31730

If my understanding of the OpenTelemetry APIs and documentation is correct, then this fact is probably very surprising to many OpenTelemetry users.

As an OpenTelemetry user, my choices seem to be:

  1. be ok with incorrectly nested spans
    (I'm not ok with this)
  2. build my entire application without async/await
    (I don't love .then and }) staircases enough to do this)
  3. ensure my entire application is transpiled back to ES2015
    (makes debugging very challenging)
  4. use explicit context propagation in all asynchronous code paths
    (feels wrong since it makes it very expensive to switch a codepath from sync to async)
  5. use explicit context propagation everywhere
    (winner winner chicken dinner)

Based on my reading of the associated issue threads, it seems unlikely that zone.js will ever be able to support ES2017+ async/await. I can add these as links if they'd be helpful to others.

Assuming I'm not missing anything, I think the OpenTelemetry documentation should be updated to highlight this (major) shortcoming of ZoneContextManager. This project might even consider advocating for users to just start using explicit context propagation in the first place.

In the medium term it might make sense to drop implicit context propagation altogether.

@ajbouh ajbouh added the bug Something isn't working label Sep 4, 2020
@dyladan
Copy link
Member

dyladan commented Sep 8, 2020

Hmm. I think at the very least we need some docs updates here, but I don't think this is actually a bug as there are no behavior changes requested.

Regarding the suggested docs, I think we should suggest that if users are using the Zone context manager, they should transpile to ES2015. If that is not an option, explicit context propagation is the fallback choice. The main reason for this is that transpiling doesn't require code changes to the user application in order to make tracing work.

@dyladan dyladan removed the bug Something isn't working label Sep 8, 2020
@ajbouh
Copy link
Author

ajbouh commented Sep 8, 2020

Ah you're right I did not specify a change in behavior beyond updating the documentation.

I can rectify this. First, I don't know whether or not opentelemetry-js should be targeting ES2017. This seems like it might be wrong?

Second, I don't think these APIs should be reliant on implicit global context to generate properly nested traces. Many of the functions seem to use a default parameter of context.active() or something along these lines.

@ajbouh
Copy link
Author

ajbouh commented Sep 8, 2020

It's also (imo) clearly a bug that tracing in the browser is broken by default in modern browsers when using modern JavaScript.

Since wrong nesting for traces can mean missing or faulty propagation values, this bug can affect server side traces that use values from the browser implementation.

@dyladan
Copy link
Member

dyladan commented Sep 9, 2020

We are going to document that an end user application using the Zone context manager should target ES2015. If that is not possible, we will recommend users manually propagate context. Dropping implicit context management is not feasible as it would possibly violate spec, and much of the code is shared with node.js which propagates context without problems.

See related Zone.js/angular issue angular/angular#31730

@dyladan dyladan added the document Documentation-related label Sep 9, 2020
@dyladan dyladan changed the title ZoneContextManager doesn't work with async/await code that targets ES2017+ Document that ZoneContextManager doesn't work with async/await code that targets ES2017+ Sep 9, 2020
@dyladan dyladan self-assigned this Sep 9, 2020
tantaman added a commit to vlcn-io/model that referenced this issue Sep 19, 2022
ZoneContextManager does not propagate context when entering native async/await.

open-telemetry/opentelemetry-js#1502
angular/angular#31730

Transpiling to es2015 doesn't sound great.

Looking for alternatives. Maybe `Dexiejs` promise which promises to work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document Documentation-related pkg:context-zone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants