Skip to content

Commit 8f0b20e

Browse files
authored
Store crashtracking options on the main process (#10036)
1 parent 0df702a commit 8f0b20e

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public static class StoredConfig {
3333
final String processTags;
3434
final String runtimeId;
3535
final String reportUUID;
36+
final boolean agentless;
37+
final boolean sendToErrorTracking;
3638

3739
StoredConfig(
3840
String reportUUID,
@@ -41,14 +43,18 @@ public static class StoredConfig {
4143
String version,
4244
String tags,
4345
String processTags,
44-
String runtimeId) {
46+
String runtimeId,
47+
boolean agentless,
48+
boolean sendToErrorTracking) {
4549
this.service = service;
4650
this.env = env;
4751
this.version = version;
4852
this.tags = tags;
4953
this.processTags = processTags;
5054
this.runtimeId = runtimeId;
5155
this.reportUUID = reportUUID;
56+
this.agentless = agentless;
57+
this.sendToErrorTracking = sendToErrorTracking;
5258
}
5359

5460
public static class Builder {
@@ -59,6 +65,8 @@ public static class Builder {
5965
String processTags;
6066
String runtimeId;
6167
String reportUUID;
68+
boolean agentless;
69+
boolean sendToErrorTracking;
6270

6371
public Builder(Config config) {
6472
// get sane defaults
@@ -67,6 +75,8 @@ public Builder(Config config) {
6775
this.version = config.getVersion();
6876
this.runtimeId = config.getRuntimeId();
6977
this.reportUUID = RandomUtils.randomUUID().toString();
78+
this.agentless = config.isCrashTrackingAgentless();
79+
this.sendToErrorTracking = config.isCrashTrackingErrorsIntakeEnabled();
7080
}
7181

7282
public Builder service(String service) {
@@ -99,14 +109,33 @@ public Builder runtimeId(String runtimeId) {
99109
return this;
100110
}
101111

112+
public Builder sendToErrorTracking(boolean sendToErrorTracking) {
113+
this.sendToErrorTracking = sendToErrorTracking;
114+
return this;
115+
}
116+
117+
public Builder agentless(boolean agentless) {
118+
this.agentless = agentless;
119+
return this;
120+
}
121+
102122
// @VisibleForTesting
103123
Builder reportUUID(String reportUUID) {
104124
this.reportUUID = reportUUID;
105125
return this;
106126
}
107127

108128
public StoredConfig build() {
109-
return new StoredConfig(reportUUID, service, env, version, tags, processTags, runtimeId);
129+
return new StoredConfig(
130+
reportUUID,
131+
service,
132+
env,
133+
version,
134+
tags,
135+
processTags,
136+
runtimeId,
137+
agentless,
138+
sendToErrorTracking);
110139
}
111140
}
112141
}
@@ -163,6 +192,8 @@ static void writeConfigToFile(Config config, Path cfgPath, String... additionalE
163192
writeEntry(bw, "process_tags", ProcessTags.getTagsForSerialization());
164193
writeEntry(bw, "runtime_id", wellKnownTags.getRuntimeId());
165194
writeEntry(bw, "java_home", SystemProperties.get("java.home"));
195+
writeEntry(bw, "agentless", Boolean.toString(config.isCrashTrackingAgentless()));
196+
writeEntry(bw, "upload_to_et", Boolean.toString(config.isCrashTrackingErrorsIntakeEnabled()));
166197

167198
Runtime.getRuntime()
168199
.addShutdownHook(
@@ -220,6 +251,12 @@ public static StoredConfig readConfig(Config config, Path scriptPath) {
220251
case "runtime_id":
221252
cfgBuilder.runtimeId(value);
222253
break;
254+
case "agentless":
255+
cfgBuilder.agentless(Boolean.parseBoolean(value));
256+
break;
257+
case "upload_to_et":
258+
cfgBuilder.sendToErrorTracking(Boolean.parseBoolean(value));
259+
break;
223260
default:
224261
// ignore
225262
break;

dd-java-agent/agent-crashtracking/src/test/java/datadog/crashtracking/ConfigManagerTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package datadog.crashtracking;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46
import static org.mockito.Mockito.mock;
57
import static org.mockito.Mockito.when;
68

@@ -20,6 +22,8 @@ public void testConfigWriteAndRead() throws IOException {
2022
Config config = mock(Config.class);
2123
when(config.getWellKnownTags())
2224
.thenReturn(new WellKnownTags("1234", "", "env", "service", "version", ""));
25+
when(config.isCrashTrackingAgentless()).thenReturn(false);
26+
when(config.isCrashTrackingErrorsIntakeEnabled()).thenReturn(true);
2327
when(config.getMergedCrashTrackingTags()).thenReturn(Collections.singletonMap("key", "value"));
2428
File tmpFile = File.createTempFile("ConfigManagerTest", null);
2529
tmpFile.deleteOnExit();
@@ -35,6 +39,8 @@ public void testConfigWriteAndRead() throws IOException {
3539
assertEquals(
3640
Objects.requireNonNull(ProcessTags.getTagsForSerialization()).toString(),
3741
deserialized.processTags);
42+
assertFalse(deserialized.agentless);
43+
assertTrue(deserialized.sendToErrorTracking);
3844
}
3945

4046
@Test
@@ -48,5 +54,7 @@ public void testStoredConfigDefaults() {
4854
assertEquals("service", storedConfig.service);
4955
assertEquals("version", storedConfig.version);
5056
assertEquals("env", storedConfig.env);
57+
assertFalse(storedConfig.agentless);
58+
assertFalse(storedConfig.sendToErrorTracking);
5159
}
5260
}

0 commit comments

Comments
 (0)