package metric

import "go.opentelemetry.io/otel/api/metric"

metric package provides an API for reporting diagnostic measurements using four basic kinds of instruments.

The three basic kinds are:

- counters - measures - observers

All instruments report either float64 or int64 values.

The primary object that handles metrics is Meter. Meter can be obtained from Provider. The implementations of the Meter and Provider are provided by SDK. Normally, the Meter is used directly only for the instrument creation and batch recording.

Counters are instruments that are reporting a quantity or a sum. An example could be bank account balance or bytes downloaded. Counters can be created with either NewFloat64Counter or NewInt64Counter. Counters expect non-negative values by default to be reported. This can be changed with the WithMonotonic option (passing false as a parameter) passed to the Meter.New*Counter function - this allows reporting negative values. To report the new value, use an Add function.

Measures are instruments that are reporting values that are recorded separately to figure out some statistical properties from those values (like average). An example could be temperature over time or lines of code in the project over time. Measures can be created with either NewFloat64Measure or NewInt64Measure. Measures by default take only non-negative values. This can be changed with the WithAbsolute option (passing false as a parameter) passed to the New*Measure function - this allows reporting negative values too. To report a new value, use the Record function.

Observers are instruments that are reporting a current state of a set of values. An example could be voltage or temperature. Observers can be created with either RegisterFloat64Observer or RegisterInt64Observer. Observers by default have no limitations about reported values - they can be less or greater than the last reported value. This can be changed with the WithMonotonic option passed to the Register*Observer function - this permits the reported values only to go up. Reporting of the new values happens asynchronously, with the use of a callback passed to the Register*Observer function. The callback can report multiple values. There is no unregister function.

Counters and measures support creating bound instruments for a potentially more efficient reporting. The bound instruments have the same function names as the instruments (so a Counter bound instrument has Add, and a Measure bound instrument has Record). Bound Instruments can be created with the Bind function of the respective instrument. When done with the bound instrument, call Unbind on it.

Index

Variables

var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation")

Types

type AsyncBatchRunner

type AsyncBatchRunner interface {
	// Run accepts a function for capturing observations of
	// multiple instruments.
	Run(capture func([]kv.KeyValue, ...Observation))

	AsyncRunner
}

AsyncBatchRunner is an interface implemented by batch-observer callbacks.

type AsyncImpl

type AsyncImpl interface {
	InstrumentImpl
}

AsyncImpl is an implementation-level interface to an asynchronous instrument (e.g., Observer instruments).

type AsyncRunner

type AsyncRunner interface {
	// contains filtered or unexported methods
}

AsyncRunner is expected to convert into an AsyncSingleRunner or an AsyncBatchRunner. SDKs will encounter an error if the AsyncRunner does not satisfy one of these interfaces.

type AsyncSingleRunner

type AsyncSingleRunner interface {
	// Run accepts a single instrument and function for capturing
	// observations of that instrument.  Each call to the function
	// receives one captured observation.  (The function accepts
	// multiple observations so the same implementation can be
	// used for batch runners.)
	Run(single AsyncImpl, capture func([]kv.KeyValue, ...Observation))

	AsyncRunner
}

AsyncSingleRunner is an interface implemented by single-observer callbacks.

type BatchObserver

type BatchObserver struct {
	// contains filtered or unexported fields
}

BatchObserver represents an Observer callback that can report observations for multiple instruments.

func (BatchObserver) RegisterFloat64Observer

func (b BatchObserver) RegisterFloat64Observer(name string, opts ...Option) (Float64Observer, error)

RegisterFloat64Observer creates a new floating point Observer with the given name, running in a batch callback, and customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

func (BatchObserver) RegisterInt64Observer

func (b BatchObserver) RegisterInt64Observer(name string, opts ...Option) (Int64Observer, error)

RegisterInt64Observer creates a new integer Observer instrument with the given name, running in a batch callback, and customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

type BatchObserverCallback

type BatchObserverCallback func(BatchObserverResult)

BatchObserverCallback is a callback argument for use with any Observer instrument that will be reported as a batch of observations.

func (*BatchObserverCallback) Run

func (b *BatchObserverCallback) Run(function func([]kv.KeyValue, ...Observation))

Run implements AsyncBatchRunner.

type BatchObserverMust

type BatchObserverMust struct {
	// contains filtered or unexported fields
}

BatchObserverMust is a wrapper for BatchObserver that panics when any instrument constructor encounters an error.

func (BatchObserverMust) RegisterFloat64Observer

func (bm BatchObserverMust) RegisterFloat64Observer(name string, oos ...Option) Float64Observer

RegisterFloat64Observer calls `BatchObserver.RegisterFloat64Observer` and returns the instrument, panicking if it encounters an error.

