2019-06-14 22:09:41 +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.
|
|
|
|
|
2019-06-14 20:37:05 +02:00
|
|
|
package metric
|
|
|
|
|
2019-10-09 00:45:49 +02:00
|
|
|
import (
|
|
|
|
"context"
|
2019-10-29 22:27:22 +02:00
|
|
|
|
2019-11-01 20:40:29 +02:00
|
|
|
"go.opentelemetry.io/otel/api/core"
|
2019-10-09 00:45:49 +02:00
|
|
|
)
|
|
|
|
|
2019-10-15 18:28:36 +02:00
|
|
|
type commonMetric struct {
|
2019-10-29 22:27:22 +02:00
|
|
|
instrument InstrumentImpl
|
2019-10-15 18:28:36 +02:00
|
|
|
}
|
2019-10-09 00:45:49 +02:00
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
type commonBoundInstrument struct {
|
|
|
|
boundInstrument BoundInstrumentImpl
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
func (m commonMetric) bind(labels LabelSet) commonBoundInstrument {
|
|
|
|
return newCommonBoundInstrument(m.instrument.Bind(labels))
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-10-15 18:28:36 +02:00
|
|
|
func (m commonMetric) float64Measurement(value float64) Measurement {
|
2019-10-29 22:27:22 +02:00
|
|
|
return newMeasurement(m.instrument, core.NewFloat64Number(value))
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
2019-06-14 20:37:05 +02:00
|
|
|
|
2019-10-15 18:28:36 +02:00
|
|
|
func (m commonMetric) int64Measurement(value int64) Measurement {
|
2019-10-29 22:27:22 +02:00
|
|
|
return newMeasurement(m.instrument, core.NewInt64Number(value))
|
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
func (m commonMetric) directRecord(ctx context.Context, number core.Number, labels LabelSet) {
|
2019-10-29 22:27:22 +02:00
|
|
|
m.instrument.RecordOne(ctx, number, labels)
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-10-29 22:27:22 +02:00
|
|
|
func (m commonMetric) Impl() InstrumentImpl {
|
|
|
|
return m.instrument
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
func (h commonBoundInstrument) directRecord(ctx context.Context, number core.Number) {
|
|
|
|
h.boundInstrument.RecordOne(ctx, number)
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
func (h commonBoundInstrument) Unbind() {
|
|
|
|
h.boundInstrument.Unbind()
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
|
2019-10-29 22:27:22 +02:00
|
|
|
func newCommonMetric(instrument InstrumentImpl) commonMetric {
|
2019-10-15 18:28:36 +02:00
|
|
|
return commonMetric{
|
2019-10-23 08:29:24 +02:00
|
|
|
instrument: instrument,
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
func newCommonBoundInstrument(boundInstrument BoundInstrumentImpl) commonBoundInstrument {
|
|
|
|
return commonBoundInstrument{
|
|
|
|
boundInstrument: boundInstrument,
|
2019-10-23 08:29:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:27:22 +02:00
|
|
|
func newMeasurement(instrument InstrumentImpl, number core.Number) Measurement {
|
2019-10-23 08:29:24 +02:00
|
|
|
return Measurement{
|
|
|
|
instrument: instrument,
|
2019-10-29 22:27:22 +02:00
|
|
|
number: number,
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
2019-06-14 20:37:05 +02:00
|
|
|
}
|