10000 Do not inspect reactor context when not needed by amarziali · Pull Request #8745 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Do not inspect reactor context when not needed #8745

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

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
10000
Diff view
Do not inspect reactor context when not needed
  • Loading branch information
amarziali committed Apr 28, 2025
commit cdc63bd13060d909ad05f844ad0f23736680ba59
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,37 @@
import datadog.trace.bootstrap.instrumentation.api.WithAgentSpan;
import javax.annotation.Nullable;
import reactor.core.CoreSubscriber;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;

public class ContextSpanHelper {

private static final Class<?> MONO_WITH_CONTEXT_CLASS = findMonoWithContextClass();

private static final String DD_SPAN_KEY = "dd.span";

private static Class<?> findMonoWithContextClass() {
final ClassLoader classLoader = Mono.class.getClassLoader();
// 3.4+
try {
return Class.forName(
"reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber", false, classLoader);
} catch (Throwable ignored) {
}
// < 3.4
try {
return Class.forName(
"reactor.core.publisher.FluxContextStart$ContextStartSubscriber", false, classLoader);
} catch (Throwable ignored) {
}
return null;
}

private ContextSpanHelper() {}

@Nullable
public static AgentSpan extractSpanFromSubscriberContext(final CoreSubscriber<?> subscriber) {
if (subscriber == null) {
if (MONO_WITH_CONTEXT_CLASS == null || !MONO_WITH_CONTEXT_CLASS.isInstance(subscriber)) {
return null;
}
Context context = null;
Expand Down
Loading
0