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

Modified otel-http-server-duration from microseconds to milliseconds #1537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed

- Change the `http-server-duration` instrument in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` to record milliseconds instead of microseconds match what is specified in the OpenTelemetry specification. (#1414, #1537)

## [1.3.0/0.28.0] - 2021-12-10

### ⚠️ Notice ⚠️
Expand Down
9 changes: 5 additions & 4 deletions instrumentation/net/http/otelhttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Handler struct {
filters []Filter
spanNameFormatter func(string, *http.Request) string
counters map[string]metric.Int64Counter
valueRecorders map[string]metric.Int64Histogram
valueRecorders map[string]metric.Float64Histogram
}

func defaultHandlerFormatter(operation string, _ *http.Request) string {
Expand Down Expand Up @@ -94,15 +94,15 @@ func handleErr(err error) {

func (h *Handler) createMeasures() {
h.counters = make(map[string]metric.Int64Counter)
h.valueRecorders = make(map[string]metric.Int64Histogram)
h.valueRecorders = make(map[string]metric.Float64Histogram)

requestBytesCounter, err := h.meter.NewInt64Counter(RequestContentLength)
handleErr(err)

responseBytesCounter, err := h.meter.NewInt64Counter(ResponseContentLength)
handleErr(err)

serverLatencyMeasure, err := h.meter.NewInt64Histogram(ServerLatency)
serverLatencyMeasure, err := h.meter.NewFloat64Histogram(ServerLatency)
handleErr(err)

h.counters[RequestContentLength] = requestBytesCounter
Expand Down Expand Up @@ -195,7 +195,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.counters[RequestContentLength].Add(ctx, bw.read, attributes...)
h.counters[ResponseContentLength].Add(ctx, rww.written, attributes...)

elapsedTime := time.Since(requestStartTime).Microseconds()
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedTime := float64(time.Since(requestStartTime)) / float64(time.Millisecond)
rltoSD marked this conversation as resolved.
Show resolved Hide resolved

h.valueRecorders[ServerLatency].Record(ctx, elapsedTime, attributes...)
}
Expand Down