mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-31 23:58:03 +08:00
vendor: update buildkit to master@8b7bcb900d3c
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
213
vendor/go.opentelemetry.io/otel/metric/internal/global/instruments.go
generated
vendored
213
vendor/go.opentelemetry.io/otel/metric/internal/global/instruments.go
generated
vendored
@@ -22,23 +22,27 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/instrument/asyncfloat64"
|
||||
"go.opentelemetry.io/otel/metric/instrument/asyncint64"
|
||||
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
|
||||
"go.opentelemetry.io/otel/metric/instrument/syncint64"
|
||||
)
|
||||
|
||||
type afCounter struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
|
||||
delegate atomic.Value //asyncfloat64.Counter
|
||||
|
||||
instrument.Asynchronous
|
||||
// unwrapper unwraps to return the underlying instrument implementation.
|
||||
type unwrapper interface {
|
||||
Unwrap() instrument.Asynchronous
|
||||
}
|
||||
|
||||
type afCounter struct {
|
||||
instrument.Float64Observable
|
||||
|
||||
name string
|
||||
opts []instrument.Float64ObserverOption
|
||||
|
||||
delegate atomic.Value //instrument.Float64ObservableCounter
|
||||
}
|
||||
|
||||
var _ unwrapper = (*afCounter)(nil)
|
||||
var _ instrument.Float64ObservableCounter = (*afCounter)(nil)
|
||||
|
||||
func (i *afCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.AsyncFloat64().Counter(i.name, i.opts...)
|
||||
ctr, err := m.Float64ObservableCounter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -46,30 +50,27 @@ func (i *afCounter) setDelegate(m metric.Meter) {
|
||||
i.delegate.Store(ctr)
|
||||
}
|
||||
|
||||
func (i *afCounter) Observe(ctx context.Context, x float64, attrs ...attribute.KeyValue) {
|
||||
func (i *afCounter) Unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(asyncfloat64.Counter).Observe(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *afCounter) unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
return ctr.(asyncfloat64.Counter)
|
||||
return ctr.(instrument.Float64ObservableCounter)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type afUpDownCounter struct {
|
||||
instrument.Float64Observable
|
||||
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Float64ObserverOption
|
||||
|
||||
delegate atomic.Value //asyncfloat64.UpDownCounter
|
||||
|
||||
instrument.Asynchronous
|
||||
delegate atomic.Value //instrument.Float64ObservableUpDownCounter
|
||||
}
|
||||
|
||||
var _ unwrapper = (*afUpDownCounter)(nil)
|
||||
var _ instrument.Float64ObservableUpDownCounter = (*afUpDownCounter)(nil)
|
||||
|
||||
func (i *afUpDownCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.AsyncFloat64().UpDownCounter(i.name, i.opts...)
|
||||
ctr, err := m.Float64ObservableUpDownCounter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -77,30 +78,27 @@ func (i *afUpDownCounter) setDelegate(m metric.Meter) {
|
||||
i.delegate.Store(ctr)
|
||||
}
|
||||
|
||||
func (i *afUpDownCounter) Observe(ctx context.Context, x float64, attrs ...attribute.KeyValue) {
|
||||
func (i *afUpDownCounter) Unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(asyncfloat64.UpDownCounter).Observe(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *afUpDownCounter) unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
return ctr.(asyncfloat64.UpDownCounter)
|
||||
return ctr.(instrument.Float64ObservableUpDownCounter)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type afGauge struct {
|
||||
instrument.Float64Observable
|
||||
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Float64ObserverOption
|
||||
|
||||
delegate atomic.Value //asyncfloat64.Gauge
|
||||
|
||||
instrument.Asynchronous
|
||||
delegate atomic.Value //instrument.Float64ObservableGauge
|
||||
}
|
||||
|
||||
var _ unwrapper = (*afGauge)(nil)
|
||||
var _ instrument.Float64ObservableGauge = (*afGauge)(nil)
|
||||
|
||||
func (i *afGauge) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.AsyncFloat64().Gauge(i.name, i.opts...)
|
||||
ctr, err := m.Float64ObservableGauge(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -108,30 +106,27 @@ func (i *afGauge) setDelegate(m metric.Meter) {
|
||||
i.delegate.Store(ctr)
|
||||
}
|
||||
|
||||
func (i *afGauge) Observe(ctx context.Context, x float64, attrs ...attribute.KeyValue) {
|
||||
func (i *afGauge) Unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(asyncfloat64.Gauge).Observe(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *afGauge) unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
return ctr.(asyncfloat64.Gauge)
|
||||
return ctr.(instrument.Float64ObservableGauge)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type aiCounter struct {
|
||||
instrument.Int64Observable
|
||||
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Int64ObserverOption
|
||||
|
||||
delegate atomic.Value //asyncint64.Counter
|
||||
|
||||
instrument.Asynchronous
|
||||
delegate atomic.Value //instrument.Int64ObservableCounter
|
||||
}
|
||||
|
||||
var _ unwrapper = (*aiCounter)(nil)
|
||||
var _ instrument.Int64ObservableCounter = (*aiCounter)(nil)
|
||||
|
||||
func (i *aiCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.AsyncInt64().Counter(i.name, i.opts...)
|
||||
ctr, err := m.Int64ObservableCounter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -139,30 +134,27 @@ func (i *aiCounter) setDelegate(m metric.Meter) {
|
||||
i.delegate.Store(ctr)
|
||||
}
|
||||
|
||||
func (i *aiCounter) Observe(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
||||
func (i *aiCounter) Unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(asyncint64.Counter).Observe(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *aiCounter) unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
return ctr.(asyncint64.Counter)
|
||||
return ctr.(instrument.Int64ObservableCounter)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type aiUpDownCounter struct {
|
||||
instrument.Int64Observable
|
||||
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Int64ObserverOption
|
||||
|
||||
delegate atomic.Value //asyncint64.UpDownCounter
|
||||
|
||||
instrument.Asynchronous
|
||||
delegate atomic.Value //instrument.Int64ObservableUpDownCounter
|
||||
}
|
||||
|
||||
var _ unwrapper = (*aiUpDownCounter)(nil)
|
||||
var _ instrument.Int64ObservableUpDownCounter = (*aiUpDownCounter)(nil)
|
||||
|
||||
func (i *aiUpDownCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.AsyncInt64().UpDownCounter(i.name, i.opts...)
|
||||
ctr, err := m.Int64ObservableUpDownCounter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -170,30 +162,27 @@ func (i *aiUpDownCounter) setDelegate(m metric.Meter) {
|
||||
i.delegate.Store(ctr)
|
||||
}
|
||||
|
||||
func (i *aiUpDownCounter) Observe(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
||||
func (i *aiUpDownCounter) Unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(asyncint64.UpDownCounter).Observe(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *aiUpDownCounter) unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
return ctr.(asyncint64.UpDownCounter)
|
||||
return ctr.(instrument.Int64ObservableUpDownCounter)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type aiGauge struct {
|
||||
instrument.Int64Observable
|
||||
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Int64ObserverOption
|
||||
|
||||
delegate atomic.Value //asyncint64.Gauge
|
||||
|
||||
instrument.Asynchronous
|
||||
delegate atomic.Value //instrument.Int64ObservableGauge
|
||||
}
|
||||
|
||||
var _ unwrapper = (*aiGauge)(nil)
|
||||
var _ instrument.Int64ObservableGauge = (*aiGauge)(nil)
|
||||
|
||||
func (i *aiGauge) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.AsyncInt64().Gauge(i.name, i.opts...)
|
||||
ctr, err := m.Int64ObservableGauge(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -201,15 +190,9 @@ func (i *aiGauge) setDelegate(m metric.Meter) {
|
||||
i.delegate.Store(ctr)
|
||||
}
|
||||
|
||||
func (i *aiGauge) Observe(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
||||
func (i *aiGauge) Unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(asyncint64.Gauge).Observe(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *aiGauge) unwrap() instrument.Asynchronous {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
return ctr.(asyncint64.Gauge)
|
||||
return ctr.(instrument.Int64ObservableGauge)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -217,15 +200,17 @@ func (i *aiGauge) unwrap() instrument.Asynchronous {
|
||||
// Sync Instruments.
|
||||
type sfCounter struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Float64Option
|
||||
|
||||
delegate atomic.Value //syncfloat64.Counter
|
||||
delegate atomic.Value //instrument.Float64Counter
|
||||
|
||||
instrument.Synchronous
|
||||
}
|
||||
|
||||
var _ instrument.Float64Counter = (*sfCounter)(nil)
|
||||
|
||||
func (i *sfCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.SyncFloat64().Counter(i.name, i.opts...)
|
||||
ctr, err := m.Float64Counter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -235,21 +220,23 @@ func (i *sfCounter) setDelegate(m metric.Meter) {
|
||||
|
||||
func (i *sfCounter) Add(ctx context.Context, incr float64, attrs ...attribute.KeyValue) {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(syncfloat64.Counter).Add(ctx, incr, attrs...)
|
||||
ctr.(instrument.Float64Counter).Add(ctx, incr, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
type sfUpDownCounter struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Float64Option
|
||||
|
||||
delegate atomic.Value //syncfloat64.UpDownCounter
|
||||
delegate atomic.Value //instrument.Float64UpDownCounter
|
||||
|
||||
instrument.Synchronous
|
||||
}
|
||||
|
||||
var _ instrument.Float64UpDownCounter = (*sfUpDownCounter)(nil)
|
||||
|
||||
func (i *sfUpDownCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.SyncFloat64().UpDownCounter(i.name, i.opts...)
|
||||
ctr, err := m.Float64UpDownCounter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -259,21 +246,23 @@ func (i *sfUpDownCounter) setDelegate(m metric.Meter) {
|
||||
|
||||
func (i *sfUpDownCounter) Add(ctx context.Context, incr float64, attrs ...attribute.KeyValue) {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(syncfloat64.UpDownCounter).Add(ctx, incr, attrs...)
|
||||
ctr.(instrument.Float64UpDownCounter).Add(ctx, incr, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
type sfHistogram struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Float64Option
|
||||
|
||||
delegate atomic.Value //syncfloat64.Histogram
|
||||
delegate atomic.Value //instrument.Float64Histogram
|
||||
|
||||
instrument.Synchronous
|
||||
}
|
||||
|
||||
var _ instrument.Float64Histogram = (*sfHistogram)(nil)
|
||||
|
||||
func (i *sfHistogram) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.SyncFloat64().Histogram(i.name, i.opts...)
|
||||
ctr, err := m.Float64Histogram(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -283,21 +272,23 @@ func (i *sfHistogram) setDelegate(m metric.Meter) {
|
||||
|
||||
func (i *sfHistogram) Record(ctx context.Context, x float64, attrs ...attribute.KeyValue) {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(syncfloat64.Histogram).Record(ctx, x, attrs...)
|
||||
ctr.(instrument.Float64Histogram).Record(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
type siCounter struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Int64Option
|
||||
|
||||
delegate atomic.Value //syncint64.Counter
|
||||
delegate atomic.Value //instrument.Int64Counter
|
||||
|
||||
instrument.Synchronous
|
||||
}
|
||||
|
||||
var _ instrument.Int64Counter = (*siCounter)(nil)
|
||||
|
||||
func (i *siCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.SyncInt64().Counter(i.name, i.opts...)
|
||||
ctr, err := m.Int64Counter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -307,21 +298,23 @@ func (i *siCounter) setDelegate(m metric.Meter) {
|
||||
|
||||
func (i *siCounter) Add(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(syncint64.Counter).Add(ctx, x, attrs...)
|
||||
ctr.(instrument.Int64Counter).Add(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
type siUpDownCounter struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Int64Option
|
||||
|
||||
delegate atomic.Value //syncint64.UpDownCounter
|
||||
delegate atomic.Value //instrument.Int64UpDownCounter
|
||||
|
||||
instrument.Synchronous
|
||||
}
|
||||
|
||||
var _ instrument.Int64UpDownCounter = (*siUpDownCounter)(nil)
|
||||
|
||||
func (i *siUpDownCounter) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.SyncInt64().UpDownCounter(i.name, i.opts...)
|
||||
ctr, err := m.Int64UpDownCounter(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -331,21 +324,23 @@ func (i *siUpDownCounter) setDelegate(m metric.Meter) {
|
||||
|
||||
func (i *siUpDownCounter) Add(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(syncint64.UpDownCounter).Add(ctx, x, attrs...)
|
||||
ctr.(instrument.Int64UpDownCounter).Add(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
||||
type siHistogram struct {
|
||||
name string
|
||||
opts []instrument.Option
|
||||
opts []instrument.Int64Option
|
||||
|
||||
delegate atomic.Value //syncint64.Histogram
|
||||
delegate atomic.Value //instrument.Int64Histogram
|
||||
|
||||
instrument.Synchronous
|
||||
}
|
||||
|
||||
var _ instrument.Int64Histogram = (*siHistogram)(nil)
|
||||
|
||||
func (i *siHistogram) setDelegate(m metric.Meter) {
|
||||
ctr, err := m.SyncInt64().Histogram(i.name, i.opts...)
|
||||
ctr, err := m.Int64Histogram(i.name, i.opts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
return
|
||||
@@ -355,6 +350,6 @@ func (i *siHistogram) setDelegate(m metric.Meter) {
|
||||
|
||||
func (i *siHistogram) Record(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
||||
if ctr := i.delegate.Load(); ctr != nil {
|
||||
ctr.(syncint64.Histogram).Record(ctx, x, attrs...)
|
||||
ctr.(instrument.Int64Histogram).Record(ctx, x, attrs...)
|
||||
}
|
||||
}
|
||||
|
335
vendor/go.opentelemetry.io/otel/metric/internal/global/meter.go
generated
vendored
335
vendor/go.opentelemetry.io/otel/metric/internal/global/meter.go
generated
vendored
@@ -15,17 +15,13 @@
|
||||
package global // import "go.opentelemetry.io/otel/metric/internal/global"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"container/list"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/instrument/asyncfloat64"
|
||||
"go.opentelemetry.io/otel/metric/instrument/asyncint64"
|
||||
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
|
||||
"go.opentelemetry.io/otel/metric/instrument/syncint64"
|
||||
)
|
||||
|
||||
// meterProvider is a placeholder for a configured SDK MeterProvider.
|
||||
@@ -109,7 +105,8 @@ type meter struct {
|
||||
|
||||
mtx sync.Mutex
|
||||
instruments []delegatedInstrument
|
||||
callbacks []delegatedCallback
|
||||
|
||||
registry list.List
|
||||
|
||||
delegate atomic.Value // metric.Meter
|
||||
}
|
||||
@@ -135,52 +132,167 @@ func (m *meter) setDelegate(provider metric.MeterProvider) {
|
||||
inst.setDelegate(meter)
|
||||
}
|
||||
|
||||
for _, callback := range m.callbacks {
|
||||
callback.setDelegate(meter)
|
||||
for e := m.registry.Front(); e != nil; e = e.Next() {
|
||||
r := e.Value.(*registration)
|
||||
r.setDelegate(meter)
|
||||
m.registry.Remove(e)
|
||||
}
|
||||
|
||||
m.instruments = nil
|
||||
m.callbacks = nil
|
||||
m.registry.Init()
|
||||
}
|
||||
|
||||
// AsyncInt64 is the namespace for the Asynchronous Integer instruments.
|
||||
//
|
||||
// To Observe data with instruments it must be registered in a callback.
|
||||
func (m *meter) AsyncInt64() asyncint64.InstrumentProvider {
|
||||
func (m *meter) Int64Counter(name string, options ...instrument.Int64Option) (instrument.Int64Counter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.AsyncInt64()
|
||||
return del.Int64Counter(name, options...)
|
||||
}
|
||||
return (*aiInstProvider)(m)
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &siCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// AsyncFloat64 is the namespace for the Asynchronous Float instruments.
|
||||
//
|
||||
// To Observe data with instruments it must be registered in a callback.
|
||||
func (m *meter) AsyncFloat64() asyncfloat64.InstrumentProvider {
|
||||
func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64Option) (instrument.Int64UpDownCounter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.AsyncFloat64()
|
||||
return del.Int64UpDownCounter(name, options...)
|
||||
}
|
||||
return (*afInstProvider)(m)
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &siUpDownCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Int64Histogram(name string, options ...instrument.Int64Option) (instrument.Int64Histogram, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Int64Histogram(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &siHistogram{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableCounter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Int64ObservableCounter(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &aiCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableUpDownCounter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Int64ObservableUpDownCounter(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &aiUpDownCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableGauge, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Int64ObservableGauge(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &aiGauge{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Float64Counter(name string, options ...instrument.Float64Option) (instrument.Float64Counter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Float64Counter(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &sfCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64Option) (instrument.Float64UpDownCounter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Float64UpDownCounter(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &sfUpDownCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Float64Histogram(name string, options ...instrument.Float64Option) (instrument.Float64Histogram, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Float64Histogram(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &sfHistogram{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Float64ObservableCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableCounter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Float64ObservableCounter(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &afCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableUpDownCounter, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Float64ObservableUpDownCounter(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &afUpDownCounter{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *meter) Float64ObservableGauge(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableGauge, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.Float64ObservableGauge(name, options...)
|
||||
}
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
i := &afGauge{name: name, opts: options}
|
||||
m.instruments = append(m.instruments, i)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// RegisterCallback captures the function that will be called during Collect.
|
||||
//
|
||||
// It is only valid to call Observe within the scope of the passed function,
|
||||
// and only on the instruments that were registered with this call.
|
||||
func (m *meter) RegisterCallback(insts []instrument.Asynchronous, function func(context.Context)) error {
|
||||
func (m *meter) RegisterCallback(f metric.Callback, insts ...instrument.Asynchronous) (metric.Registration, error) {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
insts = unwrapInstruments(insts)
|
||||
return del.RegisterCallback(insts, function)
|
||||
return del.RegisterCallback(f, insts...)
|
||||
}
|
||||
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
m.callbacks = append(m.callbacks, delegatedCallback{
|
||||
instruments: insts,
|
||||
function: function,
|
||||
})
|
||||
|
||||
return nil
|
||||
reg := ®istration{instruments: insts, function: f}
|
||||
e := m.registry.PushBack(reg)
|
||||
reg.unreg = func() error {
|
||||
m.mtx.Lock()
|
||||
_ = m.registry.Remove(e)
|
||||
m.mtx.Unlock()
|
||||
return nil
|
||||
}
|
||||
return reg, nil
|
||||
}
|
||||
|
||||
type wrapped interface {
|
||||
@@ -201,147 +313,42 @@ func unwrapInstruments(instruments []instrument.Asynchronous) []instrument.Async
|
||||
return out
|
||||
}
|
||||
|
||||
// SyncInt64 is the namespace for the Synchronous Integer instruments.
|
||||
func (m *meter) SyncInt64() syncint64.InstrumentProvider {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.SyncInt64()
|
||||
}
|
||||
return (*siInstProvider)(m)
|
||||
}
|
||||
|
||||
// SyncFloat64 is the namespace for the Synchronous Float instruments.
|
||||
func (m *meter) SyncFloat64() syncfloat64.InstrumentProvider {
|
||||
if del, ok := m.delegate.Load().(metric.Meter); ok {
|
||||
return del.SyncFloat64()
|
||||
}
|
||||
return (*sfInstProvider)(m)
|
||||
}
|
||||
|
||||
type delegatedCallback struct {
|
||||
type registration struct {
|
||||
instruments []instrument.Asynchronous
|
||||
function func(context.Context)
|
||||
function metric.Callback
|
||||
|
||||
unreg func() error
|
||||
unregMu sync.Mutex
|
||||
}
|
||||
|
||||
func (c *delegatedCallback) setDelegate(m metric.Meter) {
|
||||
func (c *registration) setDelegate(m metric.Meter) {
|
||||
insts := unwrapInstruments(c.instruments)
|
||||
err := m.RegisterCallback(insts, c.function)
|
||||
|
||||
c.unregMu.Lock()
|
||||
defer c.unregMu.Unlock()
|
||||
|
||||
if c.unreg == nil {
|
||||
// Unregister already called.
|
||||
return
|
||||
}
|
||||
|
||||
reg, err := m.RegisterCallback(c.function, insts...)
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
}
|
||||
|
||||
c.unreg = reg.Unregister
|
||||
}
|
||||
|
||||
type afInstProvider meter
|
||||
func (c *registration) Unregister() error {
|
||||
c.unregMu.Lock()
|
||||
defer c.unregMu.Unlock()
|
||||
if c.unreg == nil {
|
||||
// Unregister already called.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Counter creates an instrument for recording increasing values.
|
||||
func (ip *afInstProvider) Counter(name string, opts ...instrument.Option) (asyncfloat64.Counter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &afCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// UpDownCounter creates an instrument for recording changes of a value.
|
||||
func (ip *afInstProvider) UpDownCounter(name string, opts ...instrument.Option) (asyncfloat64.UpDownCounter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &afUpDownCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// Gauge creates an instrument for recording the current value.
|
||||
func (ip *afInstProvider) Gauge(name string, opts ...instrument.Option) (asyncfloat64.Gauge, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &afGauge{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
type aiInstProvider meter
|
||||
|
||||
// Counter creates an instrument for recording increasing values.
|
||||
func (ip *aiInstProvider) Counter(name string, opts ...instrument.Option) (asyncint64.Counter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &aiCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// UpDownCounter creates an instrument for recording changes of a value.
|
||||
func (ip *aiInstProvider) UpDownCounter(name string, opts ...instrument.Option) (asyncint64.UpDownCounter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &aiUpDownCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// Gauge creates an instrument for recording the current value.
|
||||
func (ip *aiInstProvider) Gauge(name string, opts ...instrument.Option) (asyncint64.Gauge, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &aiGauge{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
type sfInstProvider meter
|
||||
|
||||
// Counter creates an instrument for recording increasing values.
|
||||
func (ip *sfInstProvider) Counter(name string, opts ...instrument.Option) (syncfloat64.Counter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &sfCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// UpDownCounter creates an instrument for recording changes of a value.
|
||||
func (ip *sfInstProvider) UpDownCounter(name string, opts ...instrument.Option) (syncfloat64.UpDownCounter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &sfUpDownCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// Histogram creates an instrument for recording a distribution of values.
|
||||
func (ip *sfInstProvider) Histogram(name string, opts ...instrument.Option) (syncfloat64.Histogram, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &sfHistogram{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
type siInstProvider meter
|
||||
|
||||
// Counter creates an instrument for recording increasing values.
|
||||
func (ip *siInstProvider) Counter(name string, opts ...instrument.Option) (syncint64.Counter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &siCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// UpDownCounter creates an instrument for recording changes of a value.
|
||||
func (ip *siInstProvider) UpDownCounter(name string, opts ...instrument.Option) (syncint64.UpDownCounter, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &siUpDownCounter{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
// Histogram creates an instrument for recording a distribution of values.
|
||||
func (ip *siInstProvider) Histogram(name string, opts ...instrument.Option) (syncint64.Histogram, error) {
|
||||
ip.mtx.Lock()
|
||||
defer ip.mtx.Unlock()
|
||||
ctr := &siHistogram{name: name, opts: opts}
|
||||
ip.instruments = append(ip.instruments, ctr)
|
||||
return ctr, nil
|
||||
var err error
|
||||
err, c.unreg = c.unreg(), nil
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user