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 registry // import "go.opentelemetry.io/otel/api/metric/registry"

import (
	
	
	

	
	
)
Provider is a standard metric.Provider for wrapping `MeterImpl`
type Provider struct {
	impl metric.MeterImpl
}

var _ metric.Provider = (*Provider)(nil)
uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter to wrap an implementation with uniqueness checking.
NewProvider returns a new provider that implements instrument name-uniqueness checking.
Meter implements metric.Provider.
func ( *Provider) ( string,  ...metric.MeterOption) metric.Meter {
	return metric.WrapMeterImpl(.impl, , ...)
}
ErrMetricKindMismatch is the standard error for mismatched metric instrument definitions.
var ErrMetricKindMismatch = fmt.Errorf(
	"A metric was already registered by this name with another kind or number type")
NewUniqueInstrumentMeterImpl returns a wrapped metric.MeterImpl with the addition of uniqueness checking.
RecordBatch implements metric.MeterImpl.
func ( *uniqueInstrumentMeterImpl) ( context.Context,  []label.KeyValue,  ...metric.Measurement) {
	.impl.RecordBatch(, , ...)
}

func ( metric.Descriptor) key {
	return key{
		.Name(),
		.InstrumentationName(),
		.InstrumentationVersion(),
	}
}
NewMetricKindMismatchError formats an error that describes a mismatched metric instrument definition.
func ( metric.Descriptor) error {
	return fmt.Errorf("Metric was %s (%s %s)registered as a %s %s: %w",
		.Name(),
		.InstrumentationName(),
		.InstrumentationVersion(),
		.NumberKind(),
		.MetricKind(),
		ErrMetricKindMismatch)
}
Compatible determines whether two metric.Descriptors are considered the same for the purpose of uniqueness checking.
func (,  metric.Descriptor) bool {
	return .MetricKind() == .MetricKind() &&
		.NumberKind() == .NumberKind()
}
checkUniqueness returns an ErrMetricKindMismatch error if there is a conflict between a descriptor that was already registered and the `descriptor` argument. If there is an existing compatible registration, this returns the already-registered instrument. If there is no conflict and no prior registration, returns (nil, nil).
func ( *uniqueInstrumentMeterImpl) ( metric.Descriptor) (metric.InstrumentImpl, error) {
	,  := .state[keyOf()]
	if ! {
		return nil, nil
	}

	if !Compatible(, .Descriptor()) {
		return nil, NewMetricKindMismatchError(.Descriptor())
	}

	return , nil
}
NewSyncInstrument implements metric.MeterImpl.
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
}
NewAsyncInstrument implements metric.MeterImpl.
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