Skip to content

Commit 79c5bb1

Browse files
author
Matt
committed
Dump profiling template override & report profiling initialization errors within flare
1 parent 00555b1 commit 79c5bb1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,40 @@
66
import datadog.trace.api.flare.TracerFlare;
77
import datadog.trace.bootstrap.config.provider.ConfigProvider;
88
import java.io.IOException;
9+
import java.nio.charset.StandardCharsets;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
913
import java.util.Map;
1014
import java.util.zip.ZipOutputStream;
1115

1216
public final class ProfilerFlare implements TracerFlare.Reporter {
1317
private static final ProfilerFlare INSTANCE = new ProfilerFlare();
18+
private static Exception profilerInitializationException;
1419

1520
public static void register() {
1621
TracerFlare.addReporter(INSTANCE);
1722
}
1823

24+
public static void reportInitializationException(Exception e) {
25+
profilerInitializationException = e;
26+
}
27+
1928
@Override
2029
public void addReportToFlare(ZipOutputStream zip) throws IOException {
2130
TracerFlare.addText(zip, "profiler_config.txt", getProfilerConfig());
31+
String templateOverrideFile = Config.get().getProfilingTemplateOverrideFile();
32+
if (templateOverrideFile != null) {
33+
try {
34+
Path path = Paths.get(templateOverrideFile);
35+
if (Files.exists(path)) {
36+
String fileContents = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
37+
TracerFlare.addText(zip, "profiling_template_override.jfp", fileContents);
38+
}
39+
} catch (IOException e) {
40+
// no-op, ignore if we can't read the template override file
41+
}
42+
}
2243
}
2344

2445
private String getProfilerConfig() {
@@ -29,6 +50,15 @@ private String getProfilerConfig() {
2950
ConfigProvider configProvider = ConfigProvider.getInstance();
3051
Config config = Config.get();
3152

53+
sb.append("=== Profiler Initalization Status ===\n");
54+
if (profilerInitializationException == null) {
55+
sb.append("Profiler initialized successfully.\n");
56+
} else {
57+
sb.append("Profiler initializtion failed due to: \n");
58+
sb.append(profilerInitializationException.getMessage());
59+
sb.append("\n");
60+
}
61+
3262
sb.append("=== Core Settings ===\n");
3363
appendConfig(
3464
sb,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,13 @@ public static synchronized boolean run(final boolean earlyStart, Instrumentation
174174
log.warn(e.getMessage());
175175
// no need to send telemetry for this aggregate message
176176
// a detailed telemetry message has been sent from the attempts to enable the controllers
177+
// -----------------------------------------------------------------------------------------
178+
// but we do want to report this within the profiler flare
179+
ProfilerFlare.reportInitializationException(e);
177180
} catch (final ConfigurationException e) {
178181
log.warn("Failed to initialize profiling agent! {}", e.getMessage());
179182
log.debug(SEND_TELEMETRY, "Failed to initialize profiling agent!", e);
183+
ProfilerFlare.reportInitializationException(e);
180184
}
181185
}
182186
return false;

0 commit comments

Comments
 (0)