Source File
registry.go
Belonging Package
go.opentelemetry.io/otel/api/metric/registry
package registry // import "go.opentelemetry.io/otel/api/metric/registry"
import (
)
type uniqueInstrumentMeterImpl struct {
lock sync.Mutex
impl metric.MeterImpl
state map[key]metric.InstrumentImpl
}
var _ metric.MeterImpl = (*uniqueInstrumentMeterImpl)(nil)
type key struct {
instrumentName string
instrumentationName string
InstrumentationVersion string
}
func ( *Provider) ( string, ...metric.MeterOption) metric.Meter {
return metric.WrapMeterImpl(.impl, , ...)
}
var ErrMetricKindMismatch = fmt.Errorf(
"A metric was already registered by this name with another kind or number type")
func ( metric.MeterImpl) metric.MeterImpl {
return &uniqueInstrumentMeterImpl{
impl: ,
state: map[key]metric.InstrumentImpl{},
}
}
func ( *uniqueInstrumentMeterImpl) ( context.Context, []label.KeyValue, ...metric.Measurement) {
.impl.RecordBatch(, , ...)
}
func ( metric.Descriptor) key {
return key{
.Name(),
.InstrumentationName(),
.InstrumentationVersion(),
}
}
func ( metric.Descriptor) error {
return fmt.Errorf("Metric was %s (%s %s)registered as a %s %s: %w",
.Name(),
.InstrumentationName(),
.InstrumentationVersion(),
.NumberKind(),
.MetricKind(),
ErrMetricKindMismatch)
}
func (, metric.Descriptor) bool {
return .MetricKind() == .MetricKind() &&
.NumberKind() == .NumberKind()
}
func ( *uniqueInstrumentMeterImpl) ( metric.Descriptor) (metric.InstrumentImpl, error) {
, := .state[keyOf()]
if ! {
return nil, nil
}
if !Compatible(, .Descriptor()) {
return nil, NewMetricKindMismatchError(.Descriptor())
}
return , nil
}
func ( *uniqueInstrumentMeterImpl) ( metric.Descriptor) (metric.SyncImpl, error) {
.lock.Lock()
defer .lock.Unlock()
, := .checkUniqueness()
if != nil {
return nil,
} else if != nil {
return .(metric.SyncImpl), nil
}
, := .impl.NewSyncInstrument()
if != nil {
return nil,
}
.state[keyOf()] =
return , nil
}
func ( *uniqueInstrumentMeterImpl) (
metric.Descriptor,
metric.AsyncRunner,
) (metric.AsyncImpl, error) {
.lock.Lock()
defer .lock.Unlock()
, := .checkUniqueness()
if != nil {
return nil,
} else if != nil {
return .(metric.AsyncImpl), nil
}
, := .impl.NewAsyncInstrument(, )
if != nil {
return nil,
}
.state[keyOf()] =
return , nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |