-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for new telemetry crash data format
- Loading branch information
Showing
20 changed files
with
11,554 additions
and
142 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...ava-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/CrashLogParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.datadog.crashtracking; | ||
|
||
import com.datadog.crashtracking.dto.CrashLog; | ||
import com.datadog.crashtracking.parsers.HotspotCrashLogParser; | ||
|
||
public final class CrashLogParser { | ||
public static CrashLog fromHotspotCrashLog(String logText) { | ||
return new HotspotCrashLogParser().parse(logText); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
dd-java-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/dto/CrashLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.datadog.crashtracking.dto; | ||
|
||
import com.squareup.moshi.Json; | ||
import com.squareup.moshi.JsonAdapter; | ||
import com.squareup.moshi.Moshi; | ||
import java.util.UUID; | ||
|
||
public final class CrashLog { | ||
private static final int VERSION = 0; | ||
|
||
private static final JsonAdapter<CrashLog> ADAPTER; | ||
|
||
static { | ||
Moshi moshi = new Moshi.Builder().add(new SemanticVersion.SemanticVersionAdapter()).build(); | ||
ADAPTER = moshi.adapter(CrashLog.class); | ||
} | ||
|
||
public final String uuid = UUID.randomUUID().toString(); | ||
public final String timestamp; | ||
public final boolean incomplete; | ||
public final ErrorData error; | ||
public final Metadata metadata; | ||
|
||
@Json(name = "os_info") | ||
public final OSInfo osInfo; | ||
|
||
@Json(name = "proc_info") | ||
public final ProcInfo procInfo; | ||
|
||
@Json(name = "version_id") | ||
public final int version = VERSION; | ||
|
||
public CrashLog( | ||
boolean incomplete, | ||
String timestamp, | ||
ErrorData error, | ||
Metadata metadata, | ||
OSInfo osInfo, | ||
ProcInfo procInfo) { | ||
this.incomplete = incomplete; | ||
this.timestamp = timestamp; | ||
this.error = error; | ||
this.metadata = metadata; | ||
this.osInfo = osInfo; | ||
this.procInfo = procInfo; | ||
} | ||
|
||
public String toJson() { | ||
return ADAPTER.toJson(this); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
dd-java-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/dto/ErrorData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.datadog.crashtracking.dto; | ||
|
||
import com.squareup.moshi.Json; | ||
|
||
public final class ErrorData { | ||
@Json(name = "is_crash") | ||
public final boolean isCrash = true; | ||
|
||
public final String kind; | ||
public final String message; | ||
|
||
@Json(name = "source_type") | ||
public final String sourceType = "crashtracking"; | ||
|
||
public final StackTrace stack; | ||
|
||
public ErrorData(String kind, String message, StackTrace stack) { | ||
this.kind = kind; | ||
this.message = message; | ||
this.stack = stack; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
dd-java-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/dto/Metadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.datadog.crashtracking.dto; | ||
|
||
import com.squareup.moshi.Json; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public final class Metadata { | ||
@Json(name = "library_name") | ||
public final String libraryName; | ||
|
||
@Json(name = "library_version") | ||
public final String libraryVersion; | ||
|
||
public final String family; | ||
public final Map<String, String> tags; | ||
|
||
public Metadata( | ||
String libraryName, String libraryVersion, String family, Map<String, String> tags) { | ||
this.libraryName = libraryName; | ||
this.libraryVersion = libraryVersion; | ||
this.family = family; | ||
this.tags = tags != null ? Collections.unmodifiableMap(tags) : Collections.emptyMap(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
dd-java-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/dto/OSInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.datadog.crashtracking.dto; | ||
|
||
import com.squareup.moshi.Json; | ||
|
||
public final class OSInfo { | ||
public final String architecture; | ||
public final String bitness; | ||
|
||
@Json(name = "os_type") | ||
public final String osType; | ||
|
||
public final SemanticVersion version; | ||
|
||
public OSInfo(String architecture, String bitness, String osType, SemanticVersion version) { | ||
this.architecture = architecture; | ||
this.bitness = bitness; | ||
this.osType = osType; | ||
this.version = version; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
dd-java-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/dto/ProcInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.datadog.crashtracking.dto; | ||
|
||
public final class ProcInfo { | ||
public final String pid; | ||
|
||
public ProcInfo(String pid) { | ||
this.pid = pid; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...gent/agent-crashtracking/src/main/java/com/datadog/crashtracking/dto/SemanticVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.datadog.crashtracking.dto; | ||
|
||
import com.squareup.moshi.FromJson; | ||
import com.squareup.moshi.JsonReader; | ||
import com.squareup.moshi.JsonWriter; | ||
import com.squareup.moshi.ToJson; | ||
import java.io.IOException; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public final class SemanticVersion { | ||
public static final class SemanticVersionAdapter { | ||
|
||
@ToJson | ||
public void toJson(JsonWriter writer, SemanticVersion version) throws IOException { | ||
writer.beginObject(); | ||
writer.name("Semantic"); | ||
writer.beginArray(); | ||
writer.value(version.major); | ||
writer.value(version.minor); | ||
writer.value(version.patch); | ||
writer.endArray(); | ||
writer.endObject(); | ||
} | ||
|
||
@FromJson | ||
public SemanticVersion fromJson(JsonReader reader) throws IOException { | ||
reader.beginObject(); | ||
String name = reader.nextName(); | ||
if (!"Semantic".equals(name)) { | ||
throw new IOException("Expected 'Semantic' key"); | ||
} | ||
reader.beginArray(); | ||
int major = reader.nextInt(); | ||
int minor = reader.nextInt(); | ||
int patch = reader.nextInt(); | ||
reader.endArray(); | ||
reader.endObject(); | ||
return new SemanticVersion(major, minor, patch); | ||
} | ||
} | ||
|
||
public final int major; | ||
public final int minor; | ||
public final int patch; | ||
|
||
public SemanticVersion(int major, int minor, int patch) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = patch; | ||
} | ||
|
||
public static SemanticVersion of(String version) { | ||
String[] parts = version.split("\\."); | ||
if (parts.length == 3) { | ||
return new SemanticVersion( | ||
safeParseInteger(parts[0]), safeParseInteger(parts[1]), safeParseInteger(parts[2])); | ||
} else if (parts.length == 2) { | ||
return new SemanticVersion(safeParseInteger(parts[0]), safeParseInteger(parts[1]), 0); | ||
} else if (parts.length == 1) { | ||
return new SemanticVersion(safeParseInteger(parts[0]), 0, 0); | ||
} else { | ||
throw new IllegalArgumentException("Invalid version string: " + version); | ||
} | ||
} | ||
|
||
private static final Pattern INTEGER_PATTERN = Pattern.compile("(\\d+).*"); | ||
|
||
private static int safeParseInteger(String value) { | ||
try { | ||
return Integer.parseInt(value); | ||
} catch (NumberFormatException e) { | ||
Matcher matcher = INTEGER_PATTERN.matcher(value); | ||
if (matcher.matches()) { | ||
// this is guaranteed to be an integer | ||
return Integer.parseInt(matcher.group(1)); | ||
} | ||
return 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.