func (BatchObserverMust) RegisterInt64Observer

func (bm BatchObserverMust) RegisterInt64Observer(name string, oos ...Option) Int64Observer

RegisterInt64Observer calls `BatchObserver.RegisterInt64Observer` and returns the instrument, panicking if it encounters an error.

type BatchObserverResult

type BatchObserverResult struct {
	// contains filtered or unexported fields
}

BatchObserverResult is passed to a batch observer callback to capture observations for multiple asynchronous instruments.

func (BatchObserverResult) Observe

func (br BatchObserverResult) Observe(labels []kv.KeyValue, obs ...Observation)

Observe captures a multiple observations from the associated batch instrument callback, with the given labels.

type BoundFloat64Counter

type BoundFloat64Counter struct {
	// contains filtered or unexported fields
}

BoundFloat64Counter is a bound instrument for Float64Counter.

It inherits the Unbind function from syncBoundInstrument.

func (BoundFloat64Counter) Add

func (b BoundFloat64Counter) Add(ctx context.Context, value float64)

Add adds the value to the counter's sum using the labels previously bound to this counter via Bind()

func (BoundFloat64Counter) Unbind

func (h BoundFloat64Counter) Unbind()

type BoundFloat64Measure

type BoundFloat64Measure struct {
	// contains filtered or unexported fields
}

BoundFloat64Measure is a bound instrument for Float64Measure.

It inherits the Unbind function from syncBoundInstrument.

func (BoundFloat64Measure) Record

func (b BoundFloat64Measure) Record(ctx context.Context, value float64)

Record adds a new value to the list of measure's records using the labels previously bound to the measure via Bind()

func (BoundFloat64Measure) Unbind

func (h BoundFloat64Measure) Unbind()

type BoundInt64Counter

type BoundInt64Counter struct {
	// contains filtered or unexported fields
}

BoundInt64Counter is a boundInstrument for Int64Counter.

It inherits the Unbind function from syncBoundInstrument.

func (BoundInt64Counter) Add

func (b BoundInt64Counter) Add(ctx context.Context, value int64)

Add adds the value to the counter's sum using the labels previously bound to this counter via Bind()

func (BoundInt64Counter) Unbind

func (h BoundInt64Counter) Unbind()

type BoundInt64Measure

type BoundInt64Measure struct {
	// contains filtered or unexported fields
}

BoundInt64Measure is a bound instrument for Int64Measure.

It inherits the Unbind function from syncBoundInstrument.

func (BoundInt64Measure) Record

func (b BoundInt64Measure) Record(ctx context.Context, value int64)

Record adds a new value to the list of measure's records using the labels previously bound to the measure via Bind()

func (BoundInt64Measure) Unbind

func (h BoundInt64Measure) Unbind()

type BoundSyncImpl

type BoundSyncImpl interface {

	// RecordOne captures a single synchronous metric event.
	RecordOne(ctx context.Context, number Number)

	// Unbind frees the resources associated with this bound instrument. It
	// does not affect the metric this bound instrument was created through.
	Unbind()
}

BoundSyncImpl is the implementation-level interface to a generic bound synchronous instrument

type Config

type Config struct {
	// Description is an optional field describing the metric
	// instrument.
	Description string
	// Unit is an optional field describing the metric instrument.
	Unit unit.Unit
	// LibraryName is the name given to the Meter that created
	// this instrument.  See `Provider`.
	LibraryName string
}

Config contains some options for metrics of any kind.

func Configure

func Configure(opts []Option) Config

Configure is a helper that applies all the options to a Config.

type Descriptor

type Descriptor struct {
	// contains filtered or unexported fields
}

Descriptor contains all the settings that describe an instrument, including its name, metric kind, number kind, and the configurable options.

func NewDescriptor

func NewDescriptor(name string, mkind Kind, nkind NumberKind, opts ...Option) Descriptor

NewDescriptor returns a Descriptor with the given contents.

func (Descriptor) Description

func (d Descriptor) Description() string

Description provides a human-readable description of the metric instrument.

func (Descriptor) LibraryName

func (d Descriptor) LibraryName() string

LibraryName returns the metric instrument's library name, typically given via a call to Provider.Meter().

func (Descriptor) MetricKind

func (d Descriptor) MetricKind() Kind

MetricKind returns the specific kind of instrument.

func (Descriptor) Name

func (d Descriptor) Name() string

Name returns the metric instrument's name.

func (Descriptor) NumberKind

func (d Descriptor) NumberKind() NumberKind

NumberKind returns whether this instrument is declared over int64, float64, or uint64 values.

func (Descriptor) Unit

func (d Descriptor) Unit() unit.Unit

