Joey Armstrong | 903c69d | 2024-02-01 19:46:39 -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 "go.opentelemetry.io/otel/unit" |
| 18 | |
| 19 | // Descriptor contains all the settings that describe an instrument, |
| 20 | // including its name, metric kind, number kind, and the configurable |
| 21 | // options. |
| 22 | type Descriptor struct { |
| 23 | name string |
| 24 | kind Kind |
| 25 | numberKind NumberKind |
| 26 | config InstrumentConfig |
| 27 | } |
| 28 | |
| 29 | // NewDescriptor returns a Descriptor with the given contents. |
| 30 | func NewDescriptor(name string, mkind Kind, nkind NumberKind, opts ...InstrumentOption) Descriptor { |
| 31 | return Descriptor{ |
| 32 | name: name, |
| 33 | kind: mkind, |
| 34 | numberKind: nkind, |
| 35 | config: NewInstrumentConfig(opts...), |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Name returns the metric instrument's name. |
| 40 | func (d Descriptor) Name() string { |
| 41 | return d.name |
| 42 | } |
| 43 | |
| 44 | // MetricKind returns the specific kind of instrument. |
| 45 | func (d Descriptor) MetricKind() Kind { |
| 46 | return d.kind |
| 47 | } |
| 48 | |
| 49 | // Description provides a human-readable description of the metric |
| 50 | // instrument. |
| 51 | func (d Descriptor) Description() string { |
| 52 | return d.config.Description |
| 53 | } |
| 54 | |
| 55 | // Unit describes the units of the metric instrument. Unitless |
| 56 | // metrics return the empty string. |
| 57 | func (d Descriptor) Unit() unit.Unit { |
| 58 | return d.config.Unit |
| 59 | } |
| 60 | |
| 61 | // NumberKind returns whether this instrument is declared over int64, |
| 62 | // float64, or uint64 values. |
| 63 | func (d Descriptor) NumberKind() NumberKind { |
| 64 | return d.numberKind |
| 65 | } |
| 66 | |
| 67 | // InstrumentationName returns the name of the library that provided |
| 68 | // instrumentation for this instrument. |
| 69 | func (d Descriptor) InstrumentationName() string { |
| 70 | return d.config.InstrumentationName |
| 71 | } |
| 72 | |
| 73 | // InstrumentationVersion returns the version of the library that provided |
| 74 | // instrumentation for this instrument. |
| 75 | func (d Descriptor) InstrumentationVersion() string { |
| 76 | return d.config.InstrumentationVersion |
| 77 | } |