|
7 | 7 | import datadog.trace.api.profiling.RecordingDataListener; |
8 | 8 | import datadog.trace.api.profiling.RecordingInputStream; |
9 | 9 | 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; |
14 | 10 | import java.io.IOException; |
15 | 11 | import java.nio.file.Files; |
16 | 12 | import java.nio.file.Path; |
@@ -42,62 +38,40 @@ final class ScrubRecordingDataListener implements RecordingDataListener { |
42 | 38 |
|
43 | 39 | @Override |
44 | 40 | 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 | + } |
70 | 52 |
|
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); |
73 | 55 |
|
74 | | - if (tempInput != null) { |
75 | | - Files.deleteIfExists(tempInput); |
76 | | - tempInput = null; |
77 | | - } |
| 56 | + if (tempInput != null) { |
| 57 | + Files.deleteIfExists(tempInput); |
| 58 | + tempInput = null; |
| 59 | + } |
78 | 60 |
|
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); |
81 | 73 | 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 | | - } |
98 | 74 | } |
99 | | - } finally { |
100 | | - span.finish(); |
101 | 75 | } |
102 | 76 | } |
103 | 77 |
|
|
0 commit comments