open-telemetry / opentelemetry-go

OpenTelemetry Go API and SDK
https://opentelemetry.io/docs/languages/go
Apache License 2.0
5.35k stars 1.09k forks source link

Fix exemplars being added to gauge metrics in the prometheus exporter #5912

Closed trthomps closed 1 month ago

trthomps commented 1 month ago

Prometheus Gauge metrics don't support exemplars and while addGaugeMetric() doesn't add them, addSumMetric() will if the metric is monotonic. This causes the prometheus client to throw an error:

* error collecting metric Desc{fqName: "http_server_request_body_size_bytes", help: "Measures size of RPC request messages (uncompressed).", constLabels: {}, variableLabels: {net_protocol_name,net_protocol_version,http_method,http_route,http_scheme,net_host_name,net_host_port,otel_scope_name,otel_scope_version}}: cannot inject exemplar into Gauge, Summary or Untyped
linux-foundation-easycla[bot] commented 1 month ago

CLA Signed

The committers listed above are authorized under a signed CLA.

dashpole commented 1 month ago

Would be good to have a test

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 84.6%. Comparing base (30c4a9a) to head (3700b79). Report is 1 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-go/pull/5912/graphs/tree.svg?width=650&height=150&src=pr&token=8efTmh4kvf&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://app.codecov.io/gh/open-telemetry/opentelemetry-go/pull/5912?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) ```diff @@ Coverage Diff @@ ## main #5912 +/- ## ===================================== Coverage 84.6% 84.6% ===================================== Files 272 272 Lines 22837 22839 +2 ===================================== + Hits 19322 19325 +3 + Misses 3171 3170 -1 Partials 344 344 ``` [see 2 files with indirect coverage changes](https://app.codecov.io/gh/open-telemetry/opentelemetry-go/pull/5912/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)
trthomps commented 1 month ago

Would be good to have a test

@dashpole Added a test, let me know if you know of a better way to test this, I did step through the debugger and exemplars are getting added to the DataPoint.

trthomps commented 1 month ago

Thanks so much for working with me on this @dashpole.