Unit describes the units of the metric instrument. Unitless metrics return the empty string.

type Float64Counter

type Float64Counter struct {
	// contains filtered or unexported fields
}

Float64Counter is a metric that accumulates float64 values.

func (Float64Counter) Add

func (c Float64Counter) Add(ctx context.Context, value float64, labels ...kv.KeyValue)

Add adds the value to the counter's sum. The labels should contain the keys and values to be associated with this value.

func (Float64Counter) Bind

func (c Float64Counter) Bind(labels ...kv.KeyValue) (h BoundFloat64Counter)

Bind creates a bound instrument for this counter. The labels are associated with values recorded via subsequent calls to Record.

func (Float64Counter) Measurement

func (c Float64Counter) Measurement(value float64) Measurement

Measurement creates a Measurement object to use with batch recording.

func (Float64Counter) SyncImpl

func (s Float64Counter) SyncImpl() SyncImpl

type Float64Measure

type Float64Measure struct {
	// contains filtered or unexported fields
}

Float64Measure is a metric that records float64 values.

func (Float64Measure) Bind

func (c Float64Measure) Bind(labels ...kv.KeyValue) (h BoundFloat64Measure)

Bind creates a bound instrument for this measure. The labels are associated with values recorded via subsequent calls to Record.

func (Float64Measure) Measurement

func (c Float64Measure) Measurement(value float64) Measurement

Measurement creates a Measurement object to use with batch recording.

func (Float64Measure) Record

func (c Float64Measure) Record(ctx context.Context, value float64, labels ...kv.KeyValue)

Record adds a new value to the list of measure's records. The labels should contain the keys and values to be associated with this value.

func (Float64Measure) SyncImpl

func (s Float64Measure) SyncImpl() SyncImpl

type Float64Observer

type Float64Observer struct {
	// contains filtered or unexported fields
}

Float64Observer is a metric that captures a set of float64 values at a point in time.

func (Float64Observer) AsyncImpl

func (a Float64Observer) AsyncImpl() AsyncImpl

func (Float64Observer) Observation

func (f Float64Observer) Observation(v float64) Observation

Observation returns an Observation, a BatchObserverCallback argument, for an asynchronous integer instrument. This returns an implementation-level object for use by the SDK, users should not refer to this.

type Float64ObserverCallback

type Float64ObserverCallback func(Float64ObserverResult)

Float64ObserverCallback is a type of callback that floating point observers run.

func (*Float64ObserverCallback) Run

func (f *Float64ObserverCallback) Run(impl AsyncImpl, function func([]kv.KeyValue, ...Observation))

Run implements AsyncSingleRunner.

type Float64ObserverResult

type Float64ObserverResult struct {
	// contains filtered or unexported fields
}

Float64ObserverResult is passed to an observer callback to capture observations for one asynchronous floating point metric instrument.

func (Float64ObserverResult) Observe

func (fr Float64ObserverResult) Observe(value float64, labels ...kv.KeyValue)

Observe captures a single floating point value from the associated instrument callback, with the given labels.

type InstrumentImpl

type InstrumentImpl interface {
	// Implementation returns the underlying implementation of the
	// instrument, which allows the implementation to gain access
	// to its own representation especially from a `Measurement`.
	Implementation() interface{}

	// Descriptor returns a copy of the instrument's Descriptor.
	Descriptor() Descriptor
}

InstrumentImpl is a common interface for synchronous and asynchronous instruments.

type Int64Counter

type Int64Counter struct {
	// contains filtered or unexported fields
}

Int64Counter is a metric that accumulates int64 values.

func (Int64Counter) Add

func (c Int64Counter) Add(ctx context.Context, value int64, labels ...kv.KeyValue)

Add adds the value to the counter's sum. The labels should contain the keys and values to be associated with this value.

func (Int64Counter) Bind

func (c Int64Counter) Bind(labels ...kv.KeyValue) (h BoundInt64Counter)

Bind creates a bound instrument for this counter. The labels are associated with values recorded via subsequent calls to Record.

func (Int64Counter) Measurement

func (c Int64Counter) Measurement(value int64) Measurement

Measurement creates a Measurement object to use with batch recording.

func (Int64Counter) SyncImpl

func (s Int64Counter) SyncImpl() SyncImpl

type Int64Measure

type Int64Measure struct {
	// contains filtered or unexported fields
}

Int64Measure is a metric that records int64 values.

func (Int64Measure) Bind

func (c Int64Measure) Bind(labels ...kv.KeyValue) (h BoundInt64Measure)

Bind creates a bound instrument for this measure. The labels are associated with values recorded via subsequent calls to Record.

func (Int64Measure) Measurement

func (c Int64Measure) Measurement(value int64) Measurement

