blob: fa7e2d4f8a5bfd3dd89844b2e77e20b17d02e8df [file] [log] [blame]
Joey Armstrong5f51f2e2023-01-17 17:06:26 -05001// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package metric
16
17import (
18 "context"
19
20 "go.opentelemetry.io/otel/label"
21)
22
23// Float64ValueRecorder is a metric that records float64 values.
24type Float64ValueRecorder struct {
25 syncInstrument
26}
27
28// Int64ValueRecorder is a metric that records int64 values.
29type Int64ValueRecorder struct {
30 syncInstrument
31}
32
33// BoundFloat64ValueRecorder is a bound instrument for Float64ValueRecorder.
34//
35// It inherits the Unbind function from syncBoundInstrument.
36type BoundFloat64ValueRecorder struct {
37 syncBoundInstrument
38}
39
40// BoundInt64ValueRecorder is a bound instrument for Int64ValueRecorder.
41//
42// It inherits the Unbind function from syncBoundInstrument.
43type BoundInt64ValueRecorder struct {
44 syncBoundInstrument
45}
46
47// Bind creates a bound instrument for this ValueRecorder. The labels are
48// associated with values recorded via subsequent calls to Record.
49func (c Float64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundFloat64ValueRecorder) {
50 h.syncBoundInstrument = c.bind(labels)
51 return
52}
53
54// Bind creates a bound instrument for this ValueRecorder. The labels are
55// associated with values recorded via subsequent calls to Record.
56func (c Int64ValueRecorder) Bind(labels ...label.KeyValue) (h BoundInt64ValueRecorder) {
57 h.syncBoundInstrument = c.bind(labels)
58 return
59}
60
61// Measurement creates a Measurement object to use with batch
62// recording.
63func (c Float64ValueRecorder) Measurement(value float64) Measurement {
64 return c.float64Measurement(value)
65}
66
67// Measurement creates a Measurement object to use with batch
68// recording.
69func (c Int64ValueRecorder) Measurement(value int64) Measurement {
70 return c.int64Measurement(value)
71}
72
73// Record adds a new value to the list of ValueRecorder's records. The
74// labels should contain the keys and values to be associated with
75// this value.
76func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...label.KeyValue) {
77 c.directRecord(ctx, NewFloat64Number(value), labels)
78}
79
80// Record adds a new value to the ValueRecorder's distribution. The
81// labels should contain the keys and values to be associated with
82// this value.
83func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...label.KeyValue) {
84 c.directRecord(ctx, NewInt64Number(value), labels)
85}
86
87// Record adds a new value to the ValueRecorder's distribution using the labels
88// previously bound to the ValueRecorder via Bind().
89func (b BoundFloat64ValueRecorder) Record(ctx context.Context, value float64) {
90 b.directRecord(ctx, NewFloat64Number(value))
91}
92
93// Record adds a new value to the ValueRecorder's distribution using the labels
94// previously bound to the ValueRecorder via Bind().
95func (b BoundInt64ValueRecorder) Record(ctx context.Context, value int64) {
96 b.directRecord(ctx, NewInt64Number(value))
97}