2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-10-09 00:45:49 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// Float64Counter is a metric that accumulates float64 values.
|
|
|
|
type Float64Counter struct {
|
2020-03-19 21:02:46 +02:00
|
|
|
syncInstrument
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Int64Counter is a metric that accumulates int64 values.
|
|
|
|
type Int64Counter struct {
|
2020-03-19 21:02:46 +02:00
|
|
|
syncInstrument
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
// BoundFloat64Counter is a bound instrument for Float64Counter.
|
2019-10-23 08:29:24 +02:00
|
|
|
//
|
2020-03-19 21:02:46 +02:00
|
|
|
// It inherits the Unbind function from syncBoundInstrument.
|
2019-12-28 02:30:19 +02:00
|
|
|
type BoundFloat64Counter struct {
|
2020-03-19 21:02:46 +02:00
|
|
|
syncBoundInstrument
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
// BoundInt64Counter is a boundInstrument for Int64Counter.
|
2019-10-23 08:29:24 +02:00
|
|
|
//
|
2020-03-19 21:02:46 +02:00
|
|
|
// It inherits the Unbind function from syncBoundInstrument.
|
2019-12-28 02:30:19 +02:00
|
|
|
type BoundInt64Counter struct {
|
2020-03-19 21:02:46 +02:00
|
|
|
syncBoundInstrument
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 21:29:48 +02:00
|
|
|
// Bind creates a bound instrument for this counter. The labels are
|
|
|
|
// associated with values recorded via subsequent calls to Record.
|
2020-03-27 23:06:48 +02:00
|
|
|
func (c Float64Counter) Bind(labels ...core.KeyValue) (h BoundFloat64Counter) {
|
2020-03-19 21:02:46 +02:00
|
|
|
h.syncBoundInstrument = c.bind(labels)
|
2019-10-09 00:45:49 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:29:48 +02:00
|
|
|
// Bind creates a bound instrument for this counter. The labels are
|
|
|
|
// associated with values recorded via subsequent calls to Record.
|
2020-03-27 23:06:48 +02:00
|
|
|
func (c Int64Counter) Bind(labels ...core.KeyValue) (h BoundInt64Counter) {
|
2020-03-19 21:02:46 +02:00
|
|
|
h.syncBoundInstrument = c.bind(labels)
|
2019-10-09 00:45:49 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
2020-02-04 20:27:03 +02:00
|
|
|
func (c Float64Counter) Measurement(value float64) Measurement {
|
2019-10-09 00:45:49 +02:00
|
|
|
return c.float64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement creates a Measurement object to use with batch
|
|
|
|
// recording.
|
2020-02-04 20:27:03 +02:00
|
|
|
func (c Int64Counter) Measurement(value int64) Measurement {
|
2019-10-09 00:45:49 +02:00
|
|
|
return c.int64Measurement(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds the value to the counter's sum. The labels should contain
|
2020-04-28 21:29:48 +02:00
|
|
|
// the keys and values to be associated with this value.
|
2020-03-27 23:06:48 +02:00
|
|
|
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...core.KeyValue) {
|
2019-12-28 02:30:19 +02:00
|
|
|
c.directRecord(ctx, core.NewFloat64Number(value), labels)
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds the value to the counter's sum. The labels should contain
|
2020-04-28 21:29:48 +02:00
|
|
|
// the keys and values to be associated with this value.
|
2020-03-27 23:06:48 +02:00
|
|
|
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...core.KeyValue) {
|
2019-12-28 02:30:19 +02:00
|
|
|
c.directRecord(ctx, core.NewInt64Number(value), labels)
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 21:29:48 +02:00
|
|
|
// Add adds the value to the counter's sum using the labels
|
|
|
|
// previously bound to this counter via Bind()
|
2020-02-04 20:27:03 +02:00
|
|
|
func (b BoundFloat64Counter) Add(ctx context.Context, value float64) {
|
2019-12-28 02:30:19 +02:00
|
|
|
b.directRecord(ctx, core.NewFloat64Number(value))
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 21:29:48 +02:00
|
|
|
// Add adds the value to the counter's sum using the labels
|
|
|
|
// previously bound to this counter via Bind()
|
2020-02-04 20:27:03 +02:00
|
|
|
func (b BoundInt64Counter) Add(ctx context.Context, value int64) {
|
2019-12-28 02:30:19 +02:00
|
|
|
b.directRecord(ctx, core.NewInt64Number(value))
|
2019-10-09 00:45:49 +02:00
|
|
|
}
|