Measurement creates a Measurement object to use with batch recording.

func (Int64Measure) Record

func (c Int64Measure) Record(ctx context.Context, value int64, labels ...kv.KeyValue)

Record adds a new value to the list of measure's records. The labels should contain the keys and values to be associated with this value.

func (Int64Measure) SyncImpl

func (s Int64Measure) SyncImpl() SyncImpl

type Int64Observer

type Int64Observer struct {
	// contains filtered or unexported fields
}

Int64Observer is a metric that captures a set of int64 values at a point in time.

func (Int64Observer) AsyncImpl

func (a Int64Observer) AsyncImpl() AsyncImpl

func (Int64Observer) Observation

func (i Int64Observer) Observation(v int64) Observation

Observation returns an Observation, a BatchObserverCallback argument, for an asynchronous integer instrument. This returns an implementation-level object for use by the SDK, users should not refer to this.

type Int64ObserverCallback

type Int64ObserverCallback func(Int64ObserverResult)

Int64ObserverCallback is a type of callback that integral observers run.

func (*Int64ObserverCallback) Run

func (i *Int64ObserverCallback) Run(impl AsyncImpl, function func([]kv.KeyValue, ...Observation))

Run implements AsyncSingleRunner.

type Int64ObserverResult

type Int64ObserverResult struct {
	// contains filtered or unexported fields
}

Int64ObserverResult is passed to an observer callback to capture observations for one asynchronous integer metric instrument.

func (Int64ObserverResult) Observe

func (ir Int64ObserverResult) Observe(value int64, labels ...kv.KeyValue)

Observe captures a single integer value from the associated instrument callback, with the given labels.

type Kind

type Kind int8

Kind describes the kind of instrument.

const (
	// MeasureKind indicates a Measure instrument.
	MeasureKind Kind = iota
	// ObserverKind indicates an Observer instrument.
	ObserverKind
	// CounterKind indicates a Counter instrument.
	CounterKind
)

func (Kind) String

func (i Kind) String() string

type Measurement

type Measurement struct {
	// contains filtered or unexported fields
}

Measurement is used for reporting a batch of metric values. Instances of this type should be created by instruments (e.g., Int64Counter.Measurement()).

func (Measurement) Number

func (m Measurement) Number() Number

Number returns a number recorded in this measurement.

func (Measurement) SyncImpl

func (m Measurement) SyncImpl() SyncImpl

SyncImpl returns the instrument that created this measurement. This returns an implementation-level object for use by the SDK, users should not refer to this.

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

Meter is the OpenTelemetry metric API, based on a `MeterImpl` implementation and the `Meter` library name.

An uninitialized Meter is a no-op implementation.

func WrapMeterImpl

func WrapMeterImpl(impl MeterImpl, libraryName string) Meter

WrapMeterImpl constructs a `Meter` implementation from a `MeterImpl` implementation.

func (Meter) MeterImpl

func (m Meter) MeterImpl() MeterImpl

MeterImpl returns the underlying MeterImpl of this Meter.

func (Meter) NewBatchObserver

func (m Meter) NewBatchObserver(callback BatchObserverCallback) BatchObserver

NewBatchObserver creates a new BatchObserver that supports making batches of observations for multiple instruments.

func (Meter) NewFloat64Counter

func (m Meter) NewFloat64Counter(name string, options ...Option) (Float64Counter, error)

NewFloat64Counter creates a new floating point Counter with the given name, customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

func (Meter) NewFloat64Measure

func (m Meter) NewFloat64Measure(name string, opts ...Option) (Float64Measure, error)

NewFloat64Measure creates a new floating point Measure with the given name, customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

func (Meter) NewInt64Counter

func (m Meter) NewInt64Counter(name string, options ...Option) (Int64Counter, error)

NewInt64Counter creates a new integer Counter instrument with the given name, customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

func (Meter) NewInt64Measure

func (m Meter) NewInt64Measure(name string, opts ...Option) (Int64Measure, error)

NewInt64Measure creates a new integer Measure instrument with the given name, customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

func (Meter) RecordBatch

func (m Meter) RecordBatch(ctx context.Context, ls []kv.KeyValue, ms ...Measurement)

RecordBatch atomically records a batch of measurements.

func (Meter) RegisterFloat64Observer

func (m Meter) RegisterFloat64Observer(name string, callback Float64ObserverCallback, opts ...Option) (Float64Observer, error)

RegisterFloat64Observer creates a new floating point Observer with the given name, running a given callback, and customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

func (Meter) RegisterInt64Observer

func (m Meter) RegisterInt64Observer(name string, callback Int64ObserverCallback, opts ...Option) (Int64Observer, error)

