Skip to content

Commit 39cb67c

Browse files
jbachorikclaude
andcommitted
Remove tracing from JFR scrubbing operation
Tracing instrumentation in ScrubRecordingDataListener causes build-time initialization of tracer classes during GraalVM native-image compilation when the agent is attached via -J-javaagent. This results in "Classes that should be initialized at run time got initialized during image building" errors. Removing the spans/metrics maintains native-image compatibility while preserving the core scrubbing functionality. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 721ee67 commit 39cb67c

1 file changed

Lines changed: 29 additions & 55 deletions

File tree

dd-java-agent/agent-profiling/src/main/java/com/datadog/profiling/agent/ScrubRecordingDataListener.java

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
import datadog.trace.api.profiling.RecordingDataListener;
88
import datadog.trace.api.profiling.RecordingInputStream;
99
import datadog.trace.api.profiling.RecordingType;
10-
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
11-
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
12-
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
13-
import datadog.trace.bootstrap.instrumentation.api.Tags;
1410
import java.io.IOException;
1511
import java.nio.file.Files;
1612
import java.nio.file.Path;
@@ -42,62 +38,40 @@ final class ScrubRecordingDataListener implements RecordingDataListener {
4238

4339
@Override
4440
public void onNewData(RecordingType type, RecordingData data, boolean handleSynchronously) {
45-
AgentSpan span = AgentTracer.startSpan("profiling", "profiling.scrub");
46-
span.setResourceName("JFR Scrub");
47-
span.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_INTERNAL);
48-
span.setTag(Tags.COMPONENT, "profiler");
49-
50-
try (AgentScope scope = AgentTracer.activateSpan(span)) {
51-
Path tempInput = null;
52-
Path tempOutput = null;
53-
try {
54-
// Use the existing file path when available (eg. ddprof), otherwise materialize the stream
55-
Path inputPath = data.getPath();
56-
boolean fileBacked = inputPath != null;
57-
span.setTag("_dd.profiling.scrub.file_backed", fileBacked);
58-
59-
if (inputPath == null) {
60-
tempInput = Files.createTempFile(tempDir, "dd-scrub-in-", ".jfr");
61-
Files.copy(data.getStream(), tempInput, StandardCopyOption.REPLACE_EXISTING);
62-
inputPath = tempInput;
63-
}
64-
65-
long inputSize = Files.size(inputPath);
66-
span.setTag("_dd.profiling.scrub.input_size", inputSize);
67-
68-
tempOutput = Files.createTempFile(tempDir, "dd-scrub-out-", ".jfr");
69-
scrubber.scrubFile(inputPath, tempOutput);
41+
Path tempInput = null;
42+
Path tempOutput = null;
43+
try {
44+
// Use the existing file path when available (eg. ddprof), otherwise materialize the stream
45+
Path inputPath = data.getPath();
46+
47+
if (inputPath == null) {
48+
tempInput = Files.createTempFile(tempDir, "dd-scrub-in-", ".jfr");
49+
Files.copy(data.getStream(), tempInput, StandardCopyOption.REPLACE_EXISTING);
50+
inputPath = tempInput;
51+
}
7052

71-
long outputSize = Files.size(tempOutput);
72-
span.setTag("_dd.profiling.scrub.output_size", outputSize);
53+
tempOutput = Files.createTempFile(tempDir, "dd-scrub-out-", ".jfr");
54+
scrubber.scrubFile(inputPath, tempOutput);
7355

74-
if (tempInput != null) {
75-
Files.deleteIfExists(tempInput);
76-
tempInput = null;
77-
}
56+
if (tempInput != null) {
57+
Files.deleteIfExists(tempInput);
58+
tempInput = null;
59+
}
7860

79-
ScrubbedRecordingData scrubbed = new ScrubbedRecordingData(data, tempOutput);
80-
tempOutput = null; // ownership transferred to ScrubbedRecordingData
61+
ScrubbedRecordingData scrubbed = new ScrubbedRecordingData(data, tempOutput);
62+
tempOutput = null; // ownership transferred to ScrubbedRecordingData
63+
data.release();
64+
delegate.onNewData(type, scrubbed, handleSynchronously);
65+
} catch (Exception e) {
66+
cleanupQuietly(tempInput);
67+
cleanupQuietly(tempOutput);
68+
if (failOpen) {
69+
log.warn(SEND_TELEMETRY, "JFR scrubbing failed, uploading unscrubbed data", e);
70+
delegate.onNewData(type, data, handleSynchronously);
71+
} else {
72+
log.error(SEND_TELEMETRY, "JFR scrubbing failed, skipping upload", e);
8173
data.release();
82-
delegate.onNewData(type, scrubbed, handleSynchronously);
83-
} catch (Exception e) {
84-
span.setError(true);
85-
span.addThrowable(e);
86-
87-
cleanupQuietly(tempInput);
88-
cleanupQuietly(tempOutput);
89-
if (failOpen) {
90-
span.setTag("_dd.profiling.scrub.fail_open", true);
91-
log.warn(SEND_TELEMETRY, "JFR scrubbing failed, uploading unscrubbed data", e);
92-
delegate.onNewData(type, data, handleSynchronously);
93-
} else {
94-
span.setTag("_dd.profiling.scrub.fail_open", false);
95-
log.error(SEND_TELEMETRY, "JFR scrubbing failed, skipping upload", e);
96-
data.release();
97-
}
9874
}
99-
} finally {
100-
span.finish();
10175
}
10276
}
10377

0 commit comments

Comments
 (0)