grpc / grpc-java

The Java gRPC implementation. HTTP/2 based RPC
https://grpc.io/docs/languages/java/
Apache License 2.0
11.38k stars 3.83k forks source link

Migrate to new OpenCensus APIs for OpenTelemetry migration #7732

Open ejona86 opened 3 years ago

ejona86 commented 3 years ago

https://github.com/census-instrumentation/opencensus-java/pull/2059 added some new APIs to be able to use the gRPC context or the OpenTelemetry context. That change breaks gRPC (https://github.com/census-instrumentation/opencensus-java/issues/2069). Ignoring the breakage, we still want to figure out what changes we should make on our side and whether we can adopt the new API. We should also investigate what their migration looks like in the context of gRPC and its users.

Gribkoff, assigning to you for initial investigation, since this may influence your work. But I assume that before any larger changes we'd coordinate and determine who is appropriate.

eugeniyk commented 2 years ago

I can't find any example how to instrument java grpc with OpenTelemetry api Do you know is there any open version for that? like we have in opentracing-contrib/java-grpc

The only example I found is autoinstrumentation via aspects in opentelemetry-java-instrumentation, but that's works via java agent

trask commented 10 months ago

hi @eugeniyk! check out https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/grpc-1.6/library

gavin-nia commented 5 months ago

We just started migrating from opencensus to opentelemetry but grpc tracing does not work correctly.

My understanding is that the opentelemetry maintainers have provided a shim that allows libraries such as gRPC to continue to use opencensus APIs (the shim converts these to OT under the hood). This means you don't need to change the gRPC code and users of gRPC just need to add the shim as a dependency.

However, one problem is the usage of the gRPC context to store the current span etc. This is referenced in the following TODO (there may be others): https://github.com/grpc/grpc-java/blob/4c78a9746c863731b02a77d37e49631065ee6b8c/census/src/main/java/io/grpc/census/CensusTracingModule.java#L409

The issue we see is that when using the shim, the root server side span (called "Recv.something") is not correctly recognized as the parent of other spans added in user code in the server. I suppose that happens because gRPC directly stores the span in a grpc context, but OT wants to use its own context management.

Is there any chance that someone can look at this or give a little guidance on the minimal change to get things working?