Fix gRPC Context shading
MODIFY
instrumentation/grpc-1.5/grpc-1.5.gradle
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')
}

MODIFY
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java
instrumentation/grpc-1.5/src/main/java/io/opentelemetry/auto/instrumentation/grpc/client/TracingClientInterceptor.java
@@ -86,6 +86,11 @@ public class TracingClientInterceptor implements ClientInterceptor {
@Override
public void start(final Listener<RespT> 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)) {

MODIFY
instrumentation/instrumentation.gradle
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"
}

Fix gRPC Context shading (#297)