Skip to content

Commit 6b97492

Browse files
authored
Merge branch 'master' into jb/wallclock_filter
2 parents cba4efb + 0253f31 commit 6b97492

File tree

74 files changed

+6276
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6276
-260
lines changed

‎dd-java-agent/agent-debugger/build.gradle‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ excludedClassesCoverage += [
2525
// based on JDK WeakHashMap
2626
'com.datadog.debugger.util.WeakIdentityHashMap*',
2727
// tested through smoke tests
28-
'com.datadog.debugger.exception.FailedTestReplayExceptionDebugger'
28+
'com.datadog.debugger.exception.FailedTestReplayExceptionDebugger',
29+
// dynamically compiled test classes - exclude to prevent Jacoco instrumentation interference
30+
'com.datadog.debugger.symboltest.SymbolExtraction*'
2931
]
3032

3133
dependencies {

‎dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/CorrelationAccess.java‎

Lines changed: 0 additions & 90 deletions
This file was deleted.

‎dd-java-agent/agent-debugger/debugger-bootstrap/src/test/java/datadog/trace/bootstrap/debugger/CorrelationAccessTest.java‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/instrumentation/Types.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.objectweb.asm.Opcodes.SASTORE;
1919

2020
import datadog.trace.bootstrap.debugger.CapturedContext;
21-
import datadog.trace.bootstrap.debugger.CorrelationAccess;
2221
import datadog.trace.bootstrap.debugger.DebuggerContext;
2322
import datadog.trace.bootstrap.debugger.DebuggerSpan;
2423
import datadog.trace.bootstrap.debugger.MethodLocation;
@@ -64,7 +63,6 @@ public final class Types {
6463
public static final Type CAPTURE_THROWABLE_TYPE =
6564
Type.getType(CapturedContext.CapturedThrowable.class);
6665
public static final Type THROWABLE_TYPE = Type.getType(Throwable.class);
67-
public static final Type CORRELATION_ACCESS_TYPE = Type.getType(CorrelationAccess.class);
6866
public static final Type DEBUGGER_CONTEXT_TYPE = Type.getType(DebuggerContext.class);
6967
public static final Type METHOD_LOCATION_TYPE = Type.getType(MethodLocation.class);
7068
public static final Type CLASS_TYPE = Type.getType(Class.class);

‎dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import com.squareup.moshi.JsonReader;
2424
import com.squareup.moshi.JsonWriter;
2525
import datadog.trace.api.Config;
26+
import datadog.trace.api.CorrelationIdentifier;
2627
import datadog.trace.api.DDTraceId;
2728
import datadog.trace.bootstrap.debugger.CapturedContext;
2829
import datadog.trace.bootstrap.debugger.CapturedContextProbe;
29-
import datadog.trace.bootstrap.debugger.CorrelationAccess;
3030
import datadog.trace.bootstrap.debugger.DebuggerContext;
3131
import datadog.trace.bootstrap.debugger.EvaluationError;
3232
import datadog.trace.bootstrap.debugger.Limits;
@@ -633,8 +633,8 @@ protected boolean fillSnapshot(
633633
}
634634
boolean shouldCommit = false;
635635
if (entryStatus.shouldSend() && exitStatus.shouldSend()) {
636-
snapshot.setTraceId(CorrelationAccess.instance().getTraceId());
637-
snapshot.setSpanId(CorrelationAccess.instance().getSpanId());
636+
snapshot.setTraceId(CorrelationIdentifier.getTraceId());
637+
snapshot.setSpanId(CorrelationIdentifier.getSpanId());
638638
if (isFullSnapshot()) {
639639
snapshot.setEntry(entryContext);
640640
snapshot.setExit(exitContext);
@@ -754,8 +754,8 @@ public void commit(CapturedContext lineContext, int line) {
754754
Snapshot snapshot = createSnapshot();
755755
boolean shouldCommit = false;
756756
if (status.shouldSend()) {
757-
snapshot.setTraceId(CorrelationAccess.instance().getTraceId());
758-
snapshot.setSpanId(CorrelationAccess.instance().getSpanId());
757+
snapshot.setTraceId(CorrelationIdentifier.getTraceId());
758+
snapshot.setSpanId(CorrelationIdentifier.getSpanId());
759759
snapshot.setMessage(status.getMessage());
760760
shouldCommit = true;
761761
}

‎dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SymDBEnablement.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ private void extractSymbolForLoadedClasses(SymDBReport symDBReport) {
143143
try {
144144
jarPath = JarScanner.extractJarPath(clazz, symDBReport);
145145
} catch (URISyntaxException e) {
146-
throw new RuntimeException(e);
146+
LOGGER.debug("Failed to extract jar path for class {}", clazz.getTypeName(), e);
147+
continue;
147148
}
148149
if (jarPath == null) {
149150
continue;
@@ -152,7 +153,11 @@ private void extractSymbolForLoadedClasses(SymDBReport symDBReport) {
152153
symDBReport.addMissingJar(jarPath.toString());
153154
continue;
154155
}
155-
symbolAggregator.scanJar(symDBReport, jarPath, baos, buffer);
156+
try {
157+
symbolAggregator.scanJar(symDBReport, jarPath, baos, buffer);
158+
} catch (Exception ex) {
159+
LOGGER.debug("Failed to scan jar {}", jarPath, ex);
160+
}
156161
}
157162
}
158163
}

‎dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SymbolAggregator.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ void scanQueuedJars(SymbolAggregator symbolAggregator) {
158158
while (!jarsToScanQueue.isEmpty()) {
159159
String jarPath = jarsToScanQueue.poll();
160160
LOGGER.debug("Scanning queued jar: {}", jarPath);
161-
scanJar(SymDBReport.NO_OP, Paths.get(jarPath), baos, buffer);
161+
try {
162+
scanJar(SymDBReport.NO_OP, Paths.get(jarPath), baos, buffer);
163+
} catch (Exception ex) {
164+
LOGGER.debug("Failed to scan jar {}", jarPath, ex);
165+
}
162166
}
163167
}
164168

‎dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
import static org.junit.jupiter.api.Assertions.assertNull;
1717
import static org.junit.jupiter.api.Assertions.assertTrue;
1818
import static org.mockito.ArgumentMatchers.eq;
19-
import static org.mockito.Mockito.doReturn;
2019
import static org.mockito.Mockito.mock;
21-
import static org.mockito.Mockito.spy;
2220
import static org.mockito.Mockito.times;
2321
import static org.mockito.Mockito.verify;
2422
import static org.mockito.Mockito.when;
@@ -51,7 +49,6 @@
5149
import datadog.trace.api.interceptor.MutableSpan;
5250
import datadog.trace.bootstrap.debugger.CapturedContext;
5351
import datadog.trace.bootstrap.debugger.CapturedContextProbe;
54-
import datadog.trace.bootstrap.debugger.CorrelationAccess;
5552
import datadog.trace.bootstrap.debugger.DebuggerContext;
5653
import datadog.trace.bootstrap.debugger.EvaluationError;
5754
import datadog.trace.bootstrap.debugger.Limits;
@@ -67,8 +64,6 @@
6764
import java.io.File;
6865
import java.io.FileNotFoundException;
6966
import java.io.IOException;
70-
import java.lang.reflect.Field;
71-
import java.lang.reflect.Modifier;
7267
import java.net.URISyntaxException;
7368
import java.net.URL;
7469
import java.util.ArrayList;
@@ -1629,9 +1624,6 @@ public void staticInheritedFields() throws IOException, URISyntaxException {
16291624
@Test
16301625
public void staticLambda() throws IOException, URISyntaxException {
16311626
final String CLASS_NAME = "CapturedSnapshot07";
1632-
CorrelationAccess spyCorrelationAccess = spy(CorrelationAccess.instance());
1633-
setCorrelationSingleton(spyCorrelationAccess);
1634-
doReturn(true).when(spyCorrelationAccess).isAvailable();
16351627
int line = getLineForLineProbe(CLASS_NAME, LINE_PROBE_ID1);
16361628
TestSnapshotListener listener =
16371629
installProbes(createLineProbe(LINE_PROBE_ID1, CLASS_NAME, line));
@@ -1647,9 +1639,6 @@ public void staticLambda() throws IOException, URISyntaxException {
16471639
@Test
16481640
public void capturingLambda() throws IOException, URISyntaxException {
16491641
final String CLASS_NAME = "CapturedSnapshot07";
1650-
CorrelationAccess spyCorrelationAccess = spy(CorrelationAccess.instance());
1651-
setCorrelationSingleton(spyCorrelationAccess);
1652-
doReturn(true).when(spyCorrelationAccess).isAvailable();
16531642
int line = getLineForLineProbe(CLASS_NAME, LINE_PROBE_ID2);
16541643
TestSnapshotListener listener =
16551644
installProbes(createLineProbe(LINE_PROBE_ID2, CLASS_NAME, line));
@@ -1666,9 +1655,6 @@ public void capturingLambda() throws IOException, URISyntaxException {
16661655
@Test
16671656
public void multiLambdas() throws IOException, URISyntaxException {
16681657
final String CLASS_NAME = "CapturedSnapshot07";
1669-
CorrelationAccess spyCorrelationAccess = spy(CorrelationAccess.instance());
1670-
setCorrelationSingleton(spyCorrelationAccess);
1671-
doReturn(true).when(spyCorrelationAccess).isAvailable();
16721658
int line = getLineForLineProbe(CLASS_NAME, LINE_PROBE_ID3);
16731659
TestSnapshotListener listener =
16741660
installProbes(createLineProbe(LINE_PROBE_ID3, CLASS_NAME, line));
@@ -2845,21 +2831,6 @@ private TestSnapshotListener setupInstrumentTheWorldTransformer(
28452831
return listener;
28462832
}
28472833

2848-
// TODO: JEP 500 - avoid mutating final fields
2849-
private void setCorrelationSingleton(Object instance) {
2850-
Class<?> singletonClass = CorrelationAccess.class.getDeclaredClasses()[0];
2851-
try {
2852-
Field instanceField = singletonClass.getDeclaredField("INSTANCE");
2853-
instanceField.setAccessible(true);
2854-
Field modifiersField = Field.class.getDeclaredField("modifiers");
2855-
modifiersField.setAccessible(true);
2856-
modifiersField.setInt(instanceField, instanceField.getModifiers() & ~Modifier.FINAL);
2857-
instanceField.set(null, instance);
2858-
} catch (NoSuchFieldException | IllegalAccessException e) {
2859-
e.printStackTrace();
2860-
}
2861-
}
2862-
28632834
private Snapshot assertOneSnapshot(TestSnapshotListener listener) {
28642835
return assertOneSnapshot(PROBE_ID, listener);
28652836
}

‎dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/DebuggerTransformerTest.java‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@
2828
import datadog.trace.api.Tracer;
2929
import datadog.trace.api.config.TraceInstrumentationConfig;
3030
import datadog.trace.bootstrap.debugger.CapturedContext;
31-
import datadog.trace.bootstrap.debugger.CorrelationAccess;
3231
import datadog.trace.bootstrap.debugger.DebuggerContext;
3332
import datadog.trace.bootstrap.debugger.ProbeId;
3433
import datadog.trace.bootstrap.debugger.ProbeRateLimiter;
3534
import freemarker.template.Template;
3635
import java.io.File;
3736
import java.io.InputStreamReader;
3837
import java.lang.instrument.Instrumentation;
39-
import java.lang.reflect.Field;
4038
import java.nio.file.Path;
4139
import java.nio.file.Paths;
4240
import java.util.ArrayList;
@@ -91,10 +89,6 @@ static void setupAll() throws Exception {
9189
// disable tracer integration
9290
System.setProperty("dd." + TraceInstrumentationConfig.TRACE_ENABLED, "false");
9391

94-
Field fld = CorrelationAccess.class.getDeclaredField("REUSE_INSTANCE");
95-
fld.setAccessible(true);
96-
fld.set(null, false);
97-
9892
// setup the tracer
9993
noopTracer = GlobalTracer.get();
10094
Tracer mockTracer = mock(Tracer.class);

‎dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SymDBEnablementTest.java‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import java.io.IOException;
2626
import java.io.InputStream;
2727
import java.lang.instrument.Instrumentation;
28+
import java.net.MalformedURLException;
2829
import java.net.URISyntaxException;
2930
import java.net.URL;
3031
import java.net.URLClassLoader;
32+
import java.nio.file.Path;
3133
import java.util.Collections;
3234
import java.util.jar.JarEntry;
3335
import java.util.jar.JarFile;
@@ -111,11 +113,7 @@ public void noIncludesFilterOutDatadogClass() {
111113

112114
@Test
113115
public void parseLoadedClass() throws ClassNotFoundException, IOException {
114-
final String CLASS_NAME = "com.datadog.debugger.symbol.SymbolExtraction01";
115-
URL jarFileUrl = getClass().getResource("/debugger-symbol.jar");
116-
URL jarUrl = new URL("jar:file:" + jarFileUrl.getFile() + "!/");
117-
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {jarUrl}, null);
118-
Class<?> testClass = urlClassLoader.loadClass(CLASS_NAME);
116+
Class<?> testClass = loadSymbolClassFromJar();
119117
when(instr.getAllLoadedClasses()).thenReturn(new Class[] {testClass});
120118
when(config.getThirdPartyIncludes())
121119
.thenReturn(
@@ -130,14 +128,50 @@ public void parseLoadedClass() throws ClassNotFoundException, IOException {
130128
verify(instr).addTransformer(any(SymbolExtractionTransformer.class));
131129
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
132130
verify(symbolAggregator, times(2))
133-
.parseClass(any(), captor.capture(), any(), eq(jarFileUrl.getFile()));
131+
.parseClass(
132+
any(),
133+
captor.capture(),
134+
any(),
135+
eq(getClass().getResource("/debugger-symbol.jar").getFile()));
134136
assertEquals(
135137
"com/datadog/debugger/symbol/SymbolExtraction01.class", captor.getAllValues().get(0));
136138
assertEquals(
137139
"BOOT-INF/classes/org/springframework/samples/petclinic/vet/VetController.class",
138140
captor.getAllValues().get(1));
139141
}
140142

143+
@Test
144+
public void processCorruptedJar() throws ClassNotFoundException, MalformedURLException {
145+
Class<?> testClass = loadSymbolClassFromJar();
146+
when(instr.getAllLoadedClasses())
147+
.thenReturn(new Class[] {SymDBEnablementTest.class, testClass});
148+
ClassNameFiltering classNameFiltering = ClassNameFiltering.allowAll();
149+
SymbolAggregator symbolAggregatorMock = mock(SymbolAggregator.class);
150+
doAnswer(
151+
invocation -> {
152+
Path arg = invocation.getArgument(1, Path.class);
153+
if (arg.toString().endsWith("/debugger-symbol.jar")) {
154+
return null;
155+
}
156+
throw new IOException("Corrupted jar");
157+
})
158+
.when(symbolAggregatorMock)
159+
.scanJar(any(), any(), any(), any());
160+
SymDBEnablement symDBEnablement =
161+
new SymDBEnablement(instr, config, symbolAggregatorMock, classNameFiltering);
162+
symDBEnablement.startSymbolExtraction();
163+
verify(symbolAggregatorMock, times(2)).scanJar(any(), any(), any(), any());
164+
}
165+
166+
private Class<?> loadSymbolClassFromJar() throws MalformedURLException, ClassNotFoundException {
167+
final String CLASS_NAME = "com.datadog.debugger.symbol.SymbolExtraction01";
168+
URL jarFileUrl = getClass().getResource("/debugger-symbol.jar");
169+
URL jarUrl = new URL("jar:file:" + jarFileUrl.getFile() + "!/");
170+
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {jarUrl}, null);
171+
Class<?> testClass = urlClassLoader.loadClass(CLASS_NAME);
172+
return testClass;
173+
}
174+
141175
@Test
142176
public void parseLoadedClassFromDirectory()
143177
throws ClassNotFoundException, IOException, URISyntaxException {

0 commit comments

Comments
 (0)