2019-10-23 08:29:24 +02:00
|
|
|
// Copyright 2019, 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 metric
|
|
|
|
|
2019-10-29 22:27:22 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-11-01 20:40:29 +02:00
|
|
|
"go.opentelemetry.io/otel/api/core"
|
2019-10-29 22:27:22 +02:00
|
|
|
)
|
|
|
|
|
2019-12-24 09:03:04 +02:00
|
|
|
// LabelSetDelegate is a general-purpose delegating implementation of
|
|
|
|
// the LabelSet interface. This is implemented by the default
|
|
|
|
// Provider returned by api/global.SetMeterProvider(), and should be
|
|
|
|
// tested for by implementations before converting a LabelSet to their
|
|
|
|
// private concrete type.
|
|
|
|
type LabelSetDelegate interface {
|
|
|
|
Delegate() LabelSet
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:27:22 +02:00
|
|
|
// InstrumentImpl is the implementation-level interface Set/Add/Record
|
|
|
|
// individual metrics without precomputed labels.
|
|
|
|
type InstrumentImpl interface {
|
2019-12-28 02:30:19 +02:00
|
|
|
// Bind creates a Bound Instrument to record metrics with
|
2019-10-29 22:27:22 +02:00
|
|
|
// precomputed labels.
|
2019-12-28 02:30:19 +02:00
|
|
|
Bind(labels LabelSet) BoundInstrumentImpl
|
2019-10-29 22:27:22 +02:00
|
|
|
|
|
|
|
// RecordOne allows the SDK to observe a single metric event.
|
|
|
|
RecordOne(ctx context.Context, number core.Number, labels LabelSet)
|
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
// BoundInstrumentImpl is the implementation-level interface to Set/Add/Record
|
2019-10-29 22:27:22 +02:00
|
|
|
// individual metrics with precomputed labels.
|
2019-12-28 02:30:19 +02:00
|
|
|
type BoundInstrumentImpl interface {
|
2019-10-29 22:27:22 +02:00
|
|
|
// RecordOne allows the SDK to observe a single metric event.
|
|
|
|
RecordOne(ctx context.Context, number core.Number)
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
// Unbind frees the resources associated with this bound instrument. It
|
|
|
|
// does not affect the metric this bound instrument was created through.
|
|
|
|
Unbind()
|
2019-10-29 22:27:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-23 08:29:24 +02:00
|
|
|
// WrapInt64CounterInstrument wraps the instrument in the type-safe
|
|
|
|
// wrapper as an integral counter.
|
|
|
|
//
|
|
|
|
// It is mostly intended for SDKs.
|
2020-03-11 20:57:57 +02:00
|
|
|
func WrapInt64CounterInstrument(instrument InstrumentImpl, err error) (Int64Counter, error) {
|
|
|
|
common, err := newCommonMetric(instrument, err)
|
|
|
|
return Int64Counter{commonMetric: common}, err
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WrapFloat64CounterInstrument wraps the instrument in the type-safe
|
|
|
|
// wrapper as an floating point counter.
|
|
|
|
//
|
|
|
|
// It is mostly intended for SDKs.
|
2020-03-11 20:57:57 +02:00
|
|
|
func WrapFloat64CounterInstrument(instrument InstrumentImpl, err error) (Float64Counter, error) {
|
|
|
|
common, err := newCommonMetric(instrument, err)
|
|
|
|
return Float64Counter{commonMetric: common}, err
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WrapInt64MeasureInstrument wraps the instrument in the type-safe
|
|
|
|
// wrapper as an integral measure.
|
|
|
|
//
|
|
|
|
// It is mostly intended for SDKs.
|
2020-03-11 20:57:57 +02:00
|
|
|
func WrapInt64MeasureInstrument(instrument InstrumentImpl, err error) (Int64Measure, error) {
|
|
|
|
common, err := newCommonMetric(instrument, err)
|
|
|
|
return Int64Measure{commonMetric: common}, err
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WrapFloat64MeasureInstrument wraps the instrument in the type-safe
|
|
|
|
// wrapper as an floating point measure.
|
|
|
|
//
|
|
|
|
// It is mostly intended for SDKs.
|
2020-03-11 20:57:57 +02:00
|
|
|
func WrapFloat64MeasureInstrument(instrument InstrumentImpl, err error) (Float64Measure, error) {
|
|
|
|
common, err := newCommonMetric(instrument, err)
|
|
|
|
return Float64Measure{commonMetric: common}, err
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-12 05:21:34 +02:00
|
|
|
// Configure is a helper that applies all the options to a Config.
|
|
|
|
func Configure(opts []Option) Config {
|
|
|
|
var config Config
|
|
|
|
for _, o := range opts {
|
|
|
|
o.Apply(&config)
|
2020-03-05 22:15:30 +02:00
|
|
|
}
|
2020-03-12 05:21:34 +02:00
|
|
|
return config
|
2020-03-05 22:15:30 +02:00
|
|
|
}
|