summaryrefslogtreecommitdiff
path: root/vendor/go.opentelemetry.io/otel/internal
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-09-16 11:06:00 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-16 09:06:00 +0000
commitb2572b9e074ebbce8bcf1b9979d4d8ea066650d6 (patch)
tree0c2a08ed63b582676ce7661252a6917db751c62a /vendor/go.opentelemetry.io/otel/internal
parent[chore]: Bump golang.org/x/net from 0.28.0 to 0.29.0 (#3303) (diff)
downloadgotosocial-b2572b9e074ebbce8bcf1b9979d4d8ea066650d6.tar.xz
[chore] Bump otel deps -> v1.30.0/v0.52.0 (#3307)
Diffstat (limited to 'vendor/go.opentelemetry.io/otel/internal')
-rw-r--r--vendor/go.opentelemetry.io/otel/internal/global/meter.go274
1 files changed, 206 insertions, 68 deletions
diff --git a/vendor/go.opentelemetry.io/otel/internal/global/meter.go b/vendor/go.opentelemetry.io/otel/internal/global/meter.go
index cfd1df9bf..f2fc3929b 100644
--- a/vendor/go.opentelemetry.io/otel/internal/global/meter.go
+++ b/vendor/go.opentelemetry.io/otel/internal/global/meter.go
@@ -5,8 +5,8 @@ package global // import "go.opentelemetry.io/otel/internal/global"
import (
"container/list"
+ "reflect"
"sync"
- "sync/atomic"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/embedded"
@@ -76,7 +76,7 @@ func (p *meterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me
return val
}
- t := &meter{name: name, opts: opts}
+ t := &meter{name: name, opts: opts, instruments: make(map[instID]delegatedInstrument)}
p.meters[key] = t
return t
}
@@ -92,17 +92,29 @@ type meter struct {
opts []metric.MeterOption
mtx sync.Mutex
- instruments []delegatedInstrument
+ instruments map[instID]delegatedInstrument
registry list.List
- delegate atomic.Value // metric.Meter
+ delegate metric.Meter
}
type delegatedInstrument interface {
setDelegate(metric.Meter)
}
+// instID are the identifying properties of a instrument.
+type instID struct {
+ // name is the name of the stream.
+ name string
+ // description is the description of the stream.
+ description string
+ // kind defines the functional group of the instrument.
+ kind reflect.Type
+ // unit is the unit of the stream.
+ unit string
+}
+
// setDelegate configures m to delegate all Meter functionality to Meters
// created by provider.
//
@@ -110,12 +122,12 @@ type delegatedInstrument interface {
//
// It is guaranteed by the caller that this happens only once.
func (m *meter) setDelegate(provider metric.MeterProvider) {
- meter := provider.Meter(m.name, m.opts...)
- m.delegate.Store(meter)
-
m.mtx.Lock()
defer m.mtx.Unlock()
+ meter := provider.Meter(m.name, m.opts...)
+ m.delegate = meter
+
for _, inst := range m.instruments {
inst.setDelegate(meter)
}
@@ -133,169 +145,295 @@ func (m *meter) setDelegate(provider metric.MeterProvider) {
}
func (m *meter) Int64Counter(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64Counter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64Counter(name, options...)
+ }
+
i := &siCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64CounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Int64UpDownCounter(name string, options ...metric.Int64UpDownCounterOption) (metric.Int64UpDownCounter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64UpDownCounter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64UpDownCounter(name, options...)
+ }
+
i := &siUpDownCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64UpDownCounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Int64Histogram(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64Histogram(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64Histogram(name, options...)
+ }
+
i := &siHistogram{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64HistogramConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (metric.Int64Gauge, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64Gauge(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64Gauge(name, options...)
+ }
+
i := &siGauge{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64GaugeConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Int64ObservableCounter(name string, options ...metric.Int64ObservableCounterOption) (metric.Int64ObservableCounter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64ObservableCounter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64ObservableCounter(name, options...)
+ }
+
i := &aiCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64ObservableCounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Int64ObservableUpDownCounter(name string, options ...metric.Int64ObservableUpDownCounterOption) (metric.Int64ObservableUpDownCounter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64ObservableUpDownCounter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64ObservableUpDownCounter(name, options...)
+ }
+
i := &aiUpDownCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64ObservableUpDownCounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Int64ObservableGauge(name string, options ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Int64ObservableGauge(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Int64ObservableGauge(name, options...)
+ }
+
i := &aiGauge{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewInt64ObservableGaugeConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64Counter(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64Counter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64Counter(name, options...)
+ }
+
i := &sfCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64CounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64UpDownCounter(name string, options ...metric.Float64UpDownCounterOption) (metric.Float64UpDownCounter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64UpDownCounter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64UpDownCounter(name, options...)
+ }
+
i := &sfUpDownCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64UpDownCounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64Histogram(name string, options ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64Histogram(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64Histogram(name, options...)
+ }
+
i := &sfHistogram{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64HistogramConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64Gauge(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64Gauge(name, options...)
+ }
+
i := &sfGauge{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64GaugeConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64ObservableCounter(name string, options ...metric.Float64ObservableCounterOption) (metric.Float64ObservableCounter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64ObservableCounter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64ObservableCounter(name, options...)
+ }
+
i := &afCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64ObservableCounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64ObservableUpDownCounter(name string, options ...metric.Float64ObservableUpDownCounterOption) (metric.Float64ObservableUpDownCounter, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64ObservableUpDownCounter(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64ObservableUpDownCounter(name, options...)
+ }
+
i := &afUpDownCounter{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64ObservableUpDownCounterConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
func (m *meter) Float64ObservableGauge(name string, options ...metric.Float64ObservableGaugeOption) (metric.Float64ObservableGauge, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- return del.Float64ObservableGauge(name, options...)
- }
m.mtx.Lock()
defer m.mtx.Unlock()
+
+ if m.delegate != nil {
+ return m.delegate.Float64ObservableGauge(name, options...)
+ }
+
i := &afGauge{name: name, opts: options}
- m.instruments = append(m.instruments, i)
+ cfg := metric.NewFloat64ObservableGaugeConfig(options...)
+ id := instID{
+ name: name,
+ kind: reflect.TypeOf(i),
+ description: cfg.Description(),
+ unit: cfg.Unit(),
+ }
+ m.instruments[id] = i
return i, nil
}
// RegisterCallback captures the function that will be called during Collect.
func (m *meter) RegisterCallback(f metric.Callback, insts ...metric.Observable) (metric.Registration, error) {
- if del, ok := m.delegate.Load().(metric.Meter); ok {
- insts = unwrapInstruments(insts)
- return del.RegisterCallback(f, insts...)
- }
-
m.mtx.Lock()
defer m.mtx.Unlock()
+ if m.delegate != nil {
+ insts = unwrapInstruments(insts)
+ return m.delegate.RegisterCallback(f, insts...)
+ }
+
reg := &registration{instruments: insts, function: f}
e := m.registry.PushBack(reg)
reg.unreg = func() error {