(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler)
| 91 | } |
| 92 | |
| 93 | func (h *serverMetricsHandler) unaryInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { |
| 94 | var metadataExchangeLabels metadata.MD |
| 95 | if h.options.MetricsOptions.pluginOption != nil { |
| 96 | metadataExchangeLabels = h.options.MetricsOptions.pluginOption.GetMetadata() |
| 97 | } |
| 98 | |
| 99 | sts := grpc.ServerTransportStreamFromContext(ctx) |
| 100 | |
| 101 | alts := &attachLabelsTransportStream{ |
| 102 | ServerTransportStream: sts, |
| 103 | metadataExchangeLabels: metadataExchangeLabels, |
| 104 | } |
| 105 | ctx = grpc.NewContextWithServerTransportStream(ctx, alts) |
| 106 | |
| 107 | res, err := handler(ctx, req) |
| 108 | if err != nil { // maybe trailers-only if headers haven't already been sent |
| 109 | if !alts.attachedLabels.Swap(true) { |
| 110 | alts.SetTrailer(alts.metadataExchangeLabels) |
| 111 | } |
| 112 | } else { // headers will be written; a message was sent |
| 113 | if !alts.attachedLabels.Swap(true) { |
| 114 | alts.SetHeader(alts.metadataExchangeLabels) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return res, err |
| 119 | } |
| 120 | |
| 121 | // attachLabelsStream embeds a grpc.ServerStream, and intercepts the |
| 122 | // SetHeader/SendHeader/SendMsg/SendTrailer call to attach metadata exchange |
nothing calls this directly
no test coverage detected