Skip to content

Commit 87b5366

Browse files
authored
Look in another location for grpc service methods (#8468)
if the service methods aren't found on the ImplBase, look for an AsyncService interface which *should* have the service methods.
1 parent da6a1b6 commit 87b5366

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public boolean isEnabled() {
4343
public void methodAdvice(MethodTransformer transformer) {
4444
transformer.applyAdvice(
4545
isConstructor().and(takesArguments(2)),
46-
MethodHandlersInstrumentation.class.getName() + "$BuildAdvice");
46+
"datadog.trace.instrumentation.grpc.server.MethodHandlersInstrumentation$BuildAdvice");
4747
}
4848

4949
public static class BuildAdvice {
@@ -52,9 +52,21 @@ public static class BuildAdvice {
5252
public static void onEnter(@Advice.Argument(0) Object serviceImpl) {
5353
try {
5454
Class<?> serviceClass = serviceImpl.getClass();
55-
Class<?> superclass = serviceClass.getSuperclass();
56-
if (superclass != null) {
57-
for (Method method : superclass.getDeclaredMethods()) {
55+
Class<?> superClass = serviceClass.getSuperclass();
56+
while (superClass != null && !superClass.getSimpleName().endsWith("ImplBase")) {
57+
superClass = superClass.getSuperclass();
58+
}
59+
if (superClass != null) {
60+
// bindService() would be the only method in this case and it's irrelevant
61+
if (superClass.getDeclaredMethods().length == 1) {
62+
for (Class<?> i : serviceClass.getInterfaces()) {
63+
if (i.getSimpleName().equals("AsyncService")) {
64+
superClass = i;
65+
break;
66+
}
67+
}
68+
}
69+
for (Method method : superClass.getDeclaredMethods()) {
5870
try {
5971
entry(serviceClass.getDeclaredMethod(method.getName(), method.getParameterTypes()));
6072
} catch (Throwable e) {

0 commit comments

Comments
 (0)