Skip to content

Datadog context is not passed inside virtual threads. #9984

@clutcher

Description

@clutcher

Tracer Version(s)

1.55

Java Version(s)

24.0.2

JVM Vendor

Amazon Corretto

Bug Report

We have Spring Boot 3.5.7 with Spring GraphQL + using Spring HTTP Interfacases for requests. With enabled virtual threads there are no datadog trace id inside GraphQL execution context in in outbound requests made by Spring HTTP Interfaces.

To fix that we created custom code to manually pass datadog context inside virtual threads with TaskDecorator:

import datadog.trace.api.GlobalTracer;
import datadog.trace.api.Tracer;
import datadog.trace.context.TraceScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskDecorator;

@Configuration
public class TracingConfiguration {

    @Bean
    public TaskDecorator datadogContextPropagatingTaskDecorator() {
        return runnable -> {
            Tracer tracer = GlobalTracer.get();
            TraceScope.Continuation continuation = tracer.captureActiveSpan();

            return () -> {
                if (continuation != null) {
                    try (TraceScope scope = continuation.activate()) {
                        runnable.run();
                    }
                } else {
                    runnable.run();
                }
            };
        };
    }
}

Expected Behavior

datadog agent automaticaly passes own context inside virtual threads and doesn't require manual context passing with custom code.

Reproduction Code

No response

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