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

Add new metrics to the runtime instrumentation

Open liustanley opened this issue 2 years ago • 2 comments

Problem Statement

I noticed that there a number of metrics that are missing from the current runtime instrumentation, and I'd like to request for the following runtime metrics to be added:

runtime.NumCPU() runtime.MemStats.Alloc runtime.MemStats.TotalAlloc runtime.MemStats.Sys runtime.MemStats.Mallocs runtime.MemStats.Frees runtime.MemStats.TotalAlloc runtime.MemStats.StackInuse runtime.MemStats.StackSys runtime.MemStats.MSpanInuse runtime.MemStats.MSpanSys runtime.MemStats.MCacheInuse runtime.MemStats.MCacheSys runtime.MemStats.BuckHashSys runtime.MemStats.GCSys runtime.MemStats.OtherSys runtime.MemStats.NextGC runtime.MemStats.LastGC runtime.MemStats.NumForcedGC runtime.MemStats.GCCPUFraction runtime/debug.GCStats.PauseQuantiles

Proposed Solution

I believe most of these metrics can be added easily in this file: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/runtime/runtime.go

liustanley avatar Aug 29 '23 19:08 liustanley

Please link to the relevant OTel semantic conventions these metrics will be mapped to.

MrAlias avatar Aug 29 '23 23:08 MrAlias

Not sure if this helps @liustanley, but I've been maintaining a module of instrumentation that simply derives from the Go runtime/metrics source.

https://github.com/lightstep/otel-launcher-go/tree/main/lightstep/instrumentation/runtime

The way this works is a human has to read and interpret the changes in https://pkg.go.dev/runtime/metrics#hdr-Supported_metrics at each new release and decide how these concepts map into OTel concepts. I've been tracking this for two major releases now, with support for the standard toolchain's metrics produced in 1.19, 1.20, and 1.21. When unrecognized metrics appear from the library, a message is logged so the developers know to go looking for updates.

I'd be glad to help get it migrated into this repo. Here's an example where I added go-1.21 support https://github.com/lightstep/otel-launcher-go/pull/537. The new cpu and garbage collection metrics have been invaluable, and I don't think we need to block on OTel semantic conventions, maybe.

jmacd avatar Nov 06 '23 20:11 jmacd