Class GrpcClientContextPropagationInterceptor
- All Implemented Interfaces:
io.grpc.ClientInterceptor, io.micronaut.core.order.Ordered
PropagatedContext of the thread that starts a client call current again in the call's
response callbacks (onHeaders, onMessage, onClose and onReady).
gRPC runs those callbacks on the channel's executor, so without this interceptor the MDC, tracing and other context
elements of the caller are lost in an async stub's StreamObserver. The interceptor does nothing when the
thread that starts the call has no propagated context.
The context is captured when the call is started (ClientCall.start(ClientCall.Listener, Metadata)), not when it is created. This
interceptor runs first: it captures the context and wraps the application's listener, which also covers calls that
another interceptor completes without reaching the transport. GrpcClientContextPropagationInterceptor.Restoring runs last, closest to the transport,
so that the listeners of every other interceptor also run inside the restored context.
The captured context is only a fallback: a callback that already runs inside a propagated context, such as one set by another interceptor, keeps it.
Enabled by default; disable with grpc.client.context-propagation.enabled=false.
- Since:
- 5.3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRestores the captured context around the response callbacks coming from the transport. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe property that enables client context propagation.Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()Runs first, so that the context is captured on the thread that starts the call.<ReqT,RespT>
io.grpc.ClientCall<ReqT, RespT> interceptCall(io.grpc.MethodDescriptor<ReqT, RespT> method, io.grpc.CallOptions callOptions, io.grpc.Channel next)
-
Field Details
-
ENABLED
-
-
Constructor Details
-
GrpcClientContextPropagationInterceptor
public GrpcClientContextPropagationInterceptor()
-
-
Method Details
-
interceptCall
public <ReqT,RespT> io.grpc.ClientCall<ReqT,RespT> interceptCall(io.grpc.MethodDescriptor<ReqT, RespT> method, io.grpc.CallOptions callOptions, io.grpc.Channel next) - Specified by:
interceptCallin interfaceio.grpc.ClientInterceptor
-
getOrder
public int getOrder()Runs first, so that the context is captured on the thread that starts the call.- Specified by:
getOrderin interfaceio.micronaut.core.order.Ordered- Returns:
- The order
-