Skip to content

Commit 4ffa71c

Browse files
Updates based on PR review comments.
1 parent 47eba9f commit 4ffa71c

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

components/environment/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tasks.shadowJar {
1818
* Configure test coverage.
1919
*/
2020
extra.set("minimumInstructionCoverage", 0.7)
21-
extra.set("minimumBranchCoverage", 0.7)
2221
val excludedClassesCoverage by extra {
2322
listOf(
2423
"datadog.environment.JavaVirtualMachine", // depends on OS and JVM vendor

components/environment/src/main/java/datadog/environment/EnvironmentVariables.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,4 @@ public static String getOrDefault(@Nonnull String name, String defaultValue) {
3838
return defaultValue;
3939
}
4040
}
41-
42-
/**
43-
* Gets an environment variable value, or default value if missing or can't be retrieved.
44-
*
45-
* @param name The environment variable name.
46-
* @param defaultValue The default value to return if the environment variable is missing or can't
47-
* be retrieved.
48-
* @return The environment variable value, {@code defaultValue} if missing or can't be retrieved.
49-
*/
50-
public static int getOrDefault(@Nonnull String name, int defaultValue) {
51-
try {
52-
String value = System.getenv(name);
53-
return value == null ? defaultValue : Integer.parseInt(value);
54-
} catch (SecurityException | NumberFormatException e) {
55-
return defaultValue;
56-
}
57-
}
5841
}

dd-java-agent/src/main/java/datadog/trace/bootstrap/BootstrapInitializationTelemetry.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,32 @@ public void onError(Throwable t) {
122122
List<String> causes = new ArrayList<>();
123123

124124
Throwable cause = t.getCause();
125-
if (cause != null) {
126-
while (cause != null) {
127-
causes.add("error_type:" + cause.getClass().getName());
128-
cause = cause.getCause();
129-
}
125+
while (cause != null) {
126+
causes.add("error_type:" + cause.getClass().getName());
127+
cause = cause.getCause();
130128
}
131129
causes.add("error_type:" + t.getClass().getName());
132130

133131
// Limit the number of tags to avoid overpopulating the JSON payload.
134-
int maxTags = EnvironmentVariables.getOrDefault("DD_TELEMETRY_FORWARDER_MAX_TAGS", 5);
135-
int sz = causes.size();
136-
int cnt = Math.min(maxTags, sz);
132+
int maxTags = maxTags(5);
133+
int numCauses = causes.size();
134+
if (numCauses > maxTags) {
135+
causes = causes.subList(numCauses - maxTags, numCauses);
136+
}
137+
138+
onPoint("library_entrypoint.error", causes);
139+
}
137140

138-
onPoint("library_entrypoint.error", causes.subList(sz - cnt, sz));
141+
private int maxTags(int defaultValue) {
142+
try {
143+
String s =
144+
EnvironmentVariables.getOrDefault(
145+
"DD_TELEMETRY_FORWARDER_MAX_TAGS", String.valueOf(defaultValue));
146+
147+
return Integer.parseInt(s);
148+
} catch (Exception e) {
149+
return defaultValue;
150+
}
139151
}
140152

141153
@Override

0 commit comments

Comments
 (0)