Skip to content

Commit c126dd8

Browse files
committed
PR clean ups
1 parent 2dc8e9b commit c126dd8

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/spanorigin/SpanOriginInfo.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
public class SpanOriginInfo {
1212
public static void entry(AgentSpan span, Method method) {
13-
if (InstrumenterConfig.get().isSpanOriginEnabled()
14-
// i hate this too but need it for testing
15-
|| "true".equals(System.getProperty("dd.trace.span.origin.enabled"))) {
13+
if (InstrumenterConfig.get().isSpanOriginEnabled()) {
1614
String signature =
1715
stream(method.getParameterTypes())
1816
.map(Class::getName)
@@ -22,9 +20,7 @@ public static void entry(AgentSpan span, Method method) {
2220
}
2321

2422
public static void exit(AgentSpan span) {
25-
if (InstrumenterConfig.get().isSpanOriginEnabled()
26-
// i hate this too but need it for testing
27-
|| "true".equals(System.getProperty("dd.trace.span.origin.enabled"))) {
23+
if (InstrumenterConfig.get().isSpanOriginEnabled()) {
2824
span.getLocalRootSpan().setMetaStruct(captureSnapshot(null), span);
2925
}
3026
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/Fingerprinter.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@
44

55
import com.datadog.debugger.util.ClassNameFiltering;
66
import java.security.MessageDigest;
7-
import java.security.NoSuchAlgorithmException;
87
import org.slf4j.Logger;
98
import org.slf4j.LoggerFactory;
109

1110
/** Computes a fingerprint of an exception based on its stacktrace and exception type. */
1211
public class Fingerprinter {
1312
private static final Logger LOGGER = LoggerFactory.getLogger(Fingerprinter.class);
13+
private static MessageDigest digest;
14+
15+
static {
16+
try {
17+
digest = MessageDigest.getInstance("SHA-256");
18+
} catch (Throwable e) {
19+
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
20+
}
21+
}
1422

1523
// compute fingerprint of the Throwable based on the stacktrace and exception type
1624
public static String fingerprint(Throwable t, ClassNameFiltering classNameFiltering) {
25+
if (digest == null) {
26+
return null;
27+
}
1728
t = getInnerMostThrowable(t);
1829
if (t == null) {
1930
LOGGER.debug("Unable to find root cause of exception");
2031
return null;
2132
}
2233
Class<? extends Throwable> clazz = t.getClass();
23-
MessageDigest digest;
24-
try {
25-
// TODO avoid lookup a new instance every time
26-
digest = MessageDigest.getInstance("SHA-256");
27-
} catch (NoSuchAlgorithmException e) {
28-
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
29-
return null;
30-
}
3134
String typeName = clazz.getTypeName();
3235
digest.update(typeName.getBytes());
3336
StackTraceElement[] stackTrace = t.getStackTrace();
@@ -38,19 +41,15 @@ public static String fingerprint(Throwable t, ClassNameFiltering classNameFilter
3841
}
3942
digest.update(stackTraceElement.toString().getBytes());
4043
}
41-
byte[] bytes = digest.digest();
42-
return bytesToHex(bytes);
44+
return bytesToHex(digest.digest());
4345
}
4446

4547
public static String fingerprint(StackTraceElement element) {
46-
try {
47-
MessageDigest digest = MessageDigest.getInstance("SHA-256");
48-
digest.update(element.toString().getBytes());
49-
return bytesToHex(digest.digest());
50-
} catch (NoSuchAlgorithmException e) {
51-
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
48+
if (digest == null) {
5249
return null;
5350
}
51+
digest.update(element.toString().getBytes());
52+
return bytesToHex(digest.digest());
5453
}
5554

5655
// convert byte[] to hex string

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/code_origin/SpanDebuggerTest.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.TracerAPI;
2929
import datadog.trace.bootstrap.instrumentation.api.ScopeSource;
3030
import datadog.trace.core.CoreTracer;
31+
import datadog.trace.test.util.DDSpecification;
3132
import datadog.trace.util.AgentTaskScheduler;
3233
import java.util.Arrays;
3334
import java.util.HashSet;
34-
import org.junit.jupiter.api.AfterAll;
35-
import org.junit.jupiter.api.BeforeAll;
3635
import org.junit.jupiter.api.BeforeEach;
3736
import org.junit.jupiter.api.Test;
3837

39-
public class SpanDebuggerTest {
38+
public class SpanDebuggerTest extends DDSpecification {
4039
private ClassNameFiltering classNameFiltering;
4140

4241
private ConfigurationUpdater configurationUpdater;
@@ -48,18 +47,9 @@ public class SpanDebuggerTest {
4847
private DefaultSpanDebugger spanDebugger;
4948
private TracerAPI tracerAPI;
5049

51-
@BeforeAll
52-
public static void enableCodeOrigin() {
53-
System.setProperty("dd.trace.span.origin.enabled", "true");
54-
}
55-
56-
@AfterAll
57-
public static void disableCodeOrigin() {
58-
System.setProperty("dd.trace.span.origin.enabled", "false");
59-
}
60-
6150
@BeforeEach
6251
public void setUp() {
52+
injectSysConfig("dd.trace.span.origin.enabled", "true");
6353
AgentTracer.registerIfAbsent(CoreTracer.builder().build());
6454
tracerAPI = AgentTracer.get();
6555
configurationUpdater = mock(ConfigurationUpdater.class);

dd-trace-core/src/main/java/datadog/trace/core/propagation/ptags/PTagsFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public PTags(
138138
int samplingPriority,
139139
CharSequence origin,
140140
CharSequence lastParentId) {
141-
assert tagPairs == null || tagPairs.size() % DEBUG_PROPAGATION_DEFAULT == 0;
141+
assert tagPairs == null || tagPairs.size() % 2 == 0;
142142
this.factory = factory;
143143
this.tagPairs = tagPairs;
144144
this.canChangeDecisionMaker = decisionMakerTagValue == null;

0 commit comments

Comments
 (0)