RegisterInt64Observer creates a new integer Observer instrument with the given name, running a given callback, and customized with options. May return an error if the name is invalid (e.g., empty) or improperly registered (e.g., duplicate registration).

type MeterImpl

type MeterImpl interface {
	// RecordBatch atomically records a batch of measurements.
	RecordBatch(context.Context, []kv.KeyValue, ...Measurement)

	// NewSyncInstrument returns a newly constructed
	// synchronous instrument implementation or an error, should
	// one occur.
	NewSyncInstrument(descriptor Descriptor) (SyncImpl, error)

	// NewAsyncInstrument returns a newly constructed
	// asynchronous instrument implementation or an error, should
	// one occur.
	NewAsyncInstrument(
		descriptor Descriptor,
		runner AsyncRunner,
	) (AsyncImpl, error)
}

MeterImpl is the interface an SDK must implement to supply a Meter implementation.

type MeterMust

type MeterMust struct {
	// contains filtered or unexported fields
}

MeterMust is a wrapper for Meter interfaces that panics when any instrument constructor encounters an error.

func Must

func Must(meter Meter) MeterMust

Must constructs a MeterMust implementation from a Meter, allowing the application to panic when any instrument constructor yields an error.

func (MeterMust) NewBatchObserver

func (mm MeterMust) NewBatchObserver(callback BatchObserverCallback) BatchObserverMust

NewBatchObserver returns a wrapper around BatchObserver that panics when any instrument constructor returns an error.

func (MeterMust) NewFloat64Counter

func (mm MeterMust) NewFloat64Counter(name string, cos ...Option) Float64Counter

NewFloat64Counter calls `Meter.NewFloat64Counter` and returns the instrument, panicking if it encounters an error.

func (MeterMust) NewFloat64Measure

func (mm MeterMust) NewFloat64Measure(name string, mos ...Option) Float64Measure

NewFloat64Measure calls `Meter.NewFloat64Measure` and returns the instrument, panicking if it encounters an error.

func (MeterMust) NewInt64Counter

func (mm MeterMust) NewInt64Counter(name string, cos ...Option) Int64Counter

NewInt64Counter calls `Meter.NewInt64Counter` and returns the instrument, panicking if it encounters an error.

func (MeterMust) NewInt64Measure

func (mm MeterMust) NewInt64Measure(name string, mos ...Option) Int64Measure

NewInt64Measure calls `Meter.NewInt64Measure` and returns the instrument, panicking if it encounters an error.

func (MeterMust) RegisterFloat64Observer

func (mm MeterMust) RegisterFloat64Observer(name string, callback Float64ObserverCallback, oos ...Option) Float64Observer

RegisterFloat64Observer calls `Meter.RegisterFloat64Observer` and returns the instrument, panicking if it encounters an error.

func (MeterMust) RegisterInt64Observer

func (mm MeterMust) RegisterInt64Observer(name string, callback Int64ObserverCallback, oos ...Option) Int64Observer

RegisterInt64Observer calls `Meter.RegisterInt64Observer` and returns the instrument, panicking if it encounters an error.

type NoopAsync

type NoopAsync struct {
	// contains filtered or unexported fields
}

func (NoopAsync) Descriptor

func (NoopAsync) Descriptor() Descriptor

func (NoopAsync) Implementation

func (NoopAsync) Implementation() interface{}

type NoopProvider

type NoopProvider struct{}

func (NoopProvider) Meter

func (NoopProvider) Meter(name string) Meter

type NoopSync

type NoopSync struct {
	// contains filtered or unexported fields
}

func (NoopSync) Bind

func (NoopSync) Descriptor

func (NoopSync) Descriptor() Descriptor

func (NoopSync) Implementation

func (NoopSync) Implementation() interface{}

func (NoopSync) RecordOne

func (NoopSync) RecordOne(context.Context, Number, []kv.KeyValue)

type Number

type Number uint64

Number represents either an integral or a floating point value. It needs to be accompanied with a source of NumberKind that describes the actual type of the value stored within Number.

func NewFloat64Number

func NewFloat64Number(f float64) Number

NewFloat64Number creates a floating point Number.

func NewInt64Number

func NewInt64Number(i int64) Number

NewInt64Number creates an integral Number.

func NewNumberFromRaw

func NewNumberFromRaw(r uint64) Number

NewNumberFromRaw creates a new Number from a raw value.

func NewUint64Number

func NewUint64Number(u uint64) Number

NewInt64Number creates an integral Number.

func (*Number) AddFloat64

func (n *Number) AddFloat64(f float64)

AddFloat64 assumes that the number contains a float64 and adds the passed float64 to it.

func (*Number) AddFloat64Atomic

func (n *Number) AddFloat64Atomic(f float64)

