Skip to content
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.

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

Fix gRPC Context shading #297

Merged
merged 2 commits into from
Mar 31, 2020
Merged
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
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"
}