Skip to content

Commit 9718fe6

Browse files
authored
Merge branch 'master' into andrea.marziali/mulesoft
2 parents e18d572 + 7698f2f commit 9718fe6

File tree

9 files changed

+161
-124
lines changed

9 files changed

+161
-124
lines changed

.circleci/collect_results.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ do
2828
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
2929
# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
3030
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
31+
# Replace random port numbers by marker in testcase XML nodes to get stable test names
32+
sed -i '/<testcase/ s/localhost:[0-9]\{2,5\}/localhost:PORT/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
3133
if cmp -s "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"; then
3234
echo ""
3335
else
34-
echo " (hashCode replaced)"
36+
echo -n " (non-stable test names detected)"
3537
fi
3638
done < <(find "${TEST_RESULT_DIRS[@]}" -name \*.xml -print0)

dd-java-agent/agent-crashtracking/src/main/java/com/datadog/crashtracking/OOMENotifierScriptInitializer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ static void run(Path dir) {
124124
Files.walkFileTree(dir, new ScriptCleanupVisitor());
125125
}
126126
} catch (IOException e) {
127-
LOG.warn("Failed cleaning up process specific files in {}", dir, e);
127+
if (LOG.isDebugEnabled()) {
128+
LOG.info("Failed cleaning up process specific files in {}", dir, e);
129+
} else {
130+
LOG.info("Failed cleaning up process specific files in {}: {}", dir, e.toString());
131+
}
128132
}
129133
}
130134

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public enum Status {
1818

1919
private final Status status;
2020
private final Map<ProbeId, List<DiagnosticMessage>> diagnostics;
21-
private String typeName;
22-
private String methodName;
21+
private final String sourceFileName;
22+
private final String typeName;
23+
private final String methodName;
24+
private final int methodStart;
2325

2426
public static class Factory {
2527
public static InstrumentationResult blocked(String className) {
@@ -41,8 +43,10 @@ public InstrumentationResult(
4143
this(
4244
status,
4345
diagnostics,
46+
methodInfo.getClassNode().sourceFile,
4447
methodInfo.getClassNode().name.replace('/', '.'),
45-
methodInfo.getMethodNode().name);
48+
methodInfo.getMethodNode().name,
49+
methodInfo.getMethodStart());
4650
}
4751

4852
public InstrumentationResult(
@@ -54,6 +58,23 @@ public InstrumentationResult(
5458
this.diagnostics = diagnostics;
5559
this.typeName = className;
5660
this.methodName = methodName;
61+
this.methodStart = -1;
62+
this.sourceFileName = null;
63+
}
64+
65+
public InstrumentationResult(
66+
Status status,
67+
Map<ProbeId, List<DiagnosticMessage>> diagnostics,
68+
String sourceFileName,
69+
String className,
70+
String methodName,
71+
int methodStart) {
72+
this.status = status;
73+
this.diagnostics = diagnostics;
74+
this.sourceFileName = sourceFileName;
75+
this.typeName = className;
76+
this.methodName = methodName;
77+
this.methodStart = methodStart;
5778
}
5879

5980
public boolean isError() {
@@ -80,6 +101,14 @@ public String getMethodName() {
80101
return methodName;
81102
}
82103

104+
public int getMethodStart() {
105+
return methodStart;
106+
}
107+
108+
public String getSourceFileName() {
109+
return sourceFileName;
110+
}
111+
83112
@Generated
84113
@Override
85114
public String toString() {

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

+4
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public MethodNode getMethodNode() {
3737
public ClassFileLines getClassFileLines() {
3838
return classFileLines;
3939
}
40+
41+
public int getMethodStart() {
42+
return classFileLines != null ? classFileLines.getMethodStart(methodNode) : -1;
43+
}
4044
}

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

+38-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static datadog.trace.api.DDTags.DD_CODE_ORIGIN_TYPE;
66
import static java.lang.String.format;
77
import static java.util.Arrays.asList;
8+
import static java.util.Collections.emptyList;
89
import static java.util.Collections.singletonList;
910

1011
import com.datadog.debugger.agent.DebuggerAgent;
@@ -31,6 +32,8 @@ public class CodeOriginProbe extends LogProbe implements ForceMethodInstrumentat
3132

3233
private final boolean entrySpanProbe;
3334

35+
private List<StackTraceElement> stackTraceElements;
36+
3437
public CodeOriginProbe(ProbeId probeId, boolean entry, Where where, int maxFrames) {
3538
super(LANGUAGE, probeId, null, where, MethodLocation.EXIT, null, null, true, null, null, null);
3639
this.entrySpanProbe = entry;
@@ -82,8 +85,25 @@ public void commit(
8285
span.getLocalRootSpan().setTag(getId(), (String) null); // clear possible span reference
8386
}
8487

88+
private List<StackTraceElement> findLocation() {
89+
if (entrySpanProbe && stackTraceElements == null) {
90+
ProbeLocation probeLocation = getLocation();
91+
List<String> lines = probeLocation.getLines();
92+
int line = lines == null ? -1 : Integer.parseInt(lines.get(0));
93+
stackTraceElements =
94+
singletonList(
95+
new StackTraceElement(
96+
probeLocation.getType(),
97+
probeLocation.getMethod(),
98+
probeLocation.getFile(),
99+
line));
100+
}
101+
return stackTraceElements != null ? stackTraceElements : emptyList();
102+
}
103+
85104
private void applySpanOriginTags(AgentSpan span, String snapshotId) {
86-
List<StackTraceElement> entries = getUserStackFrames();
105+
List<StackTraceElement> entries =
106+
stackTraceElements != null ? stackTraceElements : getUserStackFrames();
87107
List<AgentSpan> agentSpans =
88108
entrySpanProbe ? asList(span, span.getLocalRootSpan()) : singletonList(span);
89109

@@ -92,7 +112,8 @@ private void applySpanOriginTags(AgentSpan span, String snapshotId) {
92112

93113
for (int i = 0; i < entries.size(); i++) {
94114
StackTraceElement info = entries.get(i);
95-
s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "file"), info.getFileName());
115+
String fileName = info.getFileName();
116+
s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "file"), fileName);
96117
s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "method"), info.getMethodName());
97118
s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "line"), info.getLineNumber());
98119
s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "type"), info.getClassName());
@@ -127,12 +148,25 @@ private AgentSpan findSpan(AgentSpan candidate) {
127148
public void buildLocation(InstrumentationResult result) {
128149
String type = where.getTypeName();
129150
String method = where.getMethodName();
151+
List<String> lines = null;
152+
153+
String file = where.getSourceFile();
154+
130155
if (result != null) {
131156
type = result.getTypeName();
132157
method = result.getMethodName();
158+
if (result.getMethodStart() != -1) {
159+
lines = singletonList(String.valueOf(result.getMethodStart()));
160+
}
161+
if (file == null) {
162+
file = result.getSourceFileName();
163+
}
164+
if (entrySpanProbe) {
165+
stackTraceElements =
166+
singletonList(new StackTraceElement(type, method, file, result.getMethodStart()));
167+
}
133168
}
134-
// drop line number for code origin probe
135-
this.location = new ProbeLocation(type, method, where.getSourceFile(), null);
169+
this.location = new ProbeLocation(type, method, file, lines);
136170
}
137171

138172
private List<StackTraceElement> getUserStackFrames() {

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/util/ClassFileLines.java

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
public class ClassFileLines {
1515
private final Map<Integer, List<MethodNode>> methodByLine = new HashMap<>();
16+
private final Map<String, Integer> methodStarts = new HashMap<>();
1617
private final TreeMap<Integer, LabelNode> lineLabels = new TreeMap<>();
1718

1819
public ClassFileLines(ClassNode classNode) {
@@ -21,6 +22,7 @@ public ClassFileLines(ClassNode classNode) {
2122
while (currentNode != null) {
2223
if (currentNode.getType() == AbstractInsnNode.LINE) {
2324
LineNumberNode lineNode = (LineNumberNode) currentNode;
25+
methodStarts.putIfAbsent(methodNode.name + methodNode.desc, lineNode.line);
2426
// on the same line, we can have multiple methods (lambdas, inner classes, etc)
2527
List<MethodNode> methodNodes =
2628
methodByLine.computeIfAbsent(lineNode.line, k -> new ArrayList<>());
@@ -40,6 +42,10 @@ public ClassFileLines(ClassNode classNode) {
4042
}
4143
}
4244

45+
public int getMethodStart(MethodNode node) {
46+
return methodStarts.getOrDefault(node.name + node.desc, -1);
47+
}
48+
4349
public List<MethodNode> getMethodsByLine(int line) {
4450
return methodByLine.get(line);
4551
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/origin/CodeOriginTest.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static java.util.Arrays.asList;
99
import static org.junit.jupiter.api.Assertions.assertEquals;
1010
import static org.junit.jupiter.api.Assertions.assertFalse;
11+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1112
import static org.junit.jupiter.api.Assertions.assertNotNull;
1213
import static org.junit.jupiter.api.Assertions.assertNull;
1314
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -234,6 +235,7 @@ private static void checkEntrySpanTags(MutableSpan span, boolean includeSnapshot
234235
assertKeyPresent(span, DD_CODE_ORIGIN_TYPE);
235236
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "file"));
236237
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "line"));
238+
assertNotEquals(-1, span.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "line")));
237239
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "method"));
238240
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "signature"));
239241
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "type"));
@@ -263,6 +265,7 @@ private static void checkExitSpanTags(MutableSpan span, boolean includeSnapshot)
263265
assertKeyPresent(span, DD_CODE_ORIGIN_TYPE);
264266
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "file"));
265267
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "line"));
268+
assertNotEquals(-1, span.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "line")));
266269
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "method"));
267270
assertKeyPresent(span, format(DD_CODE_ORIGIN_FRAME, 0, "type"));
268271
if (includeSnapshot) {
@@ -271,10 +274,12 @@ private static void checkExitSpanTags(MutableSpan span, boolean includeSnapshot)
271274

272275
MutableSpan rootSpan = span.getLocalRootSpan();
273276
assertEquals(rootSpan.getTag(DD_CODE_ORIGIN_TYPE), "entry", keys);
274-
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 1, "file")));
275-
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 1, "line")));
276-
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 1, "method")));
277-
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 1, "type")));
277+
Object file = rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "file"));
278+
assertNotNull(file, rootSpan.getTags().toString());
279+
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "line")));
280+
assertNotEquals(-1, rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "line")));
281+
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "method")));
282+
assertNotNull(rootSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "type")));
278283
}
279284

280285
private static Set<String> ldKeys(MutableSpan span) {

dd-java-agent/instrumentation/grpc-1.5/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
testImplementation group: 'io.grpc', name: 'grpc-protobuf', version: grpcVersion
4040
testImplementation group: 'io.grpc', name: 'grpc-stub', version: grpcVersion
4141
testImplementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
42-
testImplementation project(':dd-java-agent:agent-debugger')
42+
testImplementation project(':dd-java-agent:agent-debugger:debugger-bootstrap')
4343
testImplementation libs.bundles.mockito
4444

4545
latestDepTestImplementation sourceSets.test.output // include the protobuf generated classes

0 commit comments

Comments
 (0)