(ctx context.Context, ai *attemptInfo, e *stats.End)
| 242 | } |
| 243 | |
| 244 | func (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 | |
| 285 | const ( |
| 286 | // ClientAttemptStartedMetricName is the number of client call attempts |
no test coverage detected