2023-05-09 17:19:48 +00:00
|
|
|
// Copyright The OpenTelemetry Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package global // import "go.opentelemetry.io/otel/metric/internal/global"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel"
|
2023-05-12 12:55:18 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
2023-05-09 17:19:48 +00:00
|
|
|
"go.opentelemetry.io/otel/metric"
|
2023-05-12 12:55:18 +00:00
|
|
|
"go.opentelemetry.io/otel/metric/instrument"
|
2023-05-09 17:19:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// unwrapper unwraps to return the underlying instrument implementation.
|
|
|
|
type unwrapper interface {
|
2023-05-12 12:55:18 +00:00
|
|
|
Unwrap() instrument.Asynchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type afCounter struct {
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Float64Observable
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Float64ObserverOption
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Float64ObservableCounter
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ unwrapper = (*afCounter)(nil)
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Float64ObservableCounter = (*afCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *afCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Float64ObservableCounter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *afCounter) Unwrap() instrument.Asynchronous {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
return ctr.(instrument.Float64ObservableCounter)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type afUpDownCounter struct {
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Float64Observable
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Float64ObserverOption
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Float64ObservableUpDownCounter
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ unwrapper = (*afUpDownCounter)(nil)
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Float64ObservableUpDownCounter = (*afUpDownCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *afUpDownCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Float64ObservableUpDownCounter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *afUpDownCounter) Unwrap() instrument.Asynchronous {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
return ctr.(instrument.Float64ObservableUpDownCounter)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type afGauge struct {
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Float64Observable
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Float64ObserverOption
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Float64ObservableGauge
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ unwrapper = (*afGauge)(nil)
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Float64ObservableGauge = (*afGauge)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *afGauge) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Float64ObservableGauge(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *afGauge) Unwrap() instrument.Asynchronous {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
return ctr.(instrument.Float64ObservableGauge)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type aiCounter struct {
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Int64Observable
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Int64ObserverOption
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Int64ObservableCounter
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ unwrapper = (*aiCounter)(nil)
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Int64ObservableCounter = (*aiCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *aiCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Int64ObservableCounter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *aiCounter) Unwrap() instrument.Asynchronous {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
return ctr.(instrument.Int64ObservableCounter)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type aiUpDownCounter struct {
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Int64Observable
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Int64ObserverOption
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Int64ObservableUpDownCounter
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ unwrapper = (*aiUpDownCounter)(nil)
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Int64ObservableUpDownCounter = (*aiUpDownCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *aiUpDownCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Int64ObservableUpDownCounter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *aiUpDownCounter) Unwrap() instrument.Asynchronous {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
return ctr.(instrument.Int64ObservableUpDownCounter)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type aiGauge struct {
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Int64Observable
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Int64ObserverOption
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Int64ObservableGauge
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ unwrapper = (*aiGauge)(nil)
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Int64ObservableGauge = (*aiGauge)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *aiGauge) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Int64ObservableGauge(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *aiGauge) Unwrap() instrument.Asynchronous {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
return ctr.(instrument.Int64ObservableGauge)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync Instruments.
|
|
|
|
type sfCounter struct {
|
2023-05-12 12:33:40 +00:00
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Float64Option
|
|
|
|
|
|
|
|
delegate atomic.Value //instrument.Float64Counter
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Synchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Float64Counter = (*sfCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *sfCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Float64Counter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *sfCounter) Add(ctx context.Context, incr float64, attrs ...attribute.KeyValue) {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
ctr.(instrument.Float64Counter).Add(ctx, incr, attrs...)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type sfUpDownCounter struct {
|
2023-05-12 12:33:40 +00:00
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Float64Option
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Float64UpDownCounter
|
|
|
|
|
|
|
|
instrument.Synchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Float64UpDownCounter = (*sfUpDownCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *sfUpDownCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Float64UpDownCounter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *sfUpDownCounter) Add(ctx context.Context, incr float64, attrs ...attribute.KeyValue) {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
ctr.(instrument.Float64UpDownCounter).Add(ctx, incr, attrs...)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type sfHistogram struct {
|
2023-05-12 12:33:40 +00:00
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Float64Option
|
|
|
|
|
|
|
|
delegate atomic.Value //instrument.Float64Histogram
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Synchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Float64Histogram = (*sfHistogram)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *sfHistogram) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Float64Histogram(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *sfHistogram) Record(ctx context.Context, x float64, attrs ...attribute.KeyValue) {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
ctr.(instrument.Float64Histogram).Record(ctx, x, attrs...)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type siCounter struct {
|
2023-05-12 12:33:40 +00:00
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Int64Option
|
|
|
|
|
|
|
|
delegate atomic.Value //instrument.Int64Counter
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Synchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Int64Counter = (*siCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *siCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Int64Counter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *siCounter) Add(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
ctr.(instrument.Int64Counter).Add(ctx, x, attrs...)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type siUpDownCounter struct {
|
2023-05-12 12:33:40 +00:00
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Int64Option
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
delegate atomic.Value //instrument.Int64UpDownCounter
|
|
|
|
|
|
|
|
instrument.Synchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Int64UpDownCounter = (*siUpDownCounter)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *siUpDownCounter) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Int64UpDownCounter(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *siUpDownCounter) Add(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
ctr.(instrument.Int64UpDownCounter).Add(ctx, x, attrs...)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type siHistogram struct {
|
2023-05-12 12:33:40 +00:00
|
|
|
name string
|
2023-05-12 12:55:18 +00:00
|
|
|
opts []instrument.Int64Option
|
|
|
|
|
|
|
|
delegate atomic.Value //instrument.Int64Histogram
|
2023-05-09 17:19:48 +00:00
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
instrument.Synchronous
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
var _ instrument.Int64Histogram = (*siHistogram)(nil)
|
2023-05-09 17:19:48 +00:00
|
|
|
|
|
|
|
func (i *siHistogram) setDelegate(m metric.Meter) {
|
|
|
|
ctr, err := m.Int64Histogram(i.name, i.opts...)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
i.delegate.Store(ctr)
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:55:18 +00:00
|
|
|
func (i *siHistogram) Record(ctx context.Context, x int64, attrs ...attribute.KeyValue) {
|
2023-05-09 17:19:48 +00:00
|
|
|
if ctr := i.delegate.Load(); ctr != nil {
|
2023-05-12 12:55:18 +00:00
|
|
|
ctr.(instrument.Int64Histogram).Record(ctx, x, attrs...)
|
2023-05-09 17:19:48 +00:00
|
|
|
}
|
|
|
|
}
|