Skip to content

Commit 58ae723

Browse files
committed
Add more telemetry
1 parent 2b4f917 commit 58ae723

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

dd-java-agent/agent-crashtracking/src/main/java/datadog/crashtracking/CrashUploaderScriptInitializer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static datadog.crashtracking.Initializer.findAgentJar;
77
import static datadog.crashtracking.Initializer.getCrashUploaderTemplate;
88
import static datadog.crashtracking.Initializer.writeConfig;
9+
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
910
import static java.nio.file.attribute.PosixFilePermissions.asFileAttribute;
1011
import static java.nio.file.attribute.PosixFilePermissions.fromString;
1112
import static java.util.Locale.ROOT;
@@ -30,7 +31,8 @@ private CrashUploaderScriptInitializer() {}
3031
// @VisibleForTests
3132
static void initialize(String onErrorVal, String onErrorFile) {
3233
if (onErrorVal == null || onErrorVal.isEmpty()) {
33-
LOG.debug("'-XX:OnError' argument was not provided. Crash tracking is disabled.");
34+
LOG.debug(
35+
SEND_TELEMETRY, "'-XX:OnError' argument was not provided. Crash tracking is disabled.");
3436
return;
3537
}
3638
if (onErrorFile == null || onErrorFile.isEmpty()) {
@@ -42,7 +44,7 @@ static void initialize(String onErrorVal, String onErrorFile) {
4244

4345
String agentJar = findAgentJar();
4446
if (agentJar == null) {
45-
LOG.warn("Unable to locate the agent jar. {}", SETUP_FAILURE_MESSAGE);
47+
LOG.warn(SEND_TELEMETRY, "Unable to locate the agent jar. {}", SETUP_FAILURE_MESSAGE);
4648
return;
4749
}
4850

@@ -63,6 +65,7 @@ private static boolean copyCrashUploaderScript(
6365
Files.createDirectories(scriptDirectory, asFileAttribute(fromString(RWXRWXRWX)));
6466
} catch (UnsupportedOperationException e) {
6567
LOG.warn(
68+
SEND_TELEMETRY,
6669
"Unsupported permissions {} for {}. {}",
6770
RWXRWXRWX,
6871
scriptDirectory,
@@ -71,11 +74,13 @@ private static boolean copyCrashUploaderScript(
7174
} catch (FileAlreadyExistsException ignored) {
7275
// can be safely ignored; if the folder exists we will just reuse it
7376
if (!Files.isWritable(scriptDirectory)) {
74-
LOG.warn("Read only directory {}. {}", scriptDirectory, SETUP_FAILURE_MESSAGE);
77+
LOG.warn(
78+
SEND_TELEMETRY, "Read only directory {}. {}", scriptDirectory, SETUP_FAILURE_MESSAGE);
7579
return false;
7680
}
7781
} catch (IOException e) {
7882
LOG.warn(
83+
SEND_TELEMETRY,
7984
"Failed to create writable crash tracking script folder {}. {}",
8085
scriptDirectory,
8186
SETUP_FAILURE_MESSAGE);

dd-java-agent/agent-crashtracking/src/main/java/datadog/crashtracking/Initializer.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ static void writeConfig(Path scriptPath, String... entries) {
176176
LOG.debug("Deleting config file: {}", cfgPath);
177177
Files.deleteIfExists(cfgPath);
178178
} catch (IOException e) {
179-
LOG.warn("Failed deleting config file: {}", cfgPath, e);
179+
LOG.warn(SEND_TELEMETRY, "Failed deleting config file: {}", cfgPath, e);
180180
}
181181
}));
182182
LOG.debug("Config file written: {}", cfgPath);
183183
} catch (IOException e) {
184-
LOG.warn("Failed writing config file: {}", cfgPath);
184+
LOG.warn(SEND_TELEMETRY, "Failed writing config file: {}", cfgPath);
185185
try {
186186
Files.deleteIfExists(cfgPath);
187187
} catch (IOException ignored) {
@@ -229,7 +229,10 @@ private static void initializeCrashUploader(FlagAccess flags) {
229229
// set the JVM flag
230230
boolean rslt = flags.setValue("OnError", onErrorVal);
231231
if (!rslt && LOG.isDebugEnabled()) {
232-
LOG.debug("Unable to set OnError flag to {}. Crash-tracking may not work.", onErrorVal);
232+
LOG.debug(
233+
SEND_TELEMETRY,
234+
"Unable to set OnError flag to {}. Crash-tracking may not work.",
235+
onErrorVal);
233236
}
234237

235238
CrashUploaderScriptInitializer.initialize(uploadScript, onErrorFile);
@@ -261,13 +264,11 @@ private static void initializeOOMENotifier(FlagAccess flags) {
261264
}
262265
}
263266

264-
System.out.println("===> Initializing OOME notifier script: " + notifierScript);
265-
System.out.flush();
266-
267267
// set the JVM flag
268268
boolean rslt = flags.setValue("OnOutOfMemoryError", onOutOfMemoryVal);
269269
if (!rslt && LOG.isDebugEnabled()) {
270270
LOG.debug(
271+
SEND_TELEMETRY,
271272
"Unable to set OnOutOfMemoryError flag to {}. OOME tracking may not work.",
272273
onOutOfMemoryVal);
273274
}
@@ -292,9 +293,10 @@ private static String getScriptFileName(String scriptName) {
292293

293294
private static void logInitializationError(String msg, Throwable t) {
294295
if (LOG.isDebugEnabled()) {
295-
LOG.warn("{}", msg, t);
296+
LOG.warn(SEND_TELEMETRY, "{}", msg, t);
296297
} else {
297298
LOG.warn(
299+
SEND_TELEMETRY,
298300
"{} [{}] (Change the logging level to debug to see the full stacktrace)",
299301
msg,
300302
t.getMessage());

dd-java-agent/agent-crashtracking/src/main/java/datadog/crashtracking/OOMENotifierScriptInitializer.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static datadog.crashtracking.Initializer.findAgentJar;
88
import static datadog.crashtracking.Initializer.getOomeNotifierTemplate;
99
import static datadog.crashtracking.Initializer.writeConfig;
10+
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
1011
import static java.nio.file.FileVisitResult.CONTINUE;
1112
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
1213
import static java.nio.file.attribute.PosixFilePermissions.asFileAttribute;
@@ -37,20 +38,24 @@ private OOMENotifierScriptInitializer() {}
3738
// @VisibleForTests
3839
static void initialize(String onOutOfMemoryVal) {
3940
if (onOutOfMemoryVal == null || onOutOfMemoryVal.isEmpty()) {
40-
LOG.debug("'-XX:OnOutOfMemoryError' argument was not provided. OOME tracking is disabled.");
41+
LOG.debug(
42+
SEND_TELEMETRY,
43+
"'-XX:OnOutOfMemoryError' argument was not provided. OOME tracking is disabled.");
4144
return;
4245
}
4346
Path scriptPath = getOOMEScripPath(onOutOfMemoryVal);
44-
System.out.println("===> OOME notifier script path: " + scriptPath);
4547
if (scriptPath == null) {
4648
LOG.debug(
49+
SEND_TELEMETRY,
4750
"OOME notifier script value ({}) does not follow the expected format: <path>/dd_oome_notifier.(sh|bat) %p. OOME tracking is disabled.",
4851
onOutOfMemoryVal);
4952
return;
5053
}
5154
String agentJar = findAgentJar();
5255
if (agentJar == null) {
53-
LOG.warn("Unable to locate the agent jar. OOME notification will not work properly.");
56+
LOG.warn(
57+
SEND_TELEMETRY,
58+
"Unable to locate the agent jar. OOME notification will not work properly.");
5459
return;
5560
}
5661
if (!copyOOMEscript(scriptPath)) {
@@ -85,6 +90,7 @@ private static boolean copyOOMEscript(Path scriptPath) {
8590
Files.createDirectories(scriptDirectory, asFileAttribute(fromString(RWXRWXRWX)));
8691
} catch (UnsupportedOperationException e) {
8792
LOG.warn(
93+
SEND_TELEMETRY,
8894
"Unsupported permissions {} for {}. OOME notification will not work properly.",
8995
RWXRWXRWX,
9096
scriptDirectory);
@@ -93,11 +99,14 @@ private static boolean copyOOMEscript(Path scriptPath) {
9399
// can be safely ignored; if the folder exists we will just reuse it
94100
if (!Files.isWritable(scriptDirectory)) {
95101
LOG.warn(
96-
"Read only directory {}. OOME notification will not work properly.", scriptDirectory);
102+
SEND_TELEMETRY,
103+
"Read only directory {}. OOME notification will not work properly.",
104+
scriptDirectory);
97105
return false;
98106
}
99107
} catch (IOException e) {
100108
LOG.warn(
109+
SEND_TELEMETRY,
101110
"Failed to create writable OOME script folder {}. OOME notification will not work properly.",
102111
scriptDirectory);
103112
return false;
@@ -108,7 +117,9 @@ private static boolean copyOOMEscript(Path scriptPath) {
108117
Files.setPosixFilePermissions(scriptPath, fromString(R_XR_XR_X));
109118
} catch (IOException e) {
110119
LOG.warn(
111-
"Failed to copy OOME script {}. OOME notification will not work properly.", scriptPath);
120+
SEND_TELEMETRY,
121+
"Failed to copy OOME script {}. OOME notification will not work properly.",
122+
scriptPath);
112123
return false;
113124
}
114125
return true;

0 commit comments

Comments
 (0)