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

gRPC library server-side spans created via the opencensus shim not set as parents of spans created in user code #6416

Open
gavin-nia opened this issue Apr 30, 2024 · 2 comments
Labels
Bug Something isn't working

Comments

@gavin-nia
Copy link

gavin-nia commented Apr 30, 2024

Describe the bug
The gRPC libraries call opencensus APIs to add spans for incoming server requests (these spans have a remote parent). These have a name like "Recv.MyService.MyMethod'.

We wish to add further child spans in our user code (e.g. our implementation of MyService.MyMethod).

The problem we see is that our child spans are created as brand new traces.

Steps to reproduce
Reproduction requires a working gRPC server (it can just be a hello world) with opencensus instrumentation enabled.

To reproduce the problem:

  1. Add the opencensus-shim as a dependency
  2. Start & activate a span in the implementation of any gRPC service method.

What did you expect to see?

The spans created in the user code should be children of the spans created by the gRPC server interceptors.

What did you see instead?

The spans were treated as root spans and a new trace was started.

What version and what artifacts are you using?

    implementation platform("io.opentelemetry:opentelemetry-bom:1.37.0")
    implementation platform("io.grpc:grpc-bom:1.55.3")

    implementation "io.grpc:grpc-census"
    implementation "io.grpc:grpc-protobuf"
    implementation "io.grpc:grpc-stub"

    implementation "io.opencensus:opencensus-impl:0.31.1"

    implementation "io.opentelemetry:opentelemetry-api"
    implementation "io.opentelemetry:opentelemetry-sdk"
    implementation "io.opentelemetry:opentelemetry-exporter-logging"
    implementation "io.opentelemetry:opentelemetry-exporter-otlp"
    implementation "io.opentelemetry:opentelemetry-opencensus-shim:1.37.0-alpha"

    compileOnly "javax.annotation:javax.annotation-api:1.3.2"

    runtimeOnly "io.grpc:grpc-netty-shaded"

(from build.gradle)

Environment

Java 21 (temurin)

Additional context
Please see also: grpc/grpc-java#7732 and #5475

It does seem that the bug is really in the gRPC library since it bypasses the context management API when it activates the spans. Perhaps there is something we can do to make the fix easier for them (I think gRPC's context is passed around a lot so switching that to another type may be quite painful).

The client side does NOT have the same issue, but it seems like this may be good luck rather than intention. On the client side we create a span using otel API then call into the grpc client library. These spans created by the client library are correctly added as children but this happens despite the fact that gRPC itself thinks there is no parent (it calls the span builder with a blank parent span). It ends up with the correct output because the shim then finds the original parent via the opentelemetry context.

@breedx-splk
Copy link
Contributor

@gavin-nia given that #6415 has merged, any chance you can try a snapshot build to see if that helps? 🙏🏻

@gavin-nia
Copy link
Author

I didn't try with the snapshot, but I did make a test build containing #6415.

Unfortunately #6415 does not help to resolve the problem described in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants