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