Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions dd-java-agent/instrumentation/grpc-1.5/build.gradle
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
plugins {
id 'com.google.protobuf' version '0.10.0'
id 'dd-trace-java.module.instrumentation'
id 'idea'
}

muzzle {
pass {
group = "io.grpc"
module = "grpc-core"
versions = "[1.5.0,)"
}
}
apply from: "$rootDir/gradle/java.gradle"

addTestSuiteForDir('latestDepTest', 'test')

// First version with Mac M1 support
def grpcVersion = '1.42.2'
protobuf {
protoc {
// Download compiler rather than using locally installed version:
// First version with Mac M1 support
artifact = 'com.google.protobuf:protoc:3.17.3'
}
plugins {
// First version with aarch support
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
}
generateProtoTasks {
ofSourceSet("test").configureEach {
plugins { grpc {} }
}

muzzle {
pass {
group = 'io.grpc'
module = 'grpc-core'
versions = '[1.5.0,)'
assertInverse = true
}
}

addTestSuiteForDir('latestDepTest', 'test')

dependencies {
compileOnly group: 'io.grpc', name: 'grpc-core', version: grpcVersion

testImplementation group: 'io.grpc', name: 'grpc-core', version: grpcVersion
testImplementation group: 'io.grpc', name: 'grpc-netty', version: grpcVersion
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:debugger-bootstrap')

latestDepTestImplementation sourceSets.test.output // include the protobuf generated classes
latestDepTestCompileOnly group: 'io.grpc', name: 'grpc-core', version: '1.+'

latestDepTestImplementation group: 'io.grpc', name: 'grpc-inprocess', version: '1.+'
latestDepTestImplementation group: 'io.grpc', name: 'grpc-core', version: '1.+'
latestDepTestImplementation group: 'io.grpc', name: 'grpc-netty', version: '1.+'
latestDepTestImplementation group: 'io.grpc', name: 'grpc-protobuf', version: '1.+'
latestDepTestImplementation group: 'io.grpc', name: 'grpc-stub', version: '1.+'
}

def protocVersion = '3.17.3'
// aarch_64 support was added in 3.17.3
def protocArch = System.getProperty("os.arch") == "aarch64" ? ":osx-x86_64" : ""
def grpcArch = System.getProperty("os.arch") == "aarch64" ? ":osx-x86_64" : ""

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protocVersion}${protocArch}"
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}${grpcArch}"
}
}
generateProtoTasks {
ofSourceSet("test").configureEach {
plugins {
grpc {}
}
}
}
}
181 changes: 0 additions & 181 deletions dd-java-agent/instrumentation/grpc-1.5/gradle.lockfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ public static final class Construct {
public static void after(@Advice.This Object command) {
ContextStore<Object, State> contextStore = InstrumentationContext.get(QUEUED_COMMAND, STATE);
capture(contextStore, command);
// FIXME hard to handle both the lifecyle and get access to the queue instance in the same
// frame within the WriteQueue class.
// This means we can't get the queue length. A (bad) alternative would be to instrument
// ConcurrentLinkedQueue broadly,
// or we could write more brittle instrumentation targeting code patterns in different gRPC
// versions.
QueueTimerHelper.startQueuingTimer(
contextStore, Channel.class, ConcurrentLinkedQueue.class, 0, command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public static void after(@Advice.Enter AgentScope scope) {
public static final class SendMessage {
@Advice.OnMethodEnter
public static AgentScope before(@Advice.This ClientCall<?, ?> call) {
// could create a message span here for the request
AgentSpan span = InstrumentationContext.get(ClientCall.class, AgentSpan.class).get(call);
if (span != null) {
return activateSpan(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void methodAdvice(MethodTransformer transformer) {
public static final class Construct {
@Advice.OnMethodExit
public static void capture(@Advice.This ClientStreamListener listener) {
// instrumentation of ClientCallImpl::start ensures this scope is present and valid
AgentSpan span = activeSpan();
if (null != span) {
InstrumentationContext.get(ClientStreamListener.class, AgentSpan.class).put(listener, span);
Expand All @@ -66,11 +65,8 @@ public static void exceptionThrown(
}

public static final class RecordActivity {

@Advice.OnMethodEnter
public static AgentScope before(@Advice.This ClientStreamListener listener) {
// activate the span so serialisation work is accounted for, whichever thread the work is done
// on
AgentSpan span =
InstrumentationContext.get(ClientStreamListener.class, AgentSpan.class).get(listener);
if (span != null) {
Expand All @@ -87,18 +83,9 @@ public static void after(@Advice.Enter AgentScope scope) {
}
}

/*
A call to 'headersAvailable' is optional - meaning that it may not appear at all but if it appears
it will be followed by a call to `messageRead`. In order to properly cooperate with the `messageRead` instrumentation
we must make sure that when this method is finished the associated span is 'migrated' - such that `messageRead`
instrumentation can correctly 'resume' the span.
*/
public static final class RecordHeaders {

@Advice.OnMethodEnter
public static AgentScope before(@Advice.This ClientStreamListener listener) {
// activate the span so serialisation work is accounted for, whichever thread the work is done
// on
AgentSpan span =
InstrumentationContext.get(ClientStreamListener.class, AgentSpan.class).get(listener);
if (span != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private static DataStreamsContext createDsmContext() {

private static final ClassValue<UTF8BytesString> MESSAGE_TYPES =
GenericClassValue.of(
// Uses inner class for predictable name for Instrumenter.Default.helperClassNames()
new Function<Class<?>, UTF8BytesString>() {
@Override
public UTF8BytesString apply(Class<?> input) {
Expand Down Expand Up @@ -93,15 +92,12 @@ protected String service() {

public <ReqT, RespT> AgentSpan startCall(MethodDescriptor<ReqT, RespT> method) {
if (IGNORED_METHODS.contains(method.getFullMethodName())) {
// if the method is ignored we want to preserve the old behaviour and not make injection
// happen
return AgentTracer.blackholeSpan();
}
AgentSpan span =
startSpan(COMPONENT_NAME.toString(), OPERATION_NAME)
.setTag("request.type", requestMessageType(method))
.setTag("response.type", responseMessageType(method))
// method.getServiceName() may not be available on some grpc versions
.setTag(
Tags.RPC_SERVICE,
RPC_SERVICE_CACHE.computeIfAbsent(
Expand All @@ -124,7 +120,6 @@ public void onClose(final AgentSpan span, final Status status) {
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
span.setTag("status.description", status.getDescription());

// TODO why is there a mismatch between client / server for calling the onError method?
onError(span, status.getCause());
span.setError(CLIENT_ERROR_STATUSES.get(status.getCode().value()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public final class GrpcInjectAdapter implements CarrierSetter<Metadata> {
public void set(final Metadata carrier, final String key, final String value) {
Metadata.Key<String> metadataKey = KEY_CACHE.computeIfAbsent(key, KEY_MAKER);
if (carrier.containsKey(metadataKey)) {
carrier.removeAll(
metadataKey); // Remove existing to ensure identical behavior with other carriers
carrier.removeAll(metadataKey);
}
carrier.put(metadataKey, value);
}
Expand Down

This file was deleted.

Loading
Loading