From be28c6bc8faf6984f8e0edb32dc0f3cc281acd00 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 25 Aug 2025 06:51:01 -0700 Subject: [PATCH] Wrap `Float64ObservableCounter` with `system.CPUTime` (#7235) Fix #7234 Addresses revert of [`cpu` to `system` namespace](https://github.com/open-telemetry/semantic-conventions/pull/1896) in semantic conventions. --- semconv/templates/registry/go/weaver.yaml | 2 +- semconv/v1.36.0/systemconv/metric.go | 40 +++++------------------ 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/semconv/templates/registry/go/weaver.yaml b/semconv/templates/registry/go/weaver.yaml index 7bd608123..814793616 100644 --- a/semconv/templates/registry/go/weaver.yaml +++ b/semconv/templates/registry/go/weaver.yaml @@ -69,7 +69,7 @@ text_maps: boolean: bool boolean[]: "...bool" instrument: - cpu.time: Float64ObservableCounter + system.cpu.time: Float64ObservableCounter go.config.gogc: Int64ObservableUpDownCounter go.goroutine.count: Int64ObservableUpDownCounter go.memory.allocated: Int64ObservableCounter diff --git a/semconv/v1.36.0/systemconv/metric.go b/semconv/v1.36.0/systemconv/metric.go index ae6a95160..fddec3fca 100644 --- a/semconv/v1.36.0/systemconv/metric.go +++ b/semconv/v1.36.0/systemconv/metric.go @@ -472,35 +472,35 @@ func (m CPUPhysicalCount) Add(ctx context.Context, incr int64, attrs ...attribut // "system.cpu.time" semantic conventions. It represents the seconds each logical // CPU spent on each mode. type CPUTime struct { - metric.Float64Counter + metric.Float64ObservableCounter } // NewCPUTime returns a new CPUTime instrument. func NewCPUTime( m metric.Meter, - opt ...metric.Float64CounterOption, + opt ...metric.Float64ObservableCounterOption, ) (CPUTime, error) { // Check if the meter is nil. if m == nil { - return CPUTime{noop.Float64Counter{}}, nil + return CPUTime{noop.Float64ObservableCounter{}}, nil } - i, err := m.Float64Counter( + i, err := m.Float64ObservableCounter( "system.cpu.time", - append([]metric.Float64CounterOption{ + append([]metric.Float64ObservableCounterOption{ metric.WithDescription("Seconds each logical CPU spent on each mode"), metric.WithUnit("s"), }, opt...)..., ) if err != nil { - return CPUTime{noop.Float64Counter{}}, err + return CPUTime{noop.Float64ObservableCounter{}}, err } return CPUTime{i}, nil } // Inst returns the underlying metric instrument. -func (m CPUTime) Inst() metric.Float64Counter { - return m.Float64Counter +func (m CPUTime) Inst() metric.Float64ObservableCounter { + return m.Float64ObservableCounter } // Name returns the semantic convention name of the instrument. @@ -518,30 +518,6 @@ func (CPUTime) Description() string { return "Seconds each logical CPU spent on each mode" } -// Add adds incr to the existing count. -// -// All additional attrs passed are included in the recorded value. -func (m CPUTime) Add( - ctx context.Context, - incr float64, - attrs ...attribute.KeyValue, -) { - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - *o = (*o)[:0] - addOptPool.Put(o) - }() - - *o = append( - *o, - metric.WithAttributes( - attrs..., - ), - ) - - m.Float64Counter.Add(ctx, incr, *o...) -} - // AttrCPULogicalNumber returns an optional attribute for the // "cpu.logical_number" semantic convention. It represents the logical CPU number // [0..n-1].