Skip to content

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

@Ajay1735

Description

@Ajay1735

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.");
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions