Skip to content

Commit cf85f33

Browse files
gaiaz-iusipovdmathieuMrAlias
authored
Remove redundant otelhttp allocation (#5842)
There is no need to wrap `MeasurementOption` to a slice Co-authored-by: Damien Mathieu <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent af75717 commit cf85f33

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

instrumentation/net/http/otelhttp/handler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
232232
attributes = append(attributes, semconv.HTTPStatusCode(rww.statusCode))
233233
}
234234
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
235-
addOpts := []metric.AddOption{o} // Allocate vararg slice once.
236-
h.requestBytesCounter.Add(ctx, bw.read.Load(), addOpts...)
237-
h.responseBytesCounter.Add(ctx, rww.written, addOpts...)
235+
236+
h.requestBytesCounter.Add(ctx, bw.read.Load(), o)
237+
h.responseBytesCounter.Add(ctx, rww.written, o)
238238

239239
// Use floating point division here for higher precision (instead of Millisecond method).
240240
elapsedTime := float64(time.Since(requestStartTime)) / float64(time.Millisecond)

instrumentation/net/http/otelhttp/transport.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
172172
metricAttrs = append(metricAttrs, semconv.HTTPStatusCode(res.StatusCode))
173173
}
174174
o := metric.WithAttributeSet(attribute.NewSet(metricAttrs...))
175-
addOpts := []metric.AddOption{o} // Allocate vararg slice once.
176-
t.requestBytesCounter.Add(ctx, bw.read.Load(), addOpts...)
175+
176+
t.requestBytesCounter.Add(ctx, bw.read.Load(), o)
177177
// For handling response bytes we leverage a callback when the client reads the http response
178178
readRecordFunc := func(n int64) {
179-
t.responseBytesCounter.Add(ctx, n, addOpts...)
179+
t.responseBytesCounter.Add(ctx, n, o)
180180
}
181181

182182
// traces

0 commit comments

Comments
 (0)