opentelemetry-go-contrib icon indicating copy to clipboard operation
opentelemetry-go-contrib copied to clipboard

Add request count metric with status code label

Open nabokihms opened this issue 2 years ago • 9 comments

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

Closes https://github.com/open-telemetry/opentelemetry-go-contrib/issues/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 https://github.com/open-telemetry/opentelemetry-go-contrib/pull/771

nabokihms avatar Mar 31 '22 13:03 nabokihms

@Aneurysm9 fyi

nabokihms avatar Mar 31 '22 13:03 nabokihms

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%) :arrow_up:

codecov[bot] avatar Mar 31 '22 17:03 codecov[bot]

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?

Aneurysm9 avatar Mar 31 '22 19:03 Aneurysm9

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 avatar Apr 01 '22 03:04 nabokihms

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

nabokihms avatar Apr 06 '22 04:04 nabokihms

@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.

Aneurysm9 avatar Apr 06 '22 23:04 Aneurysm9

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

nabokihms avatar Apr 08 '22 04:04 nabokihms

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

nabokihms avatar Apr 20 '22 10:04 nabokihms

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

nabokihms avatar May 16 '22 12:05 nabokihms

Any update on this PR?

sagikazarmark avatar Dec 14 '22 12:12 sagikazarmark

Already implemented: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/c52452d90ab05a5a92f54398c0093376883cca2a/instrumentation/net/http/otelhttp/handler.go#L246

mmanciop avatar Feb 24 '23 08:02 mmanciop

Already implemented:

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

dmathieu avatar Feb 24 '23 09:02 dmathieu

@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?

nabokihms avatar Feb 24 '23 10:02 nabokihms

I believe adding a test would make the review easier.

dmathieu avatar Feb 24 '23 10:02 dmathieu

@dmathieu I checked this out, and it seems like the issue is fixed by the following code https://github.com/open-telemetry/opentelemetry-go-contrib/blob/c52452d90ab05a5a92f54398c0093376883cca2a/instrumentation/net/http/otelhttp/handler.go#L219-L221

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 avatar Feb 26 '23 00:02 nabokihms