86
handler grpc.UnaryHandler,
87
) (any, error) {
88
>
// we want to return original handler response, so don't override err
grpc.go
89
>
resp, err := handler(ctx, req)
90
>
91
>
select {
92
case <-ctx.Done():
93
return resp, err
95
}
96
97
>
metricsCtx := getMetricsContext(ctx)
grpc.go
98
>
if metricsCtx == nil {
99
return resp, err
100
}
101
102
>
metricsBaggage := &metricsspb.Baggage{CountersInt: make(map[string]int64)}
grpc.go
103
>
104
>
metricsCtx.Lock()
105
>
maps.Copy(metricsBaggage.CountersInt, metricsCtx.CountersInt)
106
>
metricsCtx.Unlock()
107
>
108
>
bytes, marshalErr := metricsBaggage.Marshal()
109
>
if marshalErr != nil {
110
logger.Error("unable to marshal metric baggage", tag.Error(marshalErr))
111
}
112
113
>
md := metadata.Pairs(metricsTrailerKey, string(bytes))
grpc.go
114
>
115
>
marshalErr = grpc.SetTrailer(ctx, md)
116
>
if marshalErr != nil {
117
logger.Error("unable to add metrics baggage to gRPC trailer", tag.Error(marshalErr))
118
}
119
121
}
122
}