open-telemetry / opentelemetry-java

OpenTelemetry Java SDK
https://opentelemetry.io
Apache License 2.0
1.98k stars 825 forks source link

When to use gauge and histogram while recording metrics using opentelemetry #6790

Closed iumairhasan closed 4 hours ago

iumairhasan commented 1 day ago

Issue

While recording metrics using open telemetry and exporting them to cloudwatch, I'm trying to understand when to use histogram vs gauge.

While referring to the data model documentation , my understanding is while using gauge it records exactly one singular value calculated at a give time, whereas histogram is collection of statistical computed values of actual data within the duration of sample time, but this does not export the actual value to cloudwatch, I was curious on what value is actually exported to cloudwatch while exporting histogram.

In my application, I'm trying to collect metrics to give me view of application like API latency, number of calls to API, and other stuff like number of active client connections at a given time.

Is there any guidance documented for using histogram vs gauge while using Open telemetry?

Thank you.

Version

Exporter

trask commented 1 day ago

hi @iumairhasan!

I'm trying to collect metrics to give me view of application like API latency, number of calls to API, and other stuff like number of active client connections at a given time

one thing that could help is to look at the existing OpenTelemetry semantic conventions for HTTP and Database to see how they are modeling these types of metrics

at the end of the day though, you'll also have to factor in how cloudwatch handles/maps histograms, gauges, counters and updowncounters, which is something you'll probably need to consult with cloudwatch folks to figure out

iumairhasan commented 1 day ago

Got it. I will look into what cloudwatch is recording from these meters.

A quick question though, is the definition of histogram and gauge meters be interpreted from these data-model documentation? i.e if I understand it right, then gauge simply records the value of sample at a given time, whereas histogram has aggregation of statistical values collected during sample time.

Thanks for the semantic conventions reference, I think that is useful for me while working with metrics!

trask commented 1 day ago

A quick question though, is the definition of histogram and gauge meters be interpreted from these data-model documentation?

yup, that is the data model that underpins the Java metrics implementation

jack-berg commented 2 hours ago

There's also a guide on instrument type selection here.

trask commented 1 hour ago

There's also a guide on instrument type selection here.

oh nice!