Joey Armstrong | 5f51f2e | 2023-01-17 17:06:26 -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 | // Float64ValueRecorder is a metric that records float64 values. |
| 24 | type Float64ValueRecorder struct { |
| 25 | syncInstrument |
| 26 | } |
| 27 | |
| 28 | // Int64ValueRecorder is a metric that records int64 values. |
| 29 | type Int64ValueRecorder struct { |
| 30 | syncInstrument |
| 31 | } |
| 32 | |
| 33 | // BoundFloat64ValueRecorder is a bound instrument for Float64ValueRecorder. |
| 34 | // |
| 35 | // It inherits the Unbind function from syncBoundInstrument. |
| 36 | type BoundFloat64ValueRecorder struct { |
| 37 | syncBoundInstrument |
| 38 | } |
| 39 | |
| 40 | // BoundInt64ValueRecorder is a bound instrument for Int64ValueRecorder. |
| 41 | // |
| 42 | // It inherits the Unbind function from syncBoundInstrument. |
| 43 | type 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. |
| 49 | func (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. |
| 56 | func (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. |
| 63 | func (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. |
| 69 | func (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. |
| 76 | func (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. |
| 83 | func (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(). |
| 89 | func (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(). |
| 95 | func (b BoundInt64ValueRecorder) Record(ctx context.Context, value int64) { |
| 96 | b.directRecord(ctx, NewInt64Number(value)) |
| 97 | } |