Skip to content

Add process tags to crashtracking #8810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -14,6 +14,7 @@
import datadog.communication.http.OkHttpUtils;
import datadog.trace.api.Config;
import datadog.trace.api.DDTags;
import datadog.trace.api.ProcessTags;
import datadog.trace.bootstrap.config.provider.ConfigProvider;
import datadog.trace.util.PidHelper;
import datadog.trace.util.RandomUtils;
@@ -139,6 +140,7 @@ void uploadToLogs(@Nonnull String message, @Nonnull PrintStream out) throws IOEx
writer.beginObject();
writer.name("ddsource").value("crashtracker");
writer.name("ddtags").value(tags);
writeProcessTags(writer);
writer.name("hostname").value(config.getHostName());
writer.name("service").value(config.getServiceName());
writer.name("message").value(message);
@@ -156,6 +158,13 @@ void uploadToLogs(@Nonnull String message, @Nonnull PrintStream out) throws IOEx
}
}

private void writeProcessTags(JsonWriter writer) throws IOException {
final CharSequence processTags = ProcessTags.getTagsForSerialization();
if (processTags != null) {
writer.name("process_tags").value(processTags.toString());
}
}

// @VisibleForTesting
@SuppressForbidden
static String extractErrorKind(String fileContent) {
@@ -306,6 +315,7 @@ private RequestBody makeTelemetryRequestBody(@Nonnull String content) throws IOE
writer.name("service_name").value(config.getServiceName());
writer.name("service_version").value(config.getVersion());
writer.name("tracer_version").value(VersionInfo.VERSION);
writeProcessTags(writer);
writer.endObject();
writer.name("host");
writer.beginObject();
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import datadog.common.version.VersionInfo;
import datadog.trace.api.Config;
import datadog.trace.api.ProcessTags;
import datadog.trace.bootstrap.config.provider.ConfigProvider;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -32,6 +33,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

@@ -89,11 +91,13 @@ public void setup() throws IOException {
when(config.getApiKey()).thenReturn(null);
}

@Test
public void testLogsHappyPath() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testLogsHappyPath(boolean collectProcessTags) throws Exception {
// Given

// When
when(config.isExperimentalPropagateProcessTagsEnabled()).thenReturn(collectProcessTags);
ProcessTags.reset(config);
uploader = new CrashUploader(config);
ByteArrayOutputStream out = new ByteArrayOutputStream();
uploader.uploadToLogs(CRASH, new PrintStream(out));
@@ -107,6 +111,13 @@ public void testLogsHappyPath() throws Exception {
assertEquals(SERVICE, event.get("service").asText());
assertEquals(CRASH, event.get("message").asText());
assertEquals("ERROR", event.get("level").asText());
if (collectProcessTags) {
assertNotNull(ProcessTags.getTagsForSerialization());
assertEquals(
ProcessTags.getTagsForSerialization().toString(), event.get("process_tags").asText());
} else {
assertNull(event.get("process_tags"));
}
}

@Test
@@ -143,14 +154,15 @@ private Path getResourcePath(String resourceName) throws Exception {
}

@ParameterizedTest
@ValueSource(
strings = {
"sample-crash-for-telemetry.txt",
"sample-crash-for-telemetry-2.txt",
"sample-crash-for-telemetry-3.txt"
})
public void testTelemetryHappyPath(String log) throws Exception {
@CsvSource({
"sample-crash-for-telemetry.txt,true",
"sample-crash-for-telemetry-2.txt,false",
"sample-crash-for-telemetry-3.txt,false"
})
public void testTelemetryHappyPath(String log, boolean collectProcessTags) throws Exception {
// Given
when(config.isExperimentalPropagateProcessTagsEnabled()).thenReturn(collectProcessTags);
ProcessTags.reset(config);
CrashLog expected = CrashLog.fromJson(readFileAsString("golden/" + log));

// When
@@ -192,6 +204,14 @@ public void testTelemetryHappyPath(String log) throws Exception {
// host
assertEquals(HOSTNAME, event.get("host").get("hostname").asText());
assertEquals(ENV, event.get("host").get("env").asText());
if (collectProcessTags) {
assertNotNull(ProcessTags.getTagsForSerialization());
assertEquals(
ProcessTags.getTagsForSerialization().toString(),
event.get("application").get("process_tags").asText());
} else {
assertNull(event.get("application").get("process_tags"));
}
}

@Test
Loading