Skip to content

Mute tracing for subprocesses executed by bootstrap telemetry logic. #9005

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datadog.json.JsonWriter;
import de.thetaphi.forbiddenapis.SuppressForbidden;
import java.io.Closeable;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -211,7 +212,8 @@ public ForwarderJsonSenderThread(String forwarderPath, byte[] payload) {
public void run() {
ProcessBuilder builder = new ProcessBuilder(forwarderPath, "library_entrypoint");

try {
// Run forwarder and mute tracing for subprocesses executed in by dd-java-agent.
try (final Closeable ignored = muteTracing()) {
Process process = builder.start();
try (OutputStream out = process.getOutputStream()) {
out.write(payload);
Expand All @@ -221,5 +223,19 @@ public void run() {
System.err.println("Failed to send telemetry: " + e.getMessage());
}
}

@SuppressForbidden
private Closeable muteTracing() {
try {
Class<?> agentTracerClass =
Class.forName("datadog.trace.bootstrap.instrumentation.api.AgentTracer");
Object tracerAPI = agentTracerClass.getMethod("get").invoke(null);
Object scope = tracerAPI.getClass().getMethod("muteTracing").invoke(tracerAPI);
return (Closeable) scope;
} catch (Throwable e) {
// Ignore all exceptions and fallback to No-Op Closable.
return () -> {};
}
}
}
}
Loading