Skip to content

Commit

Permalink
Modified otel-http-server-duration from microseconds to milliseconds (#…
Browse files Browse the repository at this point in the history
…1537)

* modified changelog and otel-http-server-duration from microseconds to milliseconds

* Update comments for floating point division

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Update changelog comment location

* EOL Character

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
Richard To and MrAlias authored Jan 4, 2022
1 parent f06b204 commit 49ea9ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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)

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

0 comments on commit 49ea9ed

Please sign in to comment.