Skip to content

Commit

Permalink
Fix gRPC Context shading (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Mar 31, 2020
1 parent d80af33 commit 64b9585
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions instrumentation/grpc-1.5/grpc-1.5.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ static final class TracingClientCall<ReqT, RespT>

@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)) {
Expand Down
5 changes: 3 additions & 2 deletions instrumentation/instrumentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 64b9585

Please sign in to comment.