AddFloat64Atomic assumes that the number contains a float64 and adds the passed float64 to it atomically.

func (*Number) AddInt64

func (n *Number) AddInt64(i int64)

AddInt64 assumes that the number contains an int64 and adds the passed int64 to it.

func (*Number) AddInt64Atomic

func (n *Number) AddInt64Atomic(i int64)

AddInt64Atomic assumes that the number contains an int64 and adds the passed int64 to it atomically.

func (*Number) AddNumber

func (n *Number) AddNumber(kind NumberKind, nn Number)

AddNumber assumes that this and the passed number are of the passed kind and adds the passed number to this number.

func (*Number) AddNumberAtomic

func (n *Number) AddNumberAtomic(kind NumberKind, nn Number)

AddNumberAtomic assumes that this and the passed number are of the passed kind and adds the passed number to this number atomically.

func (*Number) AddRaw

func (n *Number) AddRaw(kind NumberKind, r uint64)

AddRaw assumes that this number and the passed raw value are of the passed kind and adds the passed raw value to this number.

func (*Number) AddRawAtomic

func (n *Number) AddRawAtomic(kind NumberKind, r uint64)

AddRawAtomic assumes that this number and the passed raw value are of the passed kind and adds the passed raw value to this number atomically.

func (*Number) AddUint64

func (n *Number) AddUint64(u uint64)

AddUint64 assumes that the number contains a uint64 and adds the passed uint64 to it.

func (*Number) AddUint64Atomic

func (n *Number) AddUint64Atomic(u uint64)

AddUint64Atomic assumes that the number contains a uint64 and atomically adds the passed uint64 to it.

func (*Number) AsFloat64

func (n *Number) AsFloat64() float64

AsFloat64 assumes that the measurement value contains a float64 and returns it as such.

func (*Number) AsFloat64Atomic

func (n *Number) AsFloat64Atomic() float64

AsFloat64Atomic assumes that the measurement value contains a float64 and returns it as such atomically.

func (*Number) AsFloat64Ptr

func (n *Number) AsFloat64Ptr() *float64

AsFloat64Ptr assumes that the number contains a float64 and returns a pointer to it.

func (*Number) AsInt64

func (n *Number) AsInt64() int64

AsInt64 assumes that the value contains an int64 and returns it as such.

func (*Number) AsInt64Atomic

func (n *Number) AsInt64Atomic() int64

AsInt64Atomic assumes that the number contains an int64 and returns it as such atomically.

func (*Number) AsInt64Ptr

func (n *Number) AsInt64Ptr() *int64

AsInt64Ptr assumes that the number contains an int64 and returns a pointer to it.

func (*Number) AsInterface

func (n *Number) AsInterface(kind NumberKind) interface{}

AsInterface returns the number as an interface{}, typically used for NumberKind-correct JSON conversion.

func (*Number) AsNumber

func (n *Number) AsNumber() Number

AsNumber gets the Number.

func (*Number) AsNumberAtomic

func (n *Number) AsNumberAtomic() Number

AsNumberAtomic gets the Number atomically.

func (*Number) AsRaw

func (n *Number) AsRaw() uint64

AsRaw gets the uninterpreted raw value. Might be useful for some atomic operations.

func (*Number) AsRawAtomic

func (n *Number) AsRawAtomic() uint64

AsRawAtomic gets the uninterpreted raw value atomically. Might be useful for some atomic operations.

func (*Number) AsRawPtr

func (n *Number) AsRawPtr() *uint64

AsRawPtr gets the pointer to the raw, uninterpreted raw value. Might be useful for some atomic operations.

func (*Number) AsUint64

func (n *Number) AsUint64() uint64

AsUint64 assumes that the value contains an uint64 and returns it as such.

func (*Number) AsUint64Atomic

func (n *Number) AsUint64Atomic() uint64

AsUint64Atomic assumes that the number contains a uint64 and returns it as such atomically.

func (*Number) AsUint64Ptr

func (n *Number) AsUint64Ptr() *uint64

AsUint64Ptr assumes that the number contains a uint64 and returns a pointer to it.

func (*Number) CoerceToFloat64

func (n *Number) CoerceToFloat64(kind NumberKind) float64

CoerceToFloat64 casts the number to float64. May result in data/precision loss.

func (*Number) CoerceToInt64

func (n *Number) CoerceToInt64(kind NumberKind) int64

CoerceToInt64 casts the number to int64. May result in data/precision loss.

func (*Number) CoerceToUint64

func (n *Number) CoerceToUint64(kind NumberKind) uint64

CoerceToUint64 casts the number to uint64. May result in data/precision loss.

func (*Number) CompareAndSwapFloat64

func (n *Number) CompareAndSwapFloat64(of, nf float64) bool

