open-telemetry / opentelemetry-go-contrib

Collection of extensions for OpenTelemetry-Go.
https://opentelemetry.io/
Apache License 2.0
1.22k stars 566 forks source link

Missing runtime metrics #6321

Open morningspace opened 2 weeks ago

morningspace commented 2 weeks ago

Description

Some runtime metrics, e.g.: memStats.Alloc, memStats.Sys, are missing.

Steps To Reproduce

Expected behavior

Can the missing runtime metrics be added? If a PR is allowed, we'd be happy to contribute.

ysomad commented 4 days ago

any updates?

dmathieu commented 4 days ago

The non-deprecated runtime uses runtime/metrics to retrieve metrics data. The metrics we exposed are documented in semantic conventions.

It looks like you're looking for go.memory.allocated and go.memory.used.

The current runtime does expose those two metrics on its latest version, even though it uses the runtime/metrics package, not runtime.MemStats.

morningspace commented 3 days ago

Thanks @dmathieu for your reply!

dmathieu commented 3 days ago

cc @dashpole who led this.

dashpole commented 3 days ago

Based on https://github.com/prometheus/client_golang/blob/76b74e25d5660965000a74cf2e918c217ed76da2/prometheus/go_collector.go#L26, this is the mapping from memStats to go runtime metrics:

/memory/classes/total:bytes isn't useful on its own, as it includes released memory. For the new runtime metrics, we provide the go.memory.used metric, which excludes released memory.

You can see https://github.com/golang/go/issues/67120 for why we don't provide live + unswept heap memory via /memory/classes/heap/objects:bytes:

live+unswept heap memory isn't a terribly useful metric since it tends to be noisy and misleading, subject to sweep scheduling nuances. The heap goal is a much more reliable measure of total heap footprint.

In keeping with that, we would recommend using the go.memory.gc.goal metric, which measures the heap goal.