Skip to content

Commit df61802

Browse files
README.md update
Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com>
1 parent b1f6bd2 commit df61802

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

modules/transport-grpc/spi/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,17 @@ The k-NN query's `filter` field is a `QueryContainer` protobuf type that can con
334334

335335
### Overview
336336

337-
Intercept incoming gRPC requests for authentication, authorization, logging, metrics, rate limiting,etc
337+
Intercept incoming gRPC requests for authentication, authorization, logging, metrics, rate limiting, etc. Interceptors have access to OpenSearch's `ThreadContext` to store and retrieve request-scoped data.
338+
339+
**Context Preservation:** The transport-grpc module automatically preserves ThreadContext across async boundaries. Any data set by interceptors will be available in the gRPC service implementation, even when execution switches to different threads.
338340

339341
### Basic Usage
340342

341343
**1. Implement Provider:**
342344
```java
343345
public class SampleInterceptorProvider implements GrpcInterceptorProvider {
344346
@Override
345-
public List<GrpcInterceptorProvider.OrderedGrpcInterceptor> getOrderedGrpcInterceptors() {
347+
public List<GrpcInterceptorProvider.OrderedGrpcInterceptor> getOrderedGrpcInterceptors(ThreadContext threadContext) {
346348
return Arrays.asList(
347349
// First interceptor (order = 5, runs first)
348350
new GrpcInterceptorProvider.OrderedGrpcInterceptor() {
@@ -353,6 +355,7 @@ public class SampleInterceptorProvider implements GrpcInterceptorProvider {
353355
public ServerInterceptor getInterceptor() {
354356
return (call, headers, next) -> {
355357
String methodName = call.getMethodDescriptor().getFullMethodName();
358+
threadContext.putTransient("grpc.method", methodName);
356359
System.out.println("First interceptor - Method: " + methodName);
357360
return next.startCall(call, headers);
358361
};

0 commit comments

Comments
 (0)