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

DD tracing is not working with virtual threads for a micronaut 4 application #6468

Open
Ajay1735 opened this issue Jan 11, 2024 · 9 comments

Comments

@Ajay1735
Copy link

Ajay1735 commented Jan 11, 2024

Problem
I have a Micronaut-based microservice on micronaut 4 and java 21. It is not sending traces to Datadog when used with virtual threads, but is able to send traces when used with event loops. Basically tracing is not working with changing the @ExecuteOn(TaskExecutors.IO) annotation to @ExecuteOn(TaskExecutors.BLOCKING) on controller.

I was trying to debug in local and using latest dd agent, I could see that the span is not created when the controller method is executed with virtual threads.

Used below block in my controller to fetch trace_id.

        Tracer tracer = GlobalTracer.get();
        Span currentSpan = tracer.activeSpan();
        if (currentSpan != null) {
            // Retrieve the trace ID
            String traceId = currentSpan.context().toTraceId();

            // Use the trace ID as needed
            log.info("dd.trace_id=" + traceId);
        } else {
            log.info("No active span found.");
        }
@ketola
Copy link

ketola commented Jan 12, 2024

I have also noticed an issue with virtual threads. I have tried agent versions 1.26.1 and 1.27.0 to rule out the possibility of the regression coming from the agent upgrade. I also tested with both eclipse-temurin 21 and amazon-corretto 21, so it does not seem to be related to the java distribution.
I can see the resources and their response times, but in the resource names the path parameter names have been replaced by question marks and I cannot see any spans or jdbc data from the calls.

I am using Quarkus 3.6.4 with virtual thread enabled for endpoints.

@nayeem-kamal
Copy link
Contributor

@Ajay1735 Thank you for your feedback. At this time, the Java tracer does not have support for virtual threads with Java 21. Because of this, the behavior you are observing is not unexpected. This is something we are looking to add support for in the near future.

@ketola
Copy link

ketola commented Jan 17, 2024

@Ajay1735 Thank you for your feedback. At this time, the Java tracer does not have support for virtual threads with Java 21. Because of this, the behavior you are observing is not unexpected. This is something we are looking to add support for in the near future.

@nayeem-kamal I wish you could try to increase the priority on this one as virtual threads are a core feature of Java 21 and it's considered have major performance improvements on Java web applications. Also the major frameworks like Quarkus, Micronaut and Spring are already supporting it.

@Ajay1735
Copy link
Author

Ajay1735 commented Jan 18, 2024

@nayeem-kamal

At this time, the Java tracer does not have support for virtual threads with Java 21.

is this framework agnostic or
it's not yet supported for specific frameworks like micronaut, quarkus but it's supported for spring

@jhchee
Copy link

jhchee commented Mar 12, 2024

@am312 Sorry to tag you here, will this be fixed with your PR?
#6789

@am312
Copy link
Contributor

am312 commented Mar 28, 2024

@jhchee I think so but have not tested w/Micronaut using those particular annotations. If you find that something does not work, please file an issue with Datadog support. Thanks very much.

@Ajay1735
Copy link
Author

Ajay1735 commented Apr 7, 2024

Have done basic testing with latest version of dd-agent, spans are getting created and tracing is working now.
Thanks for the fix!

@ketola
Copy link

ketola commented Apr 8, 2024

I can also confirm that spans are created in a Quarkus application with an endpoint annotated with @RunOnVirtualThread (though there seems to be a delay for the spans. I can see the request almost immediately but it took some time for the spans to appear, but anyway it's working 👍 )

@severous
Copy link

I am very interested in passing traces across virtual threads for this. Could you provide some demo code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants