-
Notifications
You must be signed in to change notification settings - Fork 303
Implement code origin support for grpc server entry spans #7942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7c2e3a1
Add code origin support to the grpc server integration
evanchooly 1edc7df
Update dd-java-agent/instrumentation/grpc-1.5/src/main/java/datadog/t…
evanchooly 9f4aaa8
PR feedback updates
evanchooly 3276467
wrap advice in a try/catch
evanchooly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...rc/main/java/datadog/trace/instrumentation/grpc/server/MethodHandlersInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package datadog.trace.instrumentation.grpc.server; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.nameEndsWith; | ||
import static datadog.trace.bootstrap.debugger.spanorigin.CodeOriginInfo.entry; | ||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter.ForTypeHierarchy; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import datadog.trace.api.Platform; | ||
import java.lang.reflect.Method; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
@AutoService(InstrumenterModule.class) | ||
public class MethodHandlersInstrumentation extends InstrumenterModule.Tracing | ||
implements ForTypeHierarchy { | ||
private static final ElementMatcher<TypeDescription> METHOD_HANDLERS = | ||
nameEndsWith("$MethodHandlers"); | ||
|
||
public MethodHandlersInstrumentation() { | ||
super("grpc", "grpc-server", "grpc-server-code-origin"); | ||
} | ||
|
||
@Override | ||
public String hierarchyMarkerType() { | ||
return "io.grpc.MethodDescriptor"; | ||
} | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> hierarchyMatcher() { | ||
return METHOD_HANDLERS; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return super.isEnabled() && !Platform.isGraalVM(); | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
transformer.applyAdvice( | ||
isConstructor().and(takesArguments(2)), | ||
MethodHandlersInstrumentation.class.getName() + "$BuildAdvice"); | ||
} | ||
|
||
public static class BuildAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter(@Advice.Argument(0) Object serviceImpl) { | ||
try { | ||
Class<?> serviceClass = serviceImpl.getClass(); | ||
Class<?> superclass = serviceClass.getSuperclass(); | ||
if (superclass != null) { | ||
for (Method method : superclass.getDeclaredMethods()) { | ||
try { | ||
entry(serviceClass.getDeclaredMethod(method.getName(), method.getParameterTypes())); | ||
} catch (Throwable e) { | ||
// service method not overridden on the impl. skipping instrumentation. | ||
} | ||
} | ||
} | ||
} catch (Throwable e) { | ||
// this should be logged somehow | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.