Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static class StoredConfig {
final String processTags;
final String runtimeId;
final String reportUUID;
final boolean agentless;
final boolean sendToErrorTracking;

StoredConfig(
String reportUUID,
Expand All @@ -41,14 +43,18 @@ public static class StoredConfig {
String version,
String tags,
String processTags,
String runtimeId) {
String runtimeId,
boolean agentless,
boolean sendToErrorTracking) {
this.service = service;
this.env = env;
this.version = version;
this.tags = tags;
this.processTags = processTags;
this.runtimeId = runtimeId;
this.reportUUID = reportUUID;
this.agentless = agentless;
this.sendToErrorTracking = sendToErrorTracking;
}

public static class Builder {
Expand All @@ -59,6 +65,8 @@ public static class Builder {
String processTags;
String runtimeId;
String reportUUID;
boolean agentless;
boolean sendToErrorTracking;

public Builder(Config config) {
// get sane defaults
Expand All @@ -67,6 +75,8 @@ public Builder(Config config) {
this.version = config.getVersion();
this.runtimeId = config.getRuntimeId();
this.reportUUID = RandomUtils.randomUUID().toString();
this.agentless = config.isCrashTrackingAgentless();
this.sendToErrorTracking = config.isCrashTrackingErrorsIntakeEnabled();
}

public Builder service(String service) {
Expand Down Expand Up @@ -99,14 +109,33 @@ public Builder runtimeId(String runtimeId) {
return this;
}

public Builder sendToErrorTracking(boolean sendToErrorTracking) {
this.sendToErrorTracking = sendToErrorTracking;
return this;
}

public Builder agentless(boolean agentless) {
this.agentless = agentless;
return this;
}

// @VisibleForTesting
Builder reportUUID(String reportUUID) {
this.reportUUID = reportUUID;
return this;
}

public StoredConfig build() {
return new StoredConfig(reportUUID, service, env, version, tags, processTags, runtimeId);
return new StoredConfig(
reportUUID,
service,
env,
version,
tags,
processTags,
runtimeId,
agentless,
sendToErrorTracking);
}
}
}
Expand Down Expand Up @@ -163,6 +192,8 @@ static void writeConfigToFile(Config config, Path cfgPath, String... additionalE
writeEntry(bw, "process_tags", ProcessTags.getTagsForSerialization());
writeEntry(bw, "runtime_id", wellKnownTags.getRuntimeId());
writeEntry(bw, "java_home", SystemProperties.get("java.home"));
writeEntry(bw, "agentless", Boolean.toString(config.isCrashTrackingAgentless()));
writeEntry(bw, "upload_to_et", Boolean.toString(config.isCrashTrackingErrorsIntakeEnabled()));

Runtime.getRuntime()
.addShutdownHook(
Expand Down Expand Up @@ -220,6 +251,12 @@ public static StoredConfig readConfig(Config config, Path scriptPath) {
case "runtime_id":
cfgBuilder.runtimeId(value);
break;
case "agentless":
cfgBuilder.agentless(Boolean.parseBoolean(value));
break;
case "upload_to_et":
cfgBuilder.sendToErrorTracking(Boolean.parseBoolean(value));
break;
default:
// ignore
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package datadog.crashtracking;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -20,6 +22,8 @@ public void testConfigWriteAndRead() throws IOException {
Config config = mock(Config.class);
when(config.getWellKnownTags())
.thenReturn(new WellKnownTags("1234", "", "env", "service", "version", ""));
when(config.isCrashTrackingAgentless()).thenReturn(false);
when(config.isCrashTrackingErrorsIntakeEnabled()).thenReturn(true);
when(config.getMergedCrashTrackingTags()).thenReturn(Collections.singletonMap("key", "value"));
File tmpFile = File.createTempFile("ConfigManagerTest", null);
tmpFile.deleteOnExit();
Expand All @@ -35,6 +39,8 @@ public void testConfigWriteAndRead() throws IOException {
assertEquals(
Objects.requireNonNull(ProcessTags.getTagsForSerialization()).toString(),
deserialized.processTags);
assertFalse(deserialized.agentless);
assertTrue(deserialized.sendToErrorTracking);
}

@Test
Expand All @@ -48,5 +54,7 @@ public void testStoredConfigDefaults() {
assertEquals("service", storedConfig.service);
assertEquals("version", storedConfig.version);
assertEquals("env", storedConfig.env);
assertFalse(storedConfig.agentless);
assertFalse(storedConfig.sendToErrorTracking);
}
}