From e25861aa7b3a7fefc63be0b52839f74755089bc2 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 28 May 2025 11:25:40 -0700 Subject: [PATCH] Fix semconv instrument types (#6837) - The instrument type for `goconv.MemoryUsed` need to be an `Int64ObservableUpDownCounter`, not an `Int64ObservableCounter` [according to semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/ca0c5ada95e73abc2f741832ca56c46ce08e47d4/docs/runtime/go-metrics.md#metric-gomemoryused) - The instrument type for `systemconv.MemoryUsage` need to be an `Int64ObservableUpDownCounter`, not an `Int64ObservableGauge` [according to semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/ca0c5ada95e73abc2f741832ca56c46ce08e47d4/docs/system/system-metrics.md#metric-systemmemoryusage) All other [metric instrument type overrides](https://github.com/open-telemetry/opentelemetry-go/blob/6e90db55cac7ed4afea8a275d4af2a786ca8483c/semconv/weaver.yaml#L70-L83) have be verified. --- semconv/v1.33.0/MIGRATION.md | 12 ++++++++++++ semconv/v1.33.0/goconv/metric.go | 16 ++++++++-------- semconv/v1.33.0/systemconv/metric.go | 16 ++++++++-------- semconv/v1.34.0/goconv/metric.go | 16 ++++++++-------- semconv/v1.34.0/systemconv/metric.go | 16 ++++++++-------- semconv/weaver.yaml | 4 ++-- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/semconv/v1.33.0/MIGRATION.md b/semconv/v1.33.0/MIGRATION.md index e9c3172b5..4b55de615 100644 --- a/semconv/v1.33.0/MIGRATION.md +++ b/semconv/v1.33.0/MIGRATION.md @@ -2,6 +2,18 @@ The `go.opentelemetry.io/otel/semconv/v1.33.0` package should be a drop-in replacement for `go.opentelemetry.io/otel/semconv/v1.32.0` with the following exceptions. +## Metric instrument type fixes + +### `goconv.MemoryUse` + +The underlying metric instrument type for `goconv.MemoryUse` has been corrected be an `Int64ObservableUpDownCounter` instead of an `Int64ObservableCounter`. +This change aligns with the semantic conventions for memory usage metrics. + +### `systemconv.MemoryUsage` + +The underlying metric instrument type for `systemconv.MemoryUsage` has been corrected be an `Int64ObservableUpDownCounter` instead of an `Int64ObservableGauge`. +This change aligns with the semantic conventions for memory usage metrics. + ## Dropped deprecations The following declarations have been deprecated in the [OpenTelemetry Semantic Conventions]. diff --git a/semconv/v1.33.0/goconv/metric.go b/semconv/v1.33.0/goconv/metric.go index 86d8b456f..564ff8837 100644 --- a/semconv/v1.33.0/goconv/metric.go +++ b/semconv/v1.33.0/goconv/metric.go @@ -335,35 +335,35 @@ func (MemoryLimit) Description() string { // "go.memory.used" semantic conventions. It represents the memory used by the Go // runtime. type MemoryUsed struct { - metric.Int64ObservableCounter + metric.Int64ObservableUpDownCounter } // NewMemoryUsed returns a new MemoryUsed instrument. func NewMemoryUsed( m metric.Meter, - opt ...metric.Int64ObservableCounterOption, + opt ...metric.Int64ObservableUpDownCounterOption, ) (MemoryUsed, error) { // Check if the meter is nil. if m == nil { - return MemoryUsed{noop.Int64ObservableCounter{}}, nil + return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, nil } - i, err := m.Int64ObservableCounter( + i, err := m.Int64ObservableUpDownCounter( "go.memory.used", - append([]metric.Int64ObservableCounterOption{ + append([]metric.Int64ObservableUpDownCounterOption{ metric.WithDescription("Memory used by the Go runtime."), metric.WithUnit("By"), }, opt...)..., ) if err != nil { - return MemoryUsed{noop.Int64ObservableCounter{}}, err + return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, err } return MemoryUsed{i}, nil } // Inst returns the underlying metric instrument. -func (m MemoryUsed) Inst() metric.Int64ObservableCounter { - return m.Int64ObservableCounter +func (m MemoryUsed) Inst() metric.Int64ObservableUpDownCounter { + return m.Int64ObservableUpDownCounter } // Name returns the semantic convention name of the instrument. diff --git a/semconv/v1.33.0/systemconv/metric.go b/semconv/v1.33.0/systemconv/metric.go index e1935ccc2..4a593de89 100644 --- a/semconv/v1.33.0/systemconv/metric.go +++ b/semconv/v1.33.0/systemconv/metric.go @@ -1484,35 +1484,35 @@ func (m MemoryShared) Add(ctx context.Context, incr int64, attrs ...attribute.Ke // "system.memory.usage" semantic conventions. It represents the reports memory // in use by state. type MemoryUsage struct { - metric.Int64ObservableGauge + metric.Int64ObservableUpDownCounter } // NewMemoryUsage returns a new MemoryUsage instrument. func NewMemoryUsage( m metric.Meter, - opt ...metric.Int64ObservableGaugeOption, + opt ...metric.Int64ObservableUpDownCounterOption, ) (MemoryUsage, error) { // Check if the meter is nil. if m == nil { - return MemoryUsage{noop.Int64ObservableGauge{}}, nil + return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, nil } - i, err := m.Int64ObservableGauge( + i, err := m.Int64ObservableUpDownCounter( "system.memory.usage", - append([]metric.Int64ObservableGaugeOption{ + append([]metric.Int64ObservableUpDownCounterOption{ metric.WithDescription("Reports memory in use by state."), metric.WithUnit("By"), }, opt...)..., ) if err != nil { - return MemoryUsage{noop.Int64ObservableGauge{}}, err + return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, err } return MemoryUsage{i}, nil } // Inst returns the underlying metric instrument. -func (m MemoryUsage) Inst() metric.Int64ObservableGauge { - return m.Int64ObservableGauge +func (m MemoryUsage) Inst() metric.Int64ObservableUpDownCounter { + return m.Int64ObservableUpDownCounter } // Name returns the semantic convention name of the instrument. diff --git a/semconv/v1.34.0/goconv/metric.go b/semconv/v1.34.0/goconv/metric.go index 86d8b456f..564ff8837 100644 --- a/semconv/v1.34.0/goconv/metric.go +++ b/semconv/v1.34.0/goconv/metric.go @@ -335,35 +335,35 @@ func (MemoryLimit) Description() string { // "go.memory.used" semantic conventions. It represents the memory used by the Go // runtime. type MemoryUsed struct { - metric.Int64ObservableCounter + metric.Int64ObservableUpDownCounter } // NewMemoryUsed returns a new MemoryUsed instrument. func NewMemoryUsed( m metric.Meter, - opt ...metric.Int64ObservableCounterOption, + opt ...metric.Int64ObservableUpDownCounterOption, ) (MemoryUsed, error) { // Check if the meter is nil. if m == nil { - return MemoryUsed{noop.Int64ObservableCounter{}}, nil + return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, nil } - i, err := m.Int64ObservableCounter( + i, err := m.Int64ObservableUpDownCounter( "go.memory.used", - append([]metric.Int64ObservableCounterOption{ + append([]metric.Int64ObservableUpDownCounterOption{ metric.WithDescription("Memory used by the Go runtime."), metric.WithUnit("By"), }, opt...)..., ) if err != nil { - return MemoryUsed{noop.Int64ObservableCounter{}}, err + return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, err } return MemoryUsed{i}, nil } // Inst returns the underlying metric instrument. -func (m MemoryUsed) Inst() metric.Int64ObservableCounter { - return m.Int64ObservableCounter +func (m MemoryUsed) Inst() metric.Int64ObservableUpDownCounter { + return m.Int64ObservableUpDownCounter } // Name returns the semantic convention name of the instrument. diff --git a/semconv/v1.34.0/systemconv/metric.go b/semconv/v1.34.0/systemconv/metric.go index e1935ccc2..4a593de89 100644 --- a/semconv/v1.34.0/systemconv/metric.go +++ b/semconv/v1.34.0/systemconv/metric.go @@ -1484,35 +1484,35 @@ func (m MemoryShared) Add(ctx context.Context, incr int64, attrs ...attribute.Ke // "system.memory.usage" semantic conventions. It represents the reports memory // in use by state. type MemoryUsage struct { - metric.Int64ObservableGauge + metric.Int64ObservableUpDownCounter } // NewMemoryUsage returns a new MemoryUsage instrument. func NewMemoryUsage( m metric.Meter, - opt ...metric.Int64ObservableGaugeOption, + opt ...metric.Int64ObservableUpDownCounterOption, ) (MemoryUsage, error) { // Check if the meter is nil. if m == nil { - return MemoryUsage{noop.Int64ObservableGauge{}}, nil + return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, nil } - i, err := m.Int64ObservableGauge( + i, err := m.Int64ObservableUpDownCounter( "system.memory.usage", - append([]metric.Int64ObservableGaugeOption{ + append([]metric.Int64ObservableUpDownCounterOption{ metric.WithDescription("Reports memory in use by state."), metric.WithUnit("By"), }, opt...)..., ) if err != nil { - return MemoryUsage{noop.Int64ObservableGauge{}}, err + return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, err } return MemoryUsage{i}, nil } // Inst returns the underlying metric instrument. -func (m MemoryUsage) Inst() metric.Int64ObservableGauge { - return m.Int64ObservableGauge +func (m MemoryUsage) Inst() metric.Int64ObservableUpDownCounter { + return m.Int64ObservableUpDownCounter } // Name returns the semantic convention name of the instrument. diff --git a/semconv/weaver.yaml b/semconv/weaver.yaml index bf51ac59a..bde14bbcc 100644 --- a/semconv/weaver.yaml +++ b/semconv/weaver.yaml @@ -75,10 +75,10 @@ text_maps: go.memory.allocations: Int64ObservableCounter go.memory.gc.goal: Int64ObservableUpDownCounter go.memory.limit: Int64ObservableUpDownCounter - go.memory.used: Int64ObservableCounter + go.memory.used: Int64ObservableUpDownCounter go.processor.limit: Int64ObservableUpDownCounter process.cpu.time: Float64ObservableCounter - system.memory.usage: Int64ObservableGauge + system.memory.usage: Int64ObservableUpDownCounter system.memory.utilization: Float64ObservableGauge system.network.io: Int64ObservableCounter acronyms: