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

Add request count metric with status code label #2138

Closed

Conversation

nabokihms
Copy link

@nabokihms nabokihms commented Mar 31, 2022

Signed-off-by: m.nabokikh [email protected]

Closes #711

This PR adds a counter for the total amount of requests with the http_status_code label. It will help us to be aware of the ratio of errors.

I decided to avoid adding status code to other metrics because it looks excessive. Instead, counting the number of requests seems more sensible.

P.S.:
I accidentally closed the previous PR #771

@nabokihms
Copy link
Author

@Aneurysm9 fyi

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metric overlaps with the information that will be communicated by the http.server.active_requests: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/metrics/semantic_conventions/http-metrics.md#http-server

I'm hesitant to accept this addition if we are ultimately going to comply with the OTel semantic conventions and there will be duplication. Should this be implemented as an UpDownCounter and track the active requests? Do the semantic conventions need to be updated before we add this?

CHANGELOG.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 31, 2022

Codecov Report

Merging #2138 (4501944) into main (e915b7c) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2138   +/-   ##
=====================================
  Coverage   69.9%   69.9%           
=====================================
  Files        147     147           
  Lines       6934    6936    +2     
=====================================
+ Hits        4851    4853    +2     
  Misses      1959    1959           
  Partials     124     124           
Impacted Files Coverage Δ
instrumentation/net/http/otelhttp/handler.go 82.8% <100.0%> (+0.1%) ⬆️

@Aneurysm9
Copy link
Member

The spec recommends that the status code be added to the duration metrics, which can provide a count when aggregated as a histogram. Should we do that and rely on the user to configure a view to do dimension reduction if histograms with status codes is a cardinality concern?

@nabokihms
Copy link
Author

From my point of view, it would be better to avoid using updown counter for errors, because you cannot apply rate functions to it.

Adding status code label for histograms sounds ok to me. It is a common practice. Should we go this way then?

@nabokihms
Copy link
Author

@MrAlias @Aneurysm9, just a friendly reminder. Is it ok to add the status code label to the server latency metric?

@nabokihms nabokihms requested a review from MrAlias April 6, 2022 04:37
@Aneurysm9
Copy link
Member

@MrAlias @Aneurysm9, just a friendly reminder. Is it ok to add the status code label to the server latency metric?

I'm good with that approach.

@nabokihms nabokihms force-pushed the net-http-request-count-status branch from 854e267 to ea21e15 Compare April 8, 2022 04:57
@nabokihms
Copy link
Author

I've just added the status code label, so everything should be good now.

@nabokihms
Copy link
Author

Folks, any updates on this one? It would be best if we resolve all concerns about this PR before the next release 🙏

@nabokihms nabokihms force-pushed the net-http-request-count-status branch from 1b1f888 to 92d9aa4 Compare May 16, 2022 12:50
@nabokihms
Copy link
Author

I rebased this branch on the main. Just a friendly reminder, still waiting for the feedback 😸

@sagikazarmark
Copy link
Contributor

Any update on this PR?

@mmanciop
Copy link
Contributor

Already implemented:

attributes = append(attributes, semconv.HTTPStatusCode(statusCode))

@dmathieu dmathieu requested a review from a team February 24, 2023 09:04
@dmathieu
Copy link
Member

Already implemented:

Your link is setting attributes for the spans, not metrics.

@nabokihms
Copy link
Author

@dmathieu hello there! A test is not included for this PR. Do you want me to add one, or should I wait for the initial review?

@dmathieu
Copy link
Member

I believe adding a test would make the review easier.

@nabokihms
Copy link
Author

@dmathieu I checked this out, and it seems like the issue is fixed by the following code

if rww.statusCode > 0 {
attributes = append(attributes, semconv.HTTPStatusCode(rww.statusCode))
}

All thanks to @MrAlias. Now everything works as expected. Thanks to everyone. It was a two years journey that came to an end (I'm going to close the PR).

@nabokihms nabokihms closed this Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add status code to net/http metrics
8 participants