Skip to content

Commit

Permalink
Add request count metric with status code label
Browse files Browse the repository at this point in the history
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
  • Loading branch information
nabokihms committed Apr 8, 2022
1 parent 5611141 commit ea21e15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- The project is now tested against Go 1.18 (in addition to the existing 1.16 and 1.17) (#1976)
- Add the HTTP status code label to `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` instrumentation that allows to count requests by their response code. (#771, #2138)

### Changed

Expand Down
4 changes: 3 additions & 1 deletion instrumentation/net/http/otelhttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// 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...)
// Status code label is required to count the errors ratio
durationAttributes := append(attributes, semconv.HTTPStatusCodeKey.Int(rww.statusCode))
h.valueRecorders[ServerLatency].Record(ctx, elapsedTime, durationAttributes...)
}

func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, rerr, werr error) {
Expand Down

0 comments on commit ea21e15

Please sign in to comment.