CompareAndSwapFloat64 assumes that this number contains a float64 and does the atomic CAS operation on it.

func (*Number) CompareAndSwapInt64

func (n *Number) CompareAndSwapInt64(oi, ni int64) bool

CompareAndSwapInt64 assumes that this number contains an int64 and does the atomic CAS operation on it.

func (*Number) CompareAndSwapNumber

func (n *Number) CompareAndSwapNumber(on, nn Number) bool

CompareAndSwapNumber does the atomic CAS operation on this number. This number and passed old and new numbers should be of the same kind.

func (*Number) CompareAndSwapRaw

func (n *Number) CompareAndSwapRaw(or, nr uint64) bool

CompareAndSwapRaw does the atomic CAS operation on this number. This number and passed old and new raw values should be of the same kind.

func (*Number) CompareAndSwapUint64

func (n *Number) CompareAndSwapUint64(ou, nu uint64) bool

CompareAndSwapUint64 assumes that this number contains a uint64 and does the atomic CAS operation on it.

func (*Number) CompareFloat64

func (n *Number) CompareFloat64(f float64) int

CompareFloat64 assumes that the Number contains a float64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.

Do not compare NaN values.

func (*Number) CompareInt64

func (n *Number) CompareInt64(i int64) int

CompareInt64 assumes that the Number contains an int64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.

func (*Number) CompareNumber

func (n *Number) CompareNumber(kind NumberKind, nn Number) int

CompareNumber compares two Numbers given their kind. Both numbers should have the same kind. This returns:

0 if the numbers are equal
-1 if the subject `n` is less than the argument `nn`
+1 if the subject `n` is greater than the argument `nn`

func (*Number) CompareRaw

func (n *Number) CompareRaw(kind NumberKind, r uint64) int

CompareRaw compares two numbers, where one is input as a raw uint64, interpreting both values as a `kind` of number.

func (*Number) CompareUint64

func (n *Number) CompareUint64(u uint64) int

CompareUint64 assumes that the Number contains an uint64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.

func (*Number) Emit

func (n *Number) Emit(kind NumberKind) string

Emit returns a string representation of the raw value of the Number. A %d is used for integral values, %f for floating point values.

func (*Number) IsNegative

func (n *Number) IsNegative(kind NumberKind) bool

IsNegative returns true if the actual value is less than zero.

func (*Number) IsPositive

func (n *Number) IsPositive(kind NumberKind) bool

IsPositive returns true if the actual value is greater than zero.

func (*Number) IsZero

func (n *Number) IsZero(kind NumberKind) bool

IsZero returns true if the actual value is equal to zero.

func (*Number) SetFloat64

func (n *Number) SetFloat64(f float64)

SetFloat64 assumes that the number contains a float64 and sets it to the passed value.

func (*Number) SetFloat64Atomic

func (n *Number) SetFloat64Atomic(f float64)

SetFloat64Atomic assumes that the number contains a float64 and sets it to the passed value atomically.

func (*Number) SetInt64

func (n *Number) SetInt64(i int64)

SetInt64 assumes that the number contains an int64 and sets it to the passed value.

func (*Number) SetInt64Atomic

func (n *Number) SetInt64Atomic(i int64)

SetInt64Atomic assumes that the number contains an int64 and sets it to the passed value atomically.

func (*Number) SetNumber

func (n *Number) SetNumber(nn Number)

SetNumber sets the number to the passed number. Both should be of the same kind.

func (*Number) SetNumberAtomic

func (n *Number) SetNumberAtomic(nn Number)

SetNumberAtomic sets the number to the passed number atomically. Both should be of the same kind.

func (*Number) SetRaw

func (n *Number) SetRaw(r uint64)

SetRaw sets the number to the passed raw value. Both number and the raw number should represent the same kind.

func (*Number) SetRawAtomic

func (n *Number) SetRawAtomic(r uint64)

SetRawAtomic sets the number to the passed raw value atomically. Both number and the raw number should represent the same kind.

func (*Number) SetUint64

func (n *Number) SetUint64(u uint64)

SetUint64 assumes that the number contains a uint64 and sets it to the passed value.

func (*Number) SetUint64Atomic

func (n *Number) SetUint64Atomic(u uint64)

SetUint64Atomic assumes that the number contains a uint64 and sets it to the passed value atomically.

func (*Number) SwapFloat64

func (n *Number) SwapFloat64(f float64) float64

SwapFloat64 assumes that the number contains an float64, sets it to the passed value and returns the old float64 value.

func (*Number) SwapFloat64Atomic

func (n *Number) SwapFloat64Atomic(f float64) float64

SwapFloat64Atomic assumes that the number contains an float64, sets it to the passed value and returns the old float64 value atomically.

