Skip to content

Conversation

@YifeiZhuang
Copy link
Member

@YifeiZhuang YifeiZhuang commented Aug 30, 2024

b/357892637
following up on: #11477
This uses inprocess transport. Next we will add interop test using netty transport to test real across thread span propagation.

Context

io.opentelemetry.context forks io.grpc.context, so propagating span context becomes an issue.
In grpc, the server context is propagated from transport thread to the application thread at the JumpToApplicationThreadServerListener, using ContextRunnable. However, due to opentelemetry has its own context object/storage, the span propagation does not happen automatically with the existing grpc support. There are two ways of doing this:

  1. (this PR) use the interceptor to explicitly propagate span to the application thread. (interceptor runs in application thread, serverStreamTracer.filterContext runs in transport thread).
    Pros: simplicity, UX, API support
    Cons:context does not propagate between opentelemetry and grpc, only span context is manually propagated.
  2. Implement io.grpc.override.ContextStorageOverride, e.g. https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/grpc-1.6/library/src/main/java/io/grpc/override/ContextStorageOverride.java,
    which delegates the grpc context storage to opentelemetry context.
    Pros: propagate all
    Cons: UX is complicated. users can not it use with other custom ContextStorageOverride if we add it to grpc-opentelemetry package. Or if we release it as a separate artifact, users need to add dependency, no API support.

Client side is easier, the current span context in opentelemetry from the application will be propagated as parent span towards grpc client/attempt spans, automatically support by SpanBuilderImpl.

@YifeiZhuang
Copy link
Member Author

In the interop-test, I switched to GrpcTraceBinPropagator, but then I have to disable census in order to verify the trace-id is propagated from client application span -> grpc client span -> grpc attempt span -> grpc server span -> server application span. However, there seems no API we can disable census if we keep it in the dependency?

@YifeiZhuang YifeiZhuang requested a review from ejona86 September 10, 2024 18:40
@YifeiZhuang YifeiZhuang merged commit 5bec909 into grpc:master Sep 16, 2024
@YifeiZhuang YifeiZhuang deleted the otel-server-context-interceptor branch September 16, 2024 21:43
@YifeiZhuang YifeiZhuang changed the title Otel server context interceptor Otel server context interceptor and add experimental variable for experimental API Oct 4, 2024
kannanjgithub pushed a commit to kannanjgithub/grpc-java that referenced this pull request Oct 23, 2024
Add opentelemetry tracing API, guarded by environmental variable(disabled by default).
Use server interceptor to explicitly propagate span to the application thread.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants