Skip to content

Commit

Permalink
otelhttp: set unit and description on all instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k committed Nov 1, 2023
1 parent cff1423 commit 3649b63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions instrumentation/net/http/otelhttp/handler.go
Expand Up @@ -107,13 +107,16 @@ func (h *middleware) createMeasures() {
h.counters = make(map[string]metric.Int64Counter)
h.valueRecorders = make(map[string]metric.Float64Histogram)

requestBytesCounter, err := h.meter.Int64Counter(RequestContentLength)
requestBytesCounter, err := h.meter.Int64Counter(RequestContentLength, metric.WithUnit("By"),
metric.WithDescription("Measures the size of HTTP request content length (uncompressed)"))
handleErr(err)

responseBytesCounter, err := h.meter.Int64Counter(ResponseContentLength)
responseBytesCounter, err := h.meter.Int64Counter(ResponseContentLength, metric.WithUnit("By"),
metric.WithDescription("Measures the size of HTTP response content length (uncompressed)"))
handleErr(err)

serverLatencyMeasure, err := h.meter.Float64Histogram(ServerLatency, metric.WithUnit("ms"))
serverLatencyMeasure, err := h.meter.Float64Histogram(ServerLatency, metric.WithUnit("ms"),
metric.WithDescription("Measures the duration of HTTP request handling"))
handleErr(err)

h.counters[RequestContentLength] = requestBytesCounter
Expand Down
8 changes: 6 additions & 2 deletions instrumentation/net/http/otelhttp/test/handler_test.go
Expand Up @@ -50,7 +50,9 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, attrs attribut
require.Len(t, sm.Metrics, 3)

want := metricdata.Metrics{
Name: "http.server.request_content_length",
Name: "http.server.request_content_length",
Description: "Measures the size of HTTP request content length (uncompressed)",
Unit: "By",
Data: metricdata.Sum[int64]{
DataPoints: []metricdata.DataPoint[int64]{{Attributes: attrs, Value: 0}},
Temporality: metricdata.CumulativeTemporality,
Expand All @@ -60,7 +62,9 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, attrs attribut
metricdatatest.AssertEqual(t, want, sm.Metrics[0], metricdatatest.IgnoreTimestamp())

want = metricdata.Metrics{
Name: "http.server.response_content_length",
Name: "http.server.response_content_length",
Description: "Measures the size of HTTP response content length (uncompressed)",
Unit: "By",
Data: metricdata.Sum[int64]{
DataPoints: []metricdata.DataPoint[int64]{{Attributes: attrs, Value: 11}},
Temporality: metricdata.CumulativeTemporality,
Expand Down

0 comments on commit 3649b63

Please sign in to comment.