Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelhttp: set unit on all instruments #4500

Merged
merged 7 commits into from Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `"go.opentelemetry.io/contrib/config"` package that includes configuration models generated via go-jsonschema. (#4376)
- Add `NewSDK` function to `"go.opentelemetry.io/contrib/config"`. The initial implementation only returns noop providers. (#4414)
- Add metrics support (No-op, OTLP and Prometheus) to `go.opentelemetry.io/contrib/exporters/autoexport`. (#4229, #4479)
- otelhttp: set units on all instruments (#4500)
pellared marked this conversation as resolved.
Show resolved Hide resolved

### Changed

Expand Down
2 changes: 1 addition & 1 deletion instrumentation/net/http/otelhttp/common.go
Expand Up @@ -34,7 +34,7 @@ const (
RequestCount = "http.server.request_count" // Incoming request count total
RequestContentLength = "http.server.request_content_length" // Incoming request bytes total
ResponseContentLength = "http.server.response_content_length" // Incoming response bytes total
ServerLatency = "http.server.duration" // Incoming end to end duration, microseconds
ServerLatency = "http.server.duration" // Incoming end to end duration, milliseconds
)

// Filter is a predicate used to determine whether a given http.request should
Expand Down
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)"))
ash2k marked this conversation as resolved.
Show resolved Hide resolved
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)"))
ash2k marked this conversation as resolved.
Show resolved Hide resolved
handleErr(err)

serverLatencyMeasure, err := h.meter.Float64Histogram(ServerLatency)
serverLatencyMeasure, err := h.meter.Float64Histogram(ServerLatency, metric.WithUnit("ms"),
metric.WithDescription("Measures the duration of HTTP request handling"))
ash2k marked this conversation as resolved.
Show resolved Hide resolved
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