perCallMetrics records per call metrics for both unary and stream calls.
(ctx context.Context, err error, startTime time.Time, ci *callInfo)
| 134 | |
| 135 | // perCallMetrics records per call metrics for both unary and stream calls. |
| 136 | func (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. |
| 154 | func (h *clientMetricsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context { |
no test coverage detected