GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement code origin support for grpc server entry spans by evanchooly · Pull Request #7942 · DataDog/dd-trace-java

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.

Sign up for GitHub

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
evanchooly merged 4 commits into master from evanchooly/DEBUG-3109
Nov 27, 2024

Uh oh!

There was an error while loading. Please reload this page.

Merged

Implement code origin support for grpc server entry spans #7942

Show file tree
Hide file tree
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 Nov 11, 2024
1edc7df
Update dd-java-agent/instrumentation/grpc-1.5/src/main/java/datadog/t…
evanchooly Nov 27, 2024
9f4aaa8
PR feedback updates
evanchooly Nov 27, 2024
3276467
wrap advice in a try/catch
evanchooly Nov 27, 2024
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 dd-java-agent/agent-bootstrap/build.gradle
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
api project(':internal-api')
api project(':internal-api:internal-api-9')
api project(':dd-java-agent:agent-logging')
api project(':dd-java-agent:agent-debugger:debugger-bootstrap')
api libs.slf4j
// ^ Generally a bad idea for libraries, but we're shadowing.

Expand Down
1 change: 1 addition & 0 deletions 1 dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturingTestBase.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public static LogProbe.Builder createProbeBuilder(

protected TestSnapshotListener installProbes(
Configuration configuration, ProbeDefinition... probes) {

config = mock(Config.class);
when(config.isDebuggerEnabled()).thenReturn(true);
when(config.isDebuggerClassFileDumpEnabled()).thenReturn(true);
Expand Down
2 changes: 2 additions & 0 deletions 2 dd-java-agent/instrumentation/grpc-1.5/build.gradle
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ dependencies {
testImplementation group: 'io.grpc', name: 'grpc-protobuf', version: grpcVersion
testImplementation group: 'io.grpc', name: 'grpc-stub', version: grpcVersion
testImplementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
testImplementation project(':dd-java-agent:agent-debugger')
testImplementation libs.bundles.mockito

latestDepTestImplementation sourceSets.test.output // include the protobuf generated classes
latestDepTestCompileOnly group: 'io.grpc', name: 'grpc-core', version: '1.+'
Expand Down
70 changes: 70 additions & 0 deletions 70 ...rc/main/java/datadog/trace/instrumentation/grpc/server/MethodHandlersInstrumentation.java
Show comments
View file
Open in desktop
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 =
Comment thread
evanchooly marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

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
}
}
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.