Skip to content

Commit 2802717

Browse files
committed
entry span support for grpc servers working
1 parent c96bc45 commit 2802717

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static Where of(String typeName, String methodName, String signature, Str
4747
}
4848

4949
protected static SourceLine[] sourceLines(String[] defs) {
50-
if (defs == null) {
50+
if (defs == null || defs.length == 0) {
5151
return null;
5252
}
5353
SourceLine[] lines = new SourceLine[defs.length];
@@ -72,7 +72,7 @@ public static Where convertLineToMethod(Where lineWhere, ClassFileLines classFil
7272
null);
7373
}
7474
}
75-
throw new IllegalArgumentException("Invalid where to convert from line to method " + lineWhere);
75+
return lineWhere;
7676
}
7777

7878
public String getTypeName() {

dd-java-agent/instrumentation/grpc-1.5/src/main/java/datadog/trace/instrumentation/grpc/server/MethodHandlersInstrumentation.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import datadog.trace.agent.tooling.InstrumenterModule;
1010
import datadog.trace.bootstrap.debugger.spanorigin.CodeOriginInfo;
1111
import java.lang.reflect.Method;
12-
import java.util.Arrays;
1312
import net.bytebuddy.asm.Advice;
1413
import net.bytebuddy.description.type.TypeDescription;
1514
import net.bytebuddy.matcher.ElementMatcher;
@@ -22,7 +21,6 @@ public class MethodHandlersInstrumentation extends InstrumenterModule.Tracing
2221

2322
public MethodHandlersInstrumentation() {
2423
super("grpc-server-code-origin");
25-
System.out.println("MethodHandlersInstrumentation.MethodHandlersInstrumentation");
2624
}
2725

2826
@Override
@@ -45,16 +43,21 @@ public void methodAdvice(MethodTransformer transformer) {
4543
public static class BuildAdvice {
4644

4745
@Advice.OnMethodEnter(suppress = Throwable.class)
48-
public static void onEnter(
49-
/*@Advice.This Object handler,*/ @Advice.Argument(0) Object serviceImpl) {
46+
public static void onEnter(@Advice.Argument(0) Object serviceImpl) {
5047
Class<?> serviceClass = serviceImpl.getClass();
51-
System.out.println(
52-
"****** BuildAdvice.onEnter serviceImpl = "
53-
+ Arrays.toString(serviceClass.getInterfaces()));
5448
Method[] methods = serviceClass.getSuperclass().getDeclaredMethods();
55-
System.out.println("****** BuildAdvice.onEnter methods = " + Arrays.toString(methods));
5649
for (Method method : methods) {
57-
CodeOriginInfo.entry("testing", serviceClass, method.getName(), method.getParameterTypes());
50+
try {
51+
Method declaredMethod =
52+
serviceClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
53+
CodeOriginInfo.entry(
54+
"testing",
55+
serviceClass,
56+
declaredMethod.getName(),
57+
declaredMethod.getParameterTypes());
58+
} catch (NoSuchMethodException e) {
59+
// service method not override on the impl. skipping instrumentation
60+
}
5861
}
5962
}
6063
}

dd-java-agent/instrumentation/grpc-1.5/src/test/groovy/GrpcStreamingTest.groovy

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ abstract class GrpcStreamingTest extends VersionedNamingTestBase {
215215
"$Tags.COMPONENT" "grpc-server"
216216
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
217217
"status.code" "OK"
218-
defaultTags(true)
218+
codeOriginTags(true)
219219
}
220220
}
221221
clientRange.each {
@@ -271,21 +271,15 @@ abstract class GrpcStreamingTest extends VersionedNamingTestBase {
271271
when(config.getFinalDebuggerSnapshotUrl())
272272
.thenReturn("http://localhost:8126/debugger/v1/input")
273273
when(config.getFinalDebuggerSymDBUrl()).thenReturn("http://localhost:8126/symdb/v1/input")
274+
when(config.getDebuggerCodeOriginMaxUserFrames()).thenReturn(8)
275+
274276
def probeStatusSink = mock(ProbeStatusSink.class)
275277
def instr = ByteBuddyAgent.install()
276278

277-
278279
def sink = new DebuggerSink(config, probeStatusSink)
279-
def configurationUpdater =
280-
new ConfigurationUpdater(
281-
instr,
282-
DebuggerTransformer::new,
283-
config,
284-
sink,
285-
new ClassesToRetransformFinder())
286-
287-
def currentTransformer =
288-
new DebuggerTransformer(config, configuration, {
280+
def configurationUpdater = new ConfigurationUpdater(instr, DebuggerTransformer::new, config, sink, new ClassesToRetransformFinder())
281+
282+
def currentTransformer = new DebuggerTransformer(config, configuration, {
289283
ProbeDefinition definition, InstrumentationResult result ->
290284
}, sink)
291285
instr.addTransformer(currentTransformer)

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/asserts/TagsAssert.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ class TagsAssert {
4949
defaultTags(distributedRootSpan, false)
5050
}
5151

52+
def codeOriginTags(boolean distributedRootSpan = false, boolean checkPeerService = true) {
53+
defaultTags(distributedRootSpan, checkPeerService)
54+
assertedTags.add(DDTags.DD_CODE_ORIGIN_TYPE)
55+
for (i in 0..<8) {
56+
for (tag in ["file", "line", "method", "signature", "snapshot_id", "type"]) {
57+
assertedTags.add(String.format(DDTags.DD_CODE_ORIGIN_FRAME, i, tag))
58+
}
59+
}
60+
}
61+
5262
/**
5363
* @param distributedRootSpan set to true if current span has a parent span but still considered 'root' for current service
5464
*/

0 commit comments

Comments
 (0)