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

Method perCallMetrics

stats/opentelemetry/client_metrics.go:136–151  ·  view source on GitHub ↗

perCallMetrics records per call metrics for both unary and stream calls.

(ctx context.Context, err error, startTime time.Time, ci *callInfo)

Source from the content-addressed store, hash-verified

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) {
137 callLatency := float64(time.Since(startTime)) / float64(time.Second)
138 attributes := []otelattribute.KeyValue{
139 otelattribute.String("grpc.method", ci.method),
140 otelattribute.String("grpc.target", ci.target),
141 otelattribute.String("grpc.status", canonicalString(status.Code(err))),
142 }
143 for _, o := range h.options.MetricsOptions.OptionalLabels {
144 if o == "grpc.client.call.custom" {
145 label := estats.CustomLabelFromContext(ctx)
146 attributes = append(attributes, otelattribute.String(o, label))
147 }
148 }
149 attrs := otelmetric.WithAttributeSet(otelattribute.NewSet(attributes...))
150 h.clientMetrics.callDuration.Record(ctx, callLatency, attrs)
151}
152
153// TagConn exists to satisfy stats.Handler.
154func (h *clientMetricsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context {

Callers 2

unaryInterceptorMethod · 0.95
streamInterceptorMethod · 0.95

Calls 4

CodeFunction · 0.92
canonicalStringFunction · 0.85
StringMethod · 0.65
RecordMethod · 0.45

Tested by

no test coverage detected