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

Method processRPCEnd

stats/opentelemetry/client_metrics.go:244–283  ·  view source on GitHub ↗
(ctx context.Context, ai *attemptInfo, e *stats.End)

Source from the content-addressed store, hash-verified

242}
243
244func (h *clientMetricsHandler) processRPCEnd(ctx context.Context, ai *attemptInfo, e *stats.End) {
245 ci := getCallInfo(ctx)
246 if ci == nil {
247 logger.Error("ctx passed into client side stats handler metrics event handling has no metrics data present")
248 return
249 }
250 latency := float64(time.Since(ai.startTime)) / float64(time.Second)
251 st := "OK"
252 if e.Error != nil {
253 s, _ := status.FromError(e.Error)
254 st = canonicalString(s.Code())
255 }
256
257 attributes := []otelattribute.KeyValue{
258 otelattribute.String("grpc.method", ci.method),
259 otelattribute.String("grpc.target", ci.target),
260 otelattribute.String("grpc.status", st),
261 }
262
263 for k, v := range ai.pluginOptionLabels {
264 attributes = append(attributes, otelattribute.String(k, v))
265 }
266
267 for _, o := range h.options.MetricsOptions.OptionalLabels {
268 // TODO: Add a filter for converting to unknown if not present in the
269 // CSM Plugin Option layer by adding an optional labels API.
270 if val, ok := ai.xdsLabels[o]; ok {
271 attributes = append(attributes, otelattribute.String(o, val))
272 } else if o == "grpc.client.call.custom" {
273 label := estats.CustomLabelFromContext(ctx)
274 attributes = append(attributes, otelattribute.String(o, label))
275 }
276 }
277
278 // Allocate vararg slice once.
279 opts := []otelmetric.RecordOption{otelmetric.WithAttributeSet(otelattribute.NewSet(attributes...))}
280 h.clientMetrics.attemptDuration.Record(ctx, latency, opts...)
281 h.clientMetrics.attemptSentTotalCompressedMessageSize.Record(ctx, atomic.LoadInt64(&ai.sentCompressedBytes), opts...)
282 h.clientMetrics.attemptRcvdTotalCompressedMessageSize.Record(ctx, atomic.LoadInt64(&ai.recvCompressedBytes), opts...)
283}
284
285const (
286 // ClientAttemptStartedMetricName is the number of client call attempts

Callers 1

processRPCEventMethod · 0.95

Calls 7

FromErrorFunction · 0.92
getCallInfoFunction · 0.85
canonicalStringFunction · 0.85
CodeMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.65
RecordMethod · 0.45

Tested by

no test coverage detected