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

Tracing not propagated across @Async #138

Open
dansiviter opened this issue Jul 19, 2022 · 8 comments
Open

Tracing not propagated across @Async #138

dansiviter opened this issue Jul 19, 2022 · 8 comments
Assignees
Labels
status: awaiting validation Waiting to be validated as a real issue

Comments

@dansiviter
Copy link

Expected Behavior

When using @Aync methods the TraceContext is automatically propagated to the new thread linking in with instigating trace. Similar to io.opentelemetry.context.Context#wrap(...).

Actual Behaviour

When @Async is used instigating TraceContext is ignored leaving holes in the resulting trace. The issue goes away if @Async is removed, but that defeats the point.

Steps To Reproduce

  1. Annotate a methods with @Async,
  2. Invoke the method with a call that has a TraceContext (i.e. HTTP request with B3 header).

Environment Information

  • OS: N/A
  • Micronaut Trace: 4.1.1

Example Application

No response

Version

3.5.3

@graemerocher
Copy link
Contributor

@n0tl3ss please take a look

@graemerocher graemerocher added the status: awaiting validation Waiting to be validated as a real issue label Jul 20, 2022
@n0tl3ss
Copy link
Member

n0tl3ss commented Jul 20, 2022

Hi @dansiviter, I tried to recreate test example without success. Could you please provide me Controller class where issue exists. Thanks

@dansiviter
Copy link
Author

@n0tl3ss I can't share the code, so will have to create an example when I find some time.

@dansiviter
Copy link
Author

dansiviter commented Oct 26, 2022

After a lot of debugging, I believe the issue can be fixed by tracing.instrument-threads: true (see micronaut-projects/micronaut-core#2307).

Can this behaviour be documented please as it is confusing.

@graemerocher
Copy link
Contributor

If you provide an example maybe we can take it forward. Using instrument-threads can be unsafe if you use a lot of reactive code, hence it is disabled.

@dansiviter
Copy link
Author

@graemerocher Every time you use @Async or use ExecutorService directly. All that is needed is a note in the tracing documentation that tracing will not propegate across ExecutorService unless that flag is enabled.

@dansiviter
Copy link
Author

FYI, I've noticed that flag doesn't work for OpenTelemetry as there is no OTel equivalent for ThreadTracingInvocationInstrumentFactory.

@n0tl3ss
Copy link
Member

n0tl3ss commented Oct 26, 2022

We can add ThreadTracingInvocationInstrumentFactory for OTel if it is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting validation Waiting to be validated as a real issue
Projects
None yet
Development

No branches or pull requests

3 participants