32
// NewServerMetricsContextInjectorInterceptor returns grpc server interceptor that adds metrics context to golang
33
// context.
35
>
return func(
36
>
ctx context.Context,
37
>
req any,
38
>
info *grpc.UnaryServerInfo,
39
>
handler grpc.UnaryHandler,
40
>
) (any, error) {
41
>
ctxWithMetricsBaggage := AddMetricsContext(ctx)
42
>
return handler(ctxWithMetricsBaggage, req)
43
>
}
44
}
45
46
// NewClientMetricsTrailerPropagatorInterceptor returns grpc client interceptor that injects metrics received in trailer
47
// into metrics context.
48
>
func NewClientMetricsTrailerPropagatorInterceptor(logger log.Logger) grpc.UnaryClientInterceptor {
grpc.go
49
>
return func(
50
>
ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker,
51
>
opts ...grpc.CallOption,
52
>
) error {
54
>
optsWithTrailer := append(opts, grpc.Trailer(&trailer))
55
>
err := invoker(ctx, method, req, reply, cc, optsWithTrailer...)
56
>
57
>
baggageStrings := trailer.Get(metricsTrailerKey)
58
>
if len(baggageStrings) == 0 {
60
>
}
61
62
for _, baggageString := range baggageStrings {