blob: 10182460aaf295ffe77c1aa25c9c525bcbe74c44 [file] [log] [blame]
Joey Armstronga6af1522023-01-17 16:06:16 -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// Float64UpDownCounter is a metric instrument that sums floating
24// point values.
25type Float64UpDownCounter struct {
26 syncInstrument
27}
28
29// Int64UpDownCounter is a metric instrument that sums integer values.
30type Int64UpDownCounter struct {
31 syncInstrument
32}
33
34// BoundFloat64UpDownCounter is a bound instrument for Float64UpDownCounter.
35//
36// It inherits the Unbind function from syncBoundInstrument.
37type BoundFloat64UpDownCounter struct {
38 syncBoundInstrument
39}
40
41// BoundInt64UpDownCounter is a boundInstrument for Int64UpDownCounter.
42//
43// It inherits the Unbind function from syncBoundInstrument.
44type BoundInt64UpDownCounter struct {
45 syncBoundInstrument
46}
47
48// Bind creates a bound instrument for this counter. The labels are
49// associated with values recorded via subsequent calls to Record.
50func (c Float64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundFloat64UpDownCounter) {
51 h.syncBoundInstrument = c.bind(labels)
52 return
53}
54
55// Bind creates a bound instrument for this counter. The labels are
56// associated with values recorded via subsequent calls to Record.
57func (c Int64UpDownCounter) Bind(labels ...label.KeyValue) (h BoundInt64UpDownCounter) {
58 h.syncBoundInstrument = c.bind(labels)
59 return
60}
61
62// Measurement creates a Measurement object to use with batch
63// recording.
64func (c Float64UpDownCounter) Measurement(value float64) Measurement {
65 return c.float64Measurement(value)
66}
67
68// Measurement creates a Measurement object to use with batch
69// recording.
70func (c Int64UpDownCounter) Measurement(value int64) Measurement {
71 return c.int64Measurement(value)
72}
73
74// Add adds the value to the counter's sum. The labels should contain
75// the keys and values to be associated with this value.
76func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...label.KeyValue) {
77 c.directRecord(ctx, NewFloat64Number(value), labels)
78}
79
80// Add adds the value to the counter's sum. The labels should contain
81// the keys and values to be associated with this value.
82func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...label.KeyValue) {
83 c.directRecord(ctx, NewInt64Number(value), labels)
84}
85
86// Add adds the value to the counter's sum using the labels
87// previously bound to this counter via Bind()
88func (b BoundFloat64UpDownCounter) Add(ctx context.Context, value float64) {
89 b.directRecord(ctx, NewFloat64Number(value))
90}
91
92// Add adds the value to the counter's sum using the labels
93// previously bound to this counter via Bind()
94func (b BoundInt64UpDownCounter) Add(ctx context.Context, value int64) {
95 b.directRecord(ctx, NewInt64Number(value))
96}