mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-24 03:59:49 +02:00
core/telemetry: move requestid to pkg directory (#4911)
This commit is contained in:
parent
803baeb9e1
commit
4301da3648
18 changed files with 13 additions and 13 deletions
40
pkg/telemetry/requestid/grpc_client.go
Normal file
40
pkg/telemetry/requestid/grpc_client.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package requestid
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
// StreamClientInterceptor returns a new gRPC StreamClientInterceptor which puts the request ID in the outgoing
|
||||
// metadata.
|
||||
func StreamClientInterceptor() grpc.StreamClientInterceptor {
|
||||
return func(ctx context.Context,
|
||||
desc *grpc.StreamDesc, cc *grpc.ClientConn,
|
||||
method string, streamer grpc.Streamer, opts ...grpc.CallOption,
|
||||
) (grpc.ClientStream, error) {
|
||||
ctx = toMetadata(ctx)
|
||||
return streamer(ctx, desc, cc, method, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// UnaryClientInterceptor returns a new gRPC UnaryClientInterceptor which puts the request ID in the outgoing
|
||||
// metadata.
|
||||
func UnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
||||
return func(ctx context.Context,
|
||||
method string, req, reply interface{},
|
||||
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption,
|
||||
) error {
|
||||
ctx = toMetadata(ctx)
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func toMetadata(ctx context.Context) context.Context {
|
||||
requestID := FromContext(ctx)
|
||||
if requestID == "" {
|
||||
requestID = New()
|
||||
}
|
||||
return metadata.AppendToOutgoingContext(ctx, headerName, requestID)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue