MCPcopy
hub / github.com/grpc/grpc-go / streamInterceptor

Method streamInterceptor

stats/opentelemetry/client_metrics.go:115–133  ·  view source on GitHub ↗
(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption)

Source from the content-addressed store, hash-verified

113}
114
115func (h *clientMetricsHandler) streamInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
116 ctx, ci := getOrCreateCallInfo(ctx, cc, method, opts...)
117
118 if h.options.MetricsOptions.pluginOption != nil {
119 md := h.options.MetricsOptions.pluginOption.GetMetadata()
120 for k, vs := range md {
121 for _, v := range vs {
122 ctx = metadata.AppendToOutgoingContext(ctx, k, v)
123 }
124 }
125 }
126
127 startTime := time.Now()
128 callback := func(err error) {
129 h.perCallMetrics(ctx, err, startTime, ci)
130 }
131 opts = append([]grpc.CallOption{grpc.OnFinish(callback)}, opts...)
132 return streamer(ctx, desc, cc, method, opts...)
133}
134
135// perCallMetrics records per call metrics for both unary and stream calls.
136func (h *clientMetricsHandler) perCallMetrics(ctx context.Context, err error, startTime time.Time, ci *callInfo) {

Callers

nothing calls this directly

Calls 6

perCallMetricsMethod · 0.95
AppendToOutgoingContextFunction · 0.92
OnFinishFunction · 0.92
getOrCreateCallInfoFunction · 0.85
NowMethod · 0.80
GetMetadataMethod · 0.65

Tested by

no test coverage detected