WithForwardedRequestID forwards the incoming request ID to outgoing RPCs.
(ctx context.Context)
| 50 | |
| 51 | // WithForwardedRequestID forwards the incoming request ID to outgoing RPCs. |
| 52 | func WithForwardedRequestID(ctx context.Context) context.Context { |
| 53 | inMD, ok := metadata.FromIncomingContext(ctx) |
| 54 | if !ok { |
| 55 | return ctx |
| 56 | } |
| 57 | outMD, _ := metadata.FromOutgoingContext(ctx) |
| 58 | requestID := inMD.Get(requestIDKey) |
| 59 | if len(requestID) == 0 { |
| 60 | return ctx |
| 61 | } |
| 62 | return metadata.NewOutgoingContext(ctx, metadata.Join( |
| 63 | outMD, |
| 64 | metadata.MD{ |
| 65 | requestIDKey: requestID, |
| 66 | }, |
| 67 | )) |
| 68 | } |
no test coverage detected