| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package metric // import "go.opentelemetry.io/otel/metric" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/otel/metric/embedded" |
| 10 |
) |
| 11 |
|
| 12 |
// Float64Counter is an instrument that records increasing float64 values. |
| 13 |
// |
| 14 |
// Warning: Methods may be added to this interface in minor releases. See |
| 15 |
// package documentation on API implementation for information on how to set |
| 16 |
// default behavior for unimplemented methods. |
| 17 |
type Float64Counter interface { |
| 18 |
// Users of the interface can ignore this. This embedded type is only used |
| 19 |
// by implementations of this interface. See the "API Implementations" |
| 20 |
// section of the package documentation for more information. |
| 21 |
embedded.Float64Counter |
| 22 |
|
| 23 |
// Add records a change to the counter. |
| 24 |
// |
| 25 |
// Use the WithAttributeSet (or, if performance is not a concern, |
| 26 |
// the WithAttributes) option to include measurement attributes. |
| 27 |
// |
| 28 |
// Implementations of this method need to be safe for a user to call |
| 29 |
// concurrently. |
| 30 |
Add(ctx context.Context, incr float64, options ...AddOption) |
| 31 |
|
| 32 |
// Enabled reports whether the instrument will process measurements for the given context. |
| 33 |
// |
| 34 |
// This function can be used in places where measuring an instrument |
| 35 |
// would result in computationally expensive operations. |
| 36 |
// |
| 37 |
// Implementations of this method need to be safe for a user to call |
| 38 |
// concurrently. |
| 39 |
Enabled(context.Context) bool |
| 40 |
} |
| 41 |
|
| 42 |
// Float64CounterConfig contains options for synchronous counter instruments that |
| 43 |
// record float64 values. |
| 44 |
type Float64CounterConfig struct { |
| 45 |
description string |
| 46 |
unit string |
| 47 |
} |
| 48 |
|
| 49 |
// NewFloat64CounterConfig returns a new [Float64CounterConfig] with all opts |
| 50 |
// applied. |
| 51 |
func NewFloat64CounterConfig(opts ...Float64CounterOption) Float64CounterConfig { |
| 52 |
var config Float64CounterConfig |
| 53 |
for _, o := range opts { |
| 54 |
config = o.applyFloat64Counter(config) |
| 55 |
} |
| 56 |
return config |
| 57 |
} |
| 58 |
|
| 59 |
// Description returns the configured description. |
| 60 |
func (c Float64CounterConfig) Description() string { |
| 61 |
return c.description |
| 62 |
} |
| 63 |
|
| 64 |
// Unit returns the configured unit. |
| 65 |
func (c Float64CounterConfig) Unit() string { |
| 66 |
return c.unit |
| 67 |
} |
| 68 |
|
| 69 |
// Float64CounterOption applies options to a [Float64CounterConfig]. See |
| 70 |
// [InstrumentOption] for other options that can be used as a |
| 71 |
// Float64CounterOption. |
| 72 |
type Float64CounterOption interface { |
| 73 |
applyFloat64Counter(Float64CounterConfig) Float64CounterConfig |
| 74 |
} |
| 75 |
|
| 76 |
// Float64UpDownCounter is an instrument that records increasing or decreasing |
| 77 |
// float64 values. |
| 78 |
// |
| 79 |
// Warning: Methods may be added to this interface in minor releases. See |
| 80 |
// package documentation on API implementation for information on how to set |
| 81 |
// default behavior for unimplemented methods. |
| 82 |
type Float64UpDownCounter interface { |
| 83 |
// Users of the interface can ignore this. This embedded type is only used |
| 84 |
// by implementations of this interface. See the "API Implementations" |
| 85 |
// section of the package documentation for more information. |
| 86 |
embedded.Float64UpDownCounter |
| 87 |
|
| 88 |
// Add records a change to the counter. |
| 89 |
// |
| 90 |
// Use the WithAttributeSet (or, if performance is not a concern, |
| 91 |
// the WithAttributes) option to include measurement attributes. |
| 92 |
// |
| 93 |
// Implementations of this method need to be safe for a user to call |
| 94 |
// concurrently. |
| 95 |
Add(ctx context.Context, incr float64, options ...AddOption) |
| 96 |
|
| 97 |
// Enabled reports whether the instrument will process measurements for the given context. |
| 98 |
// |
| 99 |
// This function can be used in places where measuring an instrument |
| 100 |
// would result in computationally expensive operations. |
| 101 |
// |
| 102 |
// Implementations of this method need to be safe for a user to call |
| 103 |
// concurrently. |
| 104 |
Enabled(context.Context) bool |
| 105 |
} |
| 106 |
|
| 107 |
// Float64UpDownCounterConfig contains options for synchronous counter |
| 108 |
// instruments that record float64 values. |
| 109 |
type Float64UpDownCounterConfig struct { |
| 110 |
description string |
| 111 |
unit string |
| 112 |
} |
| 113 |
|
| 114 |
// NewFloat64UpDownCounterConfig returns a new [Float64UpDownCounterConfig] |
| 115 |
// with all opts applied. |
| 116 |
func NewFloat64UpDownCounterConfig(opts ...Float64UpDownCounterOption) Float64UpDownCounterConfig { |
| 117 |
var config Float64UpDownCounterConfig |
| 118 |
for _, o := range opts { |
| 119 |
config = o.applyFloat64UpDownCounter(config) |
| 120 |
} |
| 121 |
return config |
| 122 |
} |
| 123 |
|
| 124 |
// Description returns the configured description. |
| 125 |
func (c Float64UpDownCounterConfig) Description() string { |
| 126 |
return c.description |
| 127 |
} |
| 128 |
|
| 129 |
// Unit returns the configured unit. |
| 130 |
func (c Float64UpDownCounterConfig) Unit() string { |
| 131 |
return c.unit |
| 132 |
} |
| 133 |
|
| 134 |
// Float64UpDownCounterOption applies options to a |
| 135 |
// [Float64UpDownCounterConfig]. See [InstrumentOption] for other options that |
| 136 |
// can be used as a Float64UpDownCounterOption. |
| 137 |
type Float64UpDownCounterOption interface { |
| 138 |
applyFloat64UpDownCounter(Float64UpDownCounterConfig) Float64UpDownCounterConfig |
| 139 |
} |
| 140 |
|
| 141 |
// Float64Histogram is an instrument that records a distribution of float64 |
| 142 |
// values. |
| 143 |
// |
| 144 |
// Warning: Methods may be added to this interface in minor releases. See |
| 145 |
// package documentation on API implementation for information on how to set |
| 146 |
// default behavior for unimplemented methods. |
| 147 |
type Float64Histogram interface { |
| 148 |
// Users of the interface can ignore this. This embedded type is only used |
| 149 |
// by implementations of this interface. See the "API Implementations" |
| 150 |
// section of the package documentation for more information. |
| 151 |
embedded.Float64Histogram |
| 152 |
|
| 153 |
// Record adds an additional value to the distribution. |
| 154 |
// |
| 155 |
// Use the WithAttributeSet (or, if performance is not a concern, |
| 156 |
// the WithAttributes) option to include measurement attributes. |
| 157 |
// |
| 158 |
// Implementations of this method need to be safe for a user to call |
| 159 |
// concurrently. |
| 160 |
Record(ctx context.Context, incr float64, options ...RecordOption) |
| 161 |
|
| 162 |
// Enabled reports whether the instrument will process measurements for the given context. |
| 163 |
// |
| 164 |
// This function can be used in places where measuring an instrument |
| 165 |
// would result in computationally expensive operations. |
| 166 |
// |
| 167 |
// Implementations of this method need to be safe for a user to call |
| 168 |
// concurrently. |
| 169 |
Enabled(context.Context) bool |
| 170 |
} |
| 171 |
|
| 172 |
// Float64HistogramConfig contains options for synchronous histogram |
| 173 |
// instruments that record float64 values. |
| 174 |
type Float64HistogramConfig struct { |
| 175 |
description string |
| 176 |
unit string |
| 177 |
explicitBucketBoundaries []float64 |
| 178 |
} |
| 179 |
|
| 180 |
// NewFloat64HistogramConfig returns a new [Float64HistogramConfig] with all |
| 181 |
// opts applied. |
| 182 |
func NewFloat64HistogramConfig(opts ...Float64HistogramOption) Float64HistogramConfig { |
| 183 |
var config Float64HistogramConfig |
| 184 |
for _, o := range opts { |
| 185 |
config = o.applyFloat64Histogram(config) |
| 186 |
} |
| 187 |
return config |
| 188 |
} |
| 189 |
|
| 190 |
// Description returns the configured description. |
| 191 |
func (c Float64HistogramConfig) Description() string { |
| 192 |
return c.description |
| 193 |
} |
| 194 |
|
| 195 |
// Unit returns the configured unit. |
| 196 |
func (c Float64HistogramConfig) Unit() string { |
| 197 |
return c.unit |
| 198 |
} |
| 199 |
|
| 200 |
// ExplicitBucketBoundaries returns the configured explicit bucket boundaries. |
| 201 |
func (c Float64HistogramConfig) ExplicitBucketBoundaries() []float64 { |
| 202 |
return c.explicitBucketBoundaries |
| 203 |
} |
| 204 |
|
| 205 |
// Float64HistogramOption applies options to a [Float64HistogramConfig]. See |
| 206 |
// [InstrumentOption] for other options that can be used as a |
| 207 |
// Float64HistogramOption. |
| 208 |
type Float64HistogramOption interface { |
| 209 |
applyFloat64Histogram(Float64HistogramConfig) Float64HistogramConfig |
| 210 |
} |
| 211 |
|
| 212 |
// Float64Gauge is an instrument that records instantaneous float64 values. |
| 213 |
// |
| 214 |
// Warning: Methods may be added to this interface in minor releases. See |
| 215 |
// package documentation on API implementation for information on how to set |
| 216 |
// default behavior for unimplemented methods. |
| 217 |
type Float64Gauge interface { |
| 218 |
// Users of the interface can ignore this. This embedded type is only used |
| 219 |
// by implementations of this interface. See the "API Implementations" |
| 220 |
// section of the package documentation for more information. |
| 221 |
embedded.Float64Gauge |
| 222 |
|
| 223 |
// Record records the instantaneous value. |
| 224 |
// |
| 225 |
// Use the WithAttributeSet (or, if performance is not a concern, |
| 226 |
// the WithAttributes) option to include measurement attributes. |
| 227 |
// |
| 228 |
// Implementations of this method need to be safe for a user to call |
| 229 |
// concurrently. |
| 230 |
Record(ctx context.Context, value float64, options ...RecordOption) |
| 231 |
|
| 232 |
// Enabled reports whether the instrument will process measurements for the given context. |
| 233 |
// |
| 234 |
// This function can be used in places where measuring an instrument |
| 235 |
// would result in computationally expensive operations. |
| 236 |
// |
| 237 |
// Implementations of this method need to be safe for a user to call |
| 238 |
// concurrently. |
| 239 |
Enabled(context.Context) bool |
| 240 |
} |
| 241 |
|
| 242 |
// Float64GaugeConfig contains options for synchronous gauge instruments that |
| 243 |
// record float64 values. |
| 244 |
type Float64GaugeConfig struct { |
| 245 |
description string |
| 246 |
unit string |
| 247 |
} |
| 248 |
|
| 249 |
// NewFloat64GaugeConfig returns a new [Float64GaugeConfig] with all opts |
| 250 |
// applied. |
| 251 |
func NewFloat64GaugeConfig(opts ...Float64GaugeOption) Float64GaugeConfig { |
| 252 |
var config Float64GaugeConfig |
| 253 |
for _, o := range opts { |
| 254 |
config = o.applyFloat64Gauge(config) |
| 255 |
} |
| 256 |
return config |
| 257 |
} |
| 258 |
|
| 259 |
// Description returns the configured description. |
| 260 |
func (c Float64GaugeConfig) Description() string { |
| 261 |
return c.description |
| 262 |
} |
| 263 |
|
| 264 |
// Unit returns the configured unit. |
| 265 |
func (c Float64GaugeConfig) Unit() string { |
| 266 |
return c.unit |
| 267 |
} |
| 268 |
|
| 269 |
// Float64GaugeOption applies options to a [Float64GaugeConfig]. See |
| 270 |
// [InstrumentOption] for other options that can be used as a |
| 271 |
// Float64GaugeOption. |
| 272 |
type Float64GaugeOption interface { |
| 273 |
applyFloat64Gauge(Float64GaugeConfig) Float64GaugeConfig |
| 274 |
} |