diff --git a/instrumentation/grpc-1.5/grpc-1.5.gradle b/instrumentation/grpc-1.5/grpc-1.5.gradle index 3ea843c3f3f..bc39a669969 100644 --- a/instrumentation/grpc-1.5/grpc-1.5.gradle +++ b/instrumentation/grpc-1.5/grpc-1.5.gradle @@ -53,4 +53,11 @@ dependencies { latestDepTestCompile group: 'io.grpc', name: 'grpc-netty', version: '+' latestDepTestCompile group: 'io.grpc', name: 'grpc-protobuf', version: '+' latestDepTestCompile group: 'io.grpc', name: 'grpc-stub', version: '+' + + // this instrumentation needs to be able to be able to reference the OpenTelemetry API's gRPC Context + // that is shaded in the bootstrap class loader (for sending telemetry to the agent), + // separately from the gRPC Context that is brought by gRPC + compileOnly project(path: ':opentelemetry-api-shaded-for-instrumenting', configuration: 'shadow') + + testCompile project(path: ':opentelemetry-api-shaded-for-instrumenting', configuration: 'shadow') } diff --git a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java index 36e1d47bb3f..8cbf7da2ce0 100644 --- a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java +++ b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java @@ -86,6 +86,11 @@ static final class TracingClientCall @Override public void start(final Listener responseListener, final Metadata headers) { + // this reference to io.grpc.Context will be shaded during the build + // see instrumentation.gradle: "relocate OpenTelemetry API dependency usage" + // (luckily the grpc instrumentation doesn't need to reference unshaded grpc Context, so we + // don't need to worry about distinguishing them like in the opentelemetry-api + // instrumentation) final Context context = withSpan(span, Context.current()); OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, headers, SETTER); try (final Scope scope = currentContextWith(span)) { diff --git a/instrumentation/instrumentation.gradle b/instrumentation/instrumentation.gradle index 39512e45802..c86928a39b1 100644 --- a/instrumentation/instrumentation.gradle +++ b/instrumentation/instrumentation.gradle @@ -94,9 +94,10 @@ shadowJar { relocate "io.opentelemetry.metrics", "io.opentelemetry.auto.shaded.io.opentelemetry.metrics" relocate "io.opentelemetry.trace", "io.opentelemetry.auto.shaded.io.opentelemetry.trace" - // relocate OpenTelemetry API dependency - relocate "io.grpc", "io.opentelemetry.auto.shaded.io.grpc" + // relocate OpenTelemetry API dependency usage + relocate "io.grpc.Context", "io.opentelemetry.auto.shaded.io.grpc.Context" // this is for instrumentation on opentelemetry-api itself relocate "unshaded.io.opentelemetry", "io.opentelemetry" + relocate "unshaded.io.grpc", "io.grpc" }