2020-10-17 18:48:21 +02: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.
|
|
|
|
|
2020-11-12 17:28:32 +02:00
|
|
|
package metric // import "go.opentelemetry.io/otel/metric"
|
2020-10-17 18:48:21 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
2021-02-18 19:59:37 +02:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
2020-11-11 17:24:12 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/number"
|
2021-10-14 18:06:22 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/sdkapi"
|
2020-10-17 18:48:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
|
|
|
|
var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation")
|
|
|
|
|
|
|
|
// Int64ObserverFunc is a type of callback that integral
|
|
|
|
// observers run.
|
|
|
|
type Int64ObserverFunc func(context.Context, Int64ObserverResult)
|
|
|
|
|
|
|
|
// Float64ObserverFunc is a type of callback that floating point
|
|
|
|
// observers run.
|
|
|
|
type Float64ObserverFunc func(context.Context, Float64ObserverResult)
|
|
|
|
|
|
|
|
// BatchObserverFunc is a callback argument for use with any
|
|
|
|
// Observer instrument that will be reported as a batch of
|
|
|
|
// observations.
|
|
|
|
type BatchObserverFunc func(context.Context, BatchObserverResult)
|
|
|
|
|
|
|
|
// Int64ObserverResult is passed to an observer callback to capture
|
|
|
|
// observations for one asynchronous integer metric instrument.
|
|
|
|
type Int64ObserverResult struct {
|
2021-10-14 18:06:22 +02:00
|
|
|
instrument sdkapi.AsyncImpl
|
2021-02-18 19:59:37 +02:00
|
|
|
function func([]attribute.KeyValue, ...Observation)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Float64ObserverResult is passed to an observer callback to capture
|
|
|
|
// observations for one asynchronous floating point metric instrument.
|
|
|
|
type Float64ObserverResult struct {
|
2021-10-14 18:06:22 +02:00
|
|
|
instrument sdkapi.AsyncImpl
|
2021-02-18 19:59:37 +02:00
|
|
|
function func([]attribute.KeyValue, ...Observation)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BatchObserverResult is passed to a batch observer callback to
|
|
|
|
// capture observations for multiple asynchronous instruments.
|
|
|
|
type BatchObserverResult struct {
|
2021-02-18 19:59:37 +02:00
|
|
|
function func([]attribute.KeyValue, ...Observation)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observe captures a single integer value from the associated
|
|
|
|
// instrument callback, with the given labels.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (ir Int64ObserverResult) Observe(value int64, labels ...attribute.KeyValue) {
|
2021-10-14 18:06:22 +02:00
|
|
|
ir.function(labels, sdkapi.NewObservation(ir.instrument, number.NewInt64Number(value)))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observe captures a single floating point value from the associated
|
|
|
|
// instrument callback, with the given labels.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (fr Float64ObserverResult) Observe(value float64, labels ...attribute.KeyValue) {
|
2021-10-14 18:06:22 +02:00
|
|
|
fr.function(labels, sdkapi.NewObservation(fr.instrument, number.NewFloat64Number(value)))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observe captures a multiple observations from the associated batch
|
|
|
|
// instrument callback, with the given labels.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (br BatchObserverResult) Observe(labels []attribute.KeyValue, obs ...Observation) {
|
2020-10-17 18:48:21 +02:00
|
|
|
br.function(labels, obs...)
|
|
|
|
}
|
|
|
|
|
2021-10-14 18:06:22 +02:00
|
|
|
var _ sdkapi.AsyncSingleRunner = (*Int64ObserverFunc)(nil)
|
|
|
|
var _ sdkapi.AsyncSingleRunner = (*Float64ObserverFunc)(nil)
|
|
|
|
var _ sdkapi.AsyncBatchRunner = (*BatchObserverFunc)(nil)
|
2020-10-17 18:48:21 +02:00
|
|
|
|
|
|
|
// newInt64AsyncRunner returns a single-observer callback for integer Observer instruments.
|
2021-10-14 18:06:22 +02:00
|
|
|
func newInt64AsyncRunner(c Int64ObserverFunc) sdkapi.AsyncSingleRunner {
|
2020-10-17 18:48:21 +02:00
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
|
|
|
// newFloat64AsyncRunner returns a single-observer callback for floating point Observer instruments.
|
2021-10-14 18:06:22 +02:00
|
|
|
func newFloat64AsyncRunner(c Float64ObserverFunc) sdkapi.AsyncSingleRunner {
|
2020-10-17 18:48:21 +02:00
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
|
|
|
// newBatchAsyncRunner returns a batch-observer callback use with multiple Observer instruments.
|
2021-10-14 18:06:22 +02:00
|
|
|
func newBatchAsyncRunner(c BatchObserverFunc) sdkapi.AsyncBatchRunner {
|
2020-10-17 18:48:21 +02:00
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnyRunner implements AsyncRunner.
|
|
|
|
func (*Int64ObserverFunc) AnyRunner() {}
|
|
|
|
|
|
|
|
// AnyRunner implements AsyncRunner.
|
|
|
|
func (*Float64ObserverFunc) AnyRunner() {}
|
|
|
|
|
|
|
|
// AnyRunner implements AsyncRunner.
|
|
|
|
func (*BatchObserverFunc) AnyRunner() {}
|
|
|
|
|
|
|
|
// Run implements AsyncSingleRunner.
|
2021-10-14 18:06:22 +02:00
|
|
|
func (i *Int64ObserverFunc) Run(ctx context.Context, impl sdkapi.AsyncImpl, function func([]attribute.KeyValue, ...Observation)) {
|
2020-10-17 18:48:21 +02:00
|
|
|
(*i)(ctx, Int64ObserverResult{
|
|
|
|
instrument: impl,
|
|
|
|
function: function,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run implements AsyncSingleRunner.
|
2021-10-14 18:06:22 +02:00
|
|
|
func (f *Float64ObserverFunc) Run(ctx context.Context, impl sdkapi.AsyncImpl, function func([]attribute.KeyValue, ...Observation)) {
|
2020-10-17 18:48:21 +02:00
|
|
|
(*f)(ctx, Float64ObserverResult{
|
|
|
|
instrument: impl,
|
|
|
|
function: function,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run implements AsyncBatchRunner.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]attribute.KeyValue, ...Observation)) {
|
2020-10-17 18:48:21 +02:00
|
|
|
(*b)(ctx, BatchObserverResult{
|
|
|
|
function: function,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapInt64GaugeObserverInstrument converts an AsyncImpl into Int64GaugeObserver.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapInt64GaugeObserverInstrument(asyncInst sdkapi.AsyncImpl, err error) (Int64GaugeObserver, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewAsync(asyncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Int64GaugeObserver{asyncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapFloat64GaugeObserverInstrument converts an AsyncImpl into Float64GaugeObserver.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapFloat64GaugeObserverInstrument(asyncInst sdkapi.AsyncImpl, err error) (Float64GaugeObserver, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewAsync(asyncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Float64GaugeObserver{asyncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapInt64CounterObserverInstrument converts an AsyncImpl into Int64CounterObserver.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapInt64CounterObserverInstrument(asyncInst sdkapi.AsyncImpl, err error) (Int64CounterObserver, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewAsync(asyncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Int64CounterObserver{asyncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapFloat64CounterObserverInstrument converts an AsyncImpl into Float64CounterObserver.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapFloat64CounterObserverInstrument(asyncInst sdkapi.AsyncImpl, err error) (Float64CounterObserver, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewAsync(asyncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Float64CounterObserver{asyncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapInt64UpDownCounterObserverInstrument converts an AsyncImpl into Int64UpDownCounterObserver.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapInt64UpDownCounterObserverInstrument(asyncInst sdkapi.AsyncImpl, err error) (Int64UpDownCounterObserver, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewAsync(asyncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Int64UpDownCounterObserver{asyncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapFloat64UpDownCounterObserverInstrument converts an AsyncImpl into Float64UpDownCounterObserver.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapFloat64UpDownCounterObserverInstrument(asyncInst sdkapi.AsyncImpl, err error) (Float64UpDownCounterObserver, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewAsync(asyncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Float64UpDownCounterObserver{asyncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BatchObserver represents an Observer callback that can report
|
|
|
|
// observations for multiple instruments.
|
|
|
|
type BatchObserver struct {
|
|
|
|
meter Meter
|
2021-10-14 18:06:22 +02:00
|
|
|
runner sdkapi.AsyncBatchRunner
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Int64GaugeObserver is a metric that captures a set of int64 values at a
|
2020-10-17 18:48:21 +02:00
|
|
|
// point in time.
|
2021-09-01 22:38:37 +02:00
|
|
|
type Int64GaugeObserver struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
asyncInstrument
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Float64GaugeObserver is a metric that captures a set of float64 values
|
2020-10-17 18:48:21 +02:00
|
|
|
// at a point in time.
|
2021-09-01 22:38:37 +02:00
|
|
|
type Float64GaugeObserver struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
asyncInstrument
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Int64CounterObserver is a metric that captures a precomputed sum of
|
2020-10-17 18:48:21 +02:00
|
|
|
// int64 values at a point in time.
|
2021-09-01 22:38:37 +02:00
|
|
|
type Int64CounterObserver struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
asyncInstrument
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Float64CounterObserver is a metric that captures a precomputed sum of
|
2020-10-17 18:48:21 +02:00
|
|
|
// float64 values at a point in time.
|
2021-09-01 22:38:37 +02:00
|
|
|
type Float64CounterObserver struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
asyncInstrument
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Int64UpDownCounterObserver is a metric that captures a precomputed sum of
|
2020-10-17 18:48:21 +02:00
|
|
|
// int64 values at a point in time.
|
2021-09-01 22:38:37 +02:00
|
|
|
type Int64UpDownCounterObserver struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
asyncInstrument
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Float64UpDownCounterObserver is a metric that captures a precomputed sum of
|
2020-10-17 18:48:21 +02:00
|
|
|
// float64 values at a point in time.
|
2021-09-01 22:38:37 +02:00
|
|
|
type Float64UpDownCounterObserver struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
asyncInstrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Observation returns an Observation, a BatchObserverFunc
|
|
|
|
// argument, for an asynchronous integer instrument.
|
|
|
|
// This returns an implementation-level object for use by the SDK,
|
|
|
|
// users should not refer to this.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (i Int64GaugeObserver) Observation(v int64) Observation {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewObservation(i.instrument, number.NewInt64Number(v))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observation returns an Observation, a BatchObserverFunc
|
|
|
|
// argument, for an asynchronous integer instrument.
|
|
|
|
// This returns an implementation-level object for use by the SDK,
|
|
|
|
// users should not refer to this.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (f Float64GaugeObserver) Observation(v float64) Observation {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewObservation(f.instrument, number.NewFloat64Number(v))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observation returns an Observation, a BatchObserverFunc
|
|
|
|
// argument, for an asynchronous integer instrument.
|
|
|
|
// This returns an implementation-level object for use by the SDK,
|
|
|
|
// users should not refer to this.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (i Int64CounterObserver) Observation(v int64) Observation {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewObservation(i.instrument, number.NewInt64Number(v))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observation returns an Observation, a BatchObserverFunc
|
|
|
|
// argument, for an asynchronous integer instrument.
|
|
|
|
// This returns an implementation-level object for use by the SDK,
|
|
|
|
// users should not refer to this.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (f Float64CounterObserver) Observation(v float64) Observation {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewObservation(f.instrument, number.NewFloat64Number(v))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observation returns an Observation, a BatchObserverFunc
|
|
|
|
// argument, for an asynchronous integer instrument.
|
|
|
|
// This returns an implementation-level object for use by the SDK,
|
|
|
|
// users should not refer to this.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (i Int64UpDownCounterObserver) Observation(v int64) Observation {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewObservation(i.instrument, number.NewInt64Number(v))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Observation returns an Observation, a BatchObserverFunc
|
|
|
|
// argument, for an asynchronous integer instrument.
|
|
|
|
// This returns an implementation-level object for use by the SDK,
|
|
|
|
// users should not refer to this.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (f Float64UpDownCounterObserver) Observation(v float64) Observation {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewObservation(f.instrument, number.NewFloat64Number(v))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// syncInstrument contains a SyncImpl.
|
|
|
|
type syncInstrument struct {
|
2021-10-14 18:06:22 +02:00
|
|
|
instrument sdkapi.SyncImpl
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// asyncInstrument contains a AsyncImpl.
|
|
|
|
type asyncInstrument struct {
|
2021-10-14 18:06:22 +02:00
|
|
|
instrument sdkapi.AsyncImpl
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AsyncImpl implements AsyncImpl.
|
2021-10-14 18:06:22 +02:00
|
|
|
func (a asyncInstrument) AsyncImpl() sdkapi.AsyncImpl {
|
2020-10-17 18:48:21 +02:00
|
|
|
return a.instrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncImpl returns the implementation object for synchronous instruments.
|
2021-10-14 18:06:22 +02:00
|
|
|
func (s syncInstrument) SyncImpl() sdkapi.SyncImpl {
|
2020-10-17 18:48:21 +02:00
|
|
|
return s.instrument
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s syncInstrument) float64Measurement(value float64) Measurement {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewMeasurement(s.instrument, number.NewFloat64Number(value))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s syncInstrument) int64Measurement(value int64) Measurement {
|
2021-10-14 18:06:22 +02:00
|
|
|
return sdkapi.NewMeasurement(s.instrument, number.NewInt64Number(value))
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-02-18 19:59:37 +02:00
|
|
|
func (s syncInstrument) directRecord(ctx context.Context, number number.Number, labels []attribute.KeyValue) {
|
2020-10-17 18:48:21 +02:00
|
|
|
s.instrument.RecordOne(ctx, number, labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkNewAsync receives an AsyncImpl and potential
|
|
|
|
// error, and returns the same types, checking for and ensuring that
|
|
|
|
// the returned interface is not nil.
|
2021-10-14 18:06:22 +02:00
|
|
|
func checkNewAsync(instrument sdkapi.AsyncImpl, err error) (asyncInstrument, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
if instrument == nil {
|
|
|
|
if err == nil {
|
|
|
|
err = ErrSDKReturnedNilImpl
|
|
|
|
}
|
2021-10-14 18:06:22 +02:00
|
|
|
instrument = sdkapi.NewNoopAsyncInstrument()
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
return asyncInstrument{
|
|
|
|
instrument: instrument,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkNewSync receives an SyncImpl and potential
|
|
|
|
// error, and returns the same types, checking for and ensuring that
|
|
|
|
// the returned interface is not nil.
|
2021-10-14 18:06:22 +02:00
|
|
|
func checkNewSync(instrument sdkapi.SyncImpl, err error) (syncInstrument, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
if instrument == nil {
|
|
|
|
if err == nil {
|
|
|
|
err = ErrSDKReturnedNilImpl
|
|
|
|
}
|
|
|
|
// Note: an alternate behavior would be to synthesize a new name
|
|
|
|
// or group all duplicately-named instruments of a certain type
|
|
|
|
// together and use a tag for the original name, e.g.,
|
|
|
|
// name = 'invalid.counter.int64'
|
|
|
|
// label = 'original-name=duplicate-counter-name'
|
2021-10-14 18:06:22 +02:00
|
|
|
instrument = sdkapi.NewNoopSyncInstrument()
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
return syncInstrument{
|
|
|
|
instrument: instrument,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapInt64CounterInstrument converts a SyncImpl into Int64Counter.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapInt64CounterInstrument(syncInst sdkapi.SyncImpl, err error) (Int64Counter, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewSync(syncInst, err)
|
|
|
|
return Int64Counter{syncInstrument: common}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapFloat64CounterInstrument converts a SyncImpl into Float64Counter.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapFloat64CounterInstrument(syncInst sdkapi.SyncImpl, err error) (Float64Counter, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewSync(syncInst, err)
|
|
|
|
return Float64Counter{syncInstrument: common}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapInt64UpDownCounterInstrument converts a SyncImpl into Int64UpDownCounter.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapInt64UpDownCounterInstrument(syncInst sdkapi.SyncImpl, err error) (Int64UpDownCounter, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewSync(syncInst, err)
|
|
|
|
return Int64UpDownCounter{syncInstrument: common}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapFloat64UpDownCounterInstrument converts a SyncImpl into Float64UpDownCounter.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapFloat64UpDownCounterInstrument(syncInst sdkapi.SyncImpl, err error) (Float64UpDownCounter, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewSync(syncInst, err)
|
|
|
|
return Float64UpDownCounter{syncInstrument: common}, err
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapInt64HistogramInstrument converts a SyncImpl into Int64Histogram.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapInt64HistogramInstrument(syncInst sdkapi.SyncImpl, err error) (Int64Histogram, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewSync(syncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Int64Histogram{syncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// wrapFloat64HistogramInstrument converts a SyncImpl into Float64Histogram.
|
2021-10-14 18:06:22 +02:00
|
|
|
func wrapFloat64HistogramInstrument(syncInst sdkapi.SyncImpl, err error) (Float64Histogram, error) {
|
2020-10-17 18:48:21 +02:00
|
|
|
common, err := checkNewSync(syncInst, err)
|
2021-09-01 22:38:37 +02:00
|
|
|
return Float64Histogram{syncInstrument: common}, err
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Float64Counter is a metric that accumulates float64 values.
|
|
|
|
type Float64Counter struct {
|
|
|
|
syncInstrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Int64Counter is a metric that accumulates int64 values.
|
|
|
|
type Int64Counter struct {
|
|
|
|
syncInstrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
|
|
|
func (c Float64Counter) Measurement(value float64) Measurement {
|
|
|
|
return c.float64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
|
|
|
func (c Int64Counter) Measurement(value int64) Measurement {
|
|
|
|
return c.int64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds the value to the counter's sum. The labels should contain
|
|
|
|
// the keys and values to be associated with this value.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) {
|
2020-11-11 17:24:12 +02:00
|
|
|
c.directRecord(ctx, number.NewFloat64Number(value), labels)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds the value to the counter's sum. The labels should contain
|
|
|
|
// the keys and values to be associated with this value.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) {
|
2020-11-11 17:24:12 +02:00
|
|
|
c.directRecord(ctx, number.NewInt64Number(value), labels)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Float64UpDownCounter is a metric instrument that sums floating
|
|
|
|
// point values.
|
|
|
|
type Float64UpDownCounter struct {
|
|
|
|
syncInstrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Int64UpDownCounter is a metric instrument that sums integer values.
|
|
|
|
type Int64UpDownCounter struct {
|
|
|
|
syncInstrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
|
|
|
func (c Float64UpDownCounter) Measurement(value float64) Measurement {
|
|
|
|
return c.float64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
|
|
|
func (c Int64UpDownCounter) Measurement(value int64) Measurement {
|
|
|
|
return c.int64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds the value to the counter's sum. The labels should contain
|
|
|
|
// the keys and values to be associated with this value.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) {
|
2020-11-11 17:24:12 +02:00
|
|
|
c.directRecord(ctx, number.NewFloat64Number(value), labels)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds the value to the counter's sum. The labels should contain
|
|
|
|
// the keys and values to be associated with this value.
|
2021-02-18 19:59:37 +02:00
|
|
|
func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) {
|
2020-11-11 17:24:12 +02:00
|
|
|
c.directRecord(ctx, number.NewInt64Number(value), labels)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Float64Histogram is a metric that records float64 values.
|
|
|
|
type Float64Histogram struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
syncInstrument
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Int64Histogram is a metric that records int64 values.
|
|
|
|
type Int64Histogram struct {
|
2020-10-17 18:48:21 +02:00
|
|
|
syncInstrument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (c Float64Histogram) Measurement(value float64) Measurement {
|
2020-10-17 18:48:21 +02:00
|
|
|
return c.float64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (c Int64Histogram) Measurement(value int64) Measurement {
|
2020-10-17 18:48:21 +02:00
|
|
|
return c.int64Measurement(value)
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Record adds a new value to the list of Histogram's records. The
|
2020-10-17 18:48:21 +02:00
|
|
|
// labels should contain the keys and values to be associated with
|
|
|
|
// this value.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (c Float64Histogram) Record(ctx context.Context, value float64, labels ...attribute.KeyValue) {
|
2020-11-11 17:24:12 +02:00
|
|
|
c.directRecord(ctx, number.NewFloat64Number(value), labels)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:38:37 +02:00
|
|
|
// Record adds a new value to the Histogram's distribution. The
|
2020-10-17 18:48:21 +02:00
|
|
|
// labels should contain the keys and values to be associated with
|
|
|
|
// this value.
|
2021-09-01 22:38:37 +02:00
|
|
|
func (c Int64Histogram) Record(ctx context.Context, value int64, labels ...attribute.KeyValue) {
|
2020-11-11 17:24:12 +02:00
|
|
|
c.directRecord(ctx, number.NewInt64Number(value), labels)
|
2020-10-17 18:48:21 +02:00
|
|
|
}
|