func (*Number) SwapInt64

func (n *Number) SwapInt64(i int64) int64

SwapInt64 assumes that the number contains an int64, sets it to the passed value and returns the old int64 value.

func (*Number) SwapInt64Atomic

func (n *Number) SwapInt64Atomic(i int64) int64

SwapInt64Atomic assumes that the number contains an int64, sets it to the passed value and returns the old int64 value atomically.

func (*Number) SwapNumber

func (n *Number) SwapNumber(nn Number) Number

SwapNumber sets the number to the passed number and returns the old number. Both this number and the passed number should be of the same kind.

func (*Number) SwapNumberAtomic

func (n *Number) SwapNumberAtomic(nn Number) Number

SwapNumberAtomic sets the number to the passed number and returns the old number atomically. Both this number and the passed number should be of the same kind.

func (*Number) SwapRaw

func (n *Number) SwapRaw(r uint64) uint64

SwapRaw sets the number to the passed raw value and returns the old raw value. Both number and the raw number should represent the same kind.

func (*Number) SwapRawAtomic

func (n *Number) SwapRawAtomic(r uint64) uint64

SwapRawAtomic sets the number to the passed raw value and returns the old raw value atomically. Both number and the raw number should represent the same kind.

func (*Number) SwapUint64

func (n *Number) SwapUint64(u uint64) uint64

SwapUint64 assumes that the number contains an uint64, sets it to the passed value and returns the old uint64 value.

func (*Number) SwapUint64Atomic

func (n *Number) SwapUint64Atomic(u uint64) uint64

SwapUint64Atomic assumes that the number contains an uint64, sets it to the passed value and returns the old uint64 value atomically.

type NumberKind

type NumberKind int8

NumberKind describes the data type of the Number.

const (
	// Int64NumberKind means that the Number stores int64.
	Int64NumberKind NumberKind = iota
	// Float64NumberKind means that the Number stores float64.
	Float64NumberKind
	// Uint64NumberKind means that the Number stores uint64.
	Uint64NumberKind
)

func (NumberKind) Maximum

func (k NumberKind) Maximum() Number

Maximum returns the maximum representable value for a given NumberKind

func (NumberKind) Minimum

func (k NumberKind) Minimum() Number

Minimum returns the minimum representable value for a given NumberKind

func (NumberKind) String

func (i NumberKind) String() string

func (NumberKind) Zero

func (k NumberKind) Zero() Number

Zero returns a zero value for a given NumberKind

type Observation

type Observation struct {
	// contains filtered or unexported fields
}

Observation is used for reporting a batch of metric values. Instances of this type should be created by Observer instruments (e.g., Int64Observer.Observation()).

func (Observation) AsyncImpl

func (m Observation) AsyncImpl() AsyncImpl

AsyncImpl returns the instrument that created this observation. This returns an implementation-level object for use by the SDK, users should not refer to this.

func (Observation) Number

func (m Observation) Number() Number

Number returns a number recorded in this observation.

type Option

type Option interface {
	// Apply is used to set the Option value of a Config.
	Apply(*Config)
}

Option is an interface for applying metric options.

func WithDescription

func WithDescription(desc string) Option

WithDescription applies provided description.

func WithLibraryName

func WithLibraryName(name string) Option

WithLibraryName applies provided library name. This is meant for use in `Provider` implementations that have not used `WrapMeterImpl`. Implementations built using `WrapMeterImpl` have instrument descriptors taken care of through this package.

This option will have no effect when supplied by the user. Provider implementations are expected to append this option after the user-supplied options when building instrument descriptors.

func WithUnit

func WithUnit(unit unit.Unit) Option

WithUnit applies provided unit.

type Provider

type Provider interface {
	// Meter gets a named Meter interface.  If the name is an
	// empty string, the provider uses a default name.
	Meter(name string) Meter
}

Provider supports named Meter instances.

type SyncImpl

type SyncImpl interface {
	InstrumentImpl

	// Bind creates an implementation-level bound instrument,
	// binding a label set with this instrument implementation.
	Bind(labels []kv.KeyValue) BoundSyncImpl

	// RecordOne captures a single synchronous metric event.
	RecordOne(ctx context.Context, number Number, labels []kv.KeyValue)
}

SyncImpl is the implementation-level interface to a generic synchronous instrument (e.g., Measure and Counter instruments).

Source Files

api.go common.go counter.go doc.go kind_string.go measure.go must.go noop.go number.go numberkind_string.go observer.go sdkhelpers.go

Directories

PathSynopsis
api/metric/registry
Version
v0.5.0
Published
May 14, 2020
Platform
js/wasm
Imports
9 packages
Last checked
11 minutes ago

Tools for package owners.