Debian Codegraph @

metric/noop/noop.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Package noop provides an implementation of the OpenTelemetry metric API that
5 // produces no telemetry and minimizes used computation resources.
6 //
7 // Using this package to implement the OpenTelemetry metric API will
8 // effectively disable OpenTelemetry.
9 //
10 // This implementation can be embedded in other implementations of the
11 // OpenTelemetry metric API. Doing so will mean the implementation defaults to
12 // no operation for methods it does not implement.
13 package noop // import "go.opentelemetry.io/otel/metric/noop"
14
15 import (
16 "context"
17
18 "go.opentelemetry.io/otel/metric"
19 "go.opentelemetry.io/otel/metric/embedded"
20 )
21
22 var (
23 // Compile-time check this implements the OpenTelemetry API.
24
25 _ metric.MeterProvider = MeterProvider{}
26 _ metric.Meter = Meter{}
27 _ metric.Observer = Observer{}
28 _ metric.Registration = Registration{}
29 _ metric.Int64Counter = Int64Counter{}
30 _ metric.Float64Counter = Float64Counter{}
31 _ metric.Int64UpDownCounter = Int64UpDownCounter{}
32 _ metric.Float64UpDownCounter = Float64UpDownCounter{}
33 _ metric.Int64Histogram = Int64Histogram{}
34 _ metric.Float64Histogram = Float64Histogram{}
35 _ metric.Int64Gauge = Int64Gauge{}
36 _ metric.Float64Gauge = Float64Gauge{}
37 _ metric.Int64ObservableCounter = Int64ObservableCounter{}
38 _ metric.Float64ObservableCounter = Float64ObservableCounter{}
39 _ metric.Int64ObservableGauge = Int64ObservableGauge{}
40 _ metric.Float64ObservableGauge = Float64ObservableGauge{}
41 _ metric.Int64ObservableUpDownCounter = Int64ObservableUpDownCounter{}
42 _ metric.Float64ObservableUpDownCounter = Float64ObservableUpDownCounter{}
43 _ metric.Int64Observer = Int64Observer{}
44 _ metric.Float64Observer = Float64Observer{}
45 )
46
47 // MeterProvider is an OpenTelemetry No-Op MeterProvider.
48 type MeterProvider struct{ embedded.MeterProvider }
49
50 // NewMeterProvider returns a MeterProvider that does not record any telemetry.
51 func NewMeterProvider() MeterProvider {
52 return MeterProvider{}
53 }
54
55 // Meter returns an OpenTelemetry Meter that does not record any telemetry.
56 func (MeterProvider) Meter(string, ...metric.MeterOption) metric.Meter {
57 return Meter{}
58 }
59
60 // Meter is an OpenTelemetry No-Op Meter.
61 type Meter struct{ embedded.Meter }
62
63 // Int64Counter returns a Counter used to record int64 measurements that
64 // produces no telemetry.
65 func (Meter) Int64Counter(string, ...metric.Int64CounterOption) (metric.Int64Counter, error) {
66 return Int64Counter{}, nil
67 }
68
69 // Int64UpDownCounter returns an UpDownCounter used to record int64
70 // measurements that produces no telemetry.
71 func (Meter) Int64UpDownCounter(string, ...metric.Int64UpDownCounterOption) (metric.Int64UpDownCounter, error) {
72 return Int64UpDownCounter{}, nil
73 }
74
75 // Int64Histogram returns a Histogram used to record int64 measurements that
76 // produces no telemetry.
77 func (Meter) Int64Histogram(string, ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
78 return Int64Histogram{}, nil
79 }
80
81 // Int64Gauge returns a Gauge used to record int64 measurements that
82 // produces no telemetry.
83 func (Meter) Int64Gauge(string, ...metric.Int64GaugeOption) (metric.Int64Gauge, error) {
84 return Int64Gauge{}, nil
85 }
86
87 // Int64ObservableCounter returns an ObservableCounter used to record int64
88 // measurements that produces no telemetry.
89 func (Meter) Int64ObservableCounter(
90 string,
91 ...metric.Int64ObservableCounterOption,
92 ) (metric.Int64ObservableCounter, error) {
93 return Int64ObservableCounter{}, nil
94 }
95
96 // Int64ObservableUpDownCounter returns an ObservableUpDownCounter used to
97 // record int64 measurements that produces no telemetry.
98 func (Meter) Int64ObservableUpDownCounter(
99 string,
100 ...metric.Int64ObservableUpDownCounterOption,
101 ) (metric.Int64ObservableUpDownCounter, error) {
102 return Int64ObservableUpDownCounter{}, nil
103 }
104
105 // Int64ObservableGauge returns an ObservableGauge used to record int64
106 // measurements that produces no telemetry.
107 func (Meter) Int64ObservableGauge(string, ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) {
108 return Int64ObservableGauge{}, nil
109 }
110
111 // Float64Counter returns a Counter used to record int64 measurements that
112 // produces no telemetry.
113 func (Meter) Float64Counter(string, ...metric.Float64CounterOption) (metric.Float64Counter, error) {
114 return Float64Counter{}, nil
115 }
116
117 // Float64UpDownCounter returns an UpDownCounter used to record int64
118 // measurements that produces no telemetry.
119 func (Meter) Float64UpDownCounter(string, ...metric.Float64UpDownCounterOption) (metric.Float64UpDownCounter, error) {
120 return Float64UpDownCounter{}, nil
121 }
122
123 // Float64Histogram returns a Histogram used to record int64 measurements that
124 // produces no telemetry.
125 func (Meter) Float64Histogram(string, ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
126 return Float64Histogram{}, nil
127 }
128
129 // Float64Gauge returns a Gauge used to record float64 measurements that
130 // produces no telemetry.
131 func (Meter) Float64Gauge(string, ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
132 return Float64Gauge{}, nil
133 }
134
135 // Float64ObservableCounter returns an ObservableCounter used to record int64
136 // measurements that produces no telemetry.
137 func (Meter) Float64ObservableCounter(
138 string,
139 ...metric.Float64ObservableCounterOption,
140 ) (metric.Float64ObservableCounter, error) {
141 return Float64ObservableCounter{}, nil
142 }
143
144 // Float64ObservableUpDownCounter returns an ObservableUpDownCounter used to
145 // record int64 measurements that produces no telemetry.
146 func (Meter) Float64ObservableUpDownCounter(
147 string,
148 ...metric.Float64ObservableUpDownCounterOption,
149 ) (metric.Float64ObservableUpDownCounter, error) {
150 return Float64ObservableUpDownCounter{}, nil
151 }
152
153 // Float64ObservableGauge returns an ObservableGauge used to record int64
154 // measurements that produces no telemetry.
155 func (Meter) Float64ObservableGauge(
156 string,
157 ...metric.Float64ObservableGaugeOption,
158 ) (metric.Float64ObservableGauge, error) {
159 return Float64ObservableGauge{}, nil
160 }
161
162 // RegisterCallback performs no operation.
163 func (Meter) RegisterCallback(metric.Callback, ...metric.Observable) (metric.Registration, error) {
164 return Registration{}, nil
165 }
166
167 // Observer acts as a recorder of measurements for multiple instruments in a
168 // Callback, it performing no operation.
169 type Observer struct{ embedded.Observer }
170
171 // ObserveFloat64 performs no operation.
172 func (Observer) ObserveFloat64(metric.Float64Observable, float64, ...metric.ObserveOption) {
173 }
174
175 // ObserveInt64 performs no operation.
176 func (Observer) ObserveInt64(metric.Int64Observable, int64, ...metric.ObserveOption) {
177 }
178
179 // Registration is the registration of a Callback with a No-Op Meter.
180 type Registration struct{ embedded.Registration }
181
182 // Unregister unregisters the Callback the Registration represents with the
183 // No-Op Meter. This will always return nil because the No-Op Meter performs no
184 // operation, including hold any record of registrations.
185 func (Registration) Unregister() error { return nil }
186
187 // Int64Counter is an OpenTelemetry Counter used to record int64 measurements.
188 // It produces no telemetry.
189 type Int64Counter struct{ embedded.Int64Counter }
190
191 // Add performs no operation.
192 func (Int64Counter) Add(context.Context, int64, ...metric.AddOption) {}
193
194 // Enabled performs no operation.
195 func (Int64Counter) Enabled(context.Context) bool { return false }
196
197 // Float64Counter is an OpenTelemetry Counter used to record float64
198 // measurements. It produces no telemetry.
199 type Float64Counter struct{ embedded.Float64Counter }
200
201 // Add performs no operation.
202 func (Float64Counter) Add(context.Context, float64, ...metric.AddOption) {}
203
204 // Enabled performs no operation.
205 func (Float64Counter) Enabled(context.Context) bool { return false }
206
207 // Int64UpDownCounter is an OpenTelemetry UpDownCounter used to record int64
208 // measurements. It produces no telemetry.
209 type Int64UpDownCounter struct{ embedded.Int64UpDownCounter }
210
211 // Add performs no operation.
212 func (Int64UpDownCounter) Add(context.Context, int64, ...metric.AddOption) {}
213
214 // Enabled performs no operation.
215 func (Int64UpDownCounter) Enabled(context.Context) bool { return false }
216
217 // Float64UpDownCounter is an OpenTelemetry UpDownCounter used to record
218 // float64 measurements. It produces no telemetry.
219 type Float64UpDownCounter struct{ embedded.Float64UpDownCounter }
220
221 // Add performs no operation.
222 func (Float64UpDownCounter) Add(context.Context, float64, ...metric.AddOption) {}
223
224 // Enabled performs no operation.
225 func (Float64UpDownCounter) Enabled(context.Context) bool { return false }
226
227 // Int64Histogram is an OpenTelemetry Histogram used to record int64
228 // measurements. It produces no telemetry.
229 type Int64Histogram struct{ embedded.Int64Histogram }
230
231 // Record performs no operation.
232 func (Int64Histogram) Record(context.Context, int64, ...metric.RecordOption) {}
233
234 // Enabled performs no operation.
235 func (Int64Histogram) Enabled(context.Context) bool { return false }
236
237 // Float64Histogram is an OpenTelemetry Histogram used to record float64
238 // measurements. It produces no telemetry.
239 type Float64Histogram struct{ embedded.Float64Histogram }
240
241 // Record performs no operation.
242 func (Float64Histogram) Record(context.Context, float64, ...metric.RecordOption) {}
243
244 // Enabled performs no operation.
245 func (Float64Histogram) Enabled(context.Context) bool { return false }
246
247 // Int64Gauge is an OpenTelemetry Gauge used to record instantaneous int64
248 // measurements. It produces no telemetry.
249 type Int64Gauge struct{ embedded.Int64Gauge }
250
251 // Record performs no operation.
252 func (Int64Gauge) Record(context.Context, int64, ...metric.RecordOption) {}
253
254 // Enabled performs no operation.
255 func (Int64Gauge) Enabled(context.Context) bool { return false }
256
257 // Float64Gauge is an OpenTelemetry Gauge used to record instantaneous float64
258 // measurements. It produces no telemetry.
259 type Float64Gauge struct{ embedded.Float64Gauge }
260
261 // Record performs no operation.
262 func (Float64Gauge) Record(context.Context, float64, ...metric.RecordOption) {}
263
264 // Enabled performs no operation.
265 func (Float64Gauge) Enabled(context.Context) bool { return false }
266
267 // Int64ObservableCounter is an OpenTelemetry ObservableCounter used to record
268 // int64 measurements. It produces no telemetry.
269 type Int64ObservableCounter struct {
270 metric.Int64Observable
271 embedded.Int64ObservableCounter
272 }
273
274 // Float64ObservableCounter is an OpenTelemetry ObservableCounter used to record
275 // float64 measurements. It produces no telemetry.
276 type Float64ObservableCounter struct {
277 metric.Float64Observable
278 embedded.Float64ObservableCounter
279 }
280
281 // Int64ObservableGauge is an OpenTelemetry ObservableGauge used to record
282 // int64 measurements. It produces no telemetry.
283 type Int64ObservableGauge struct {
284 metric.Int64Observable
285 embedded.Int64ObservableGauge
286 }
287
288 // Float64ObservableGauge is an OpenTelemetry ObservableGauge used to record
289 // float64 measurements. It produces no telemetry.
290 type Float64ObservableGauge struct {
291 metric.Float64Observable
292 embedded.Float64ObservableGauge
293 }
294
295 // Int64ObservableUpDownCounter is an OpenTelemetry ObservableUpDownCounter
296 // used to record int64 measurements. It produces no telemetry.
297 type Int64ObservableUpDownCounter struct {
298 metric.Int64Observable
299 embedded.Int64ObservableUpDownCounter
300 }
301
302 // Float64ObservableUpDownCounter is an OpenTelemetry ObservableUpDownCounter
303 // used to record float64 measurements. It produces no telemetry.
304 type Float64ObservableUpDownCounter struct {
305 metric.Float64Observable
306 embedded.Float64ObservableUpDownCounter
307 }
308
309 // Int64Observer is a recorder of int64 measurements that performs no operation.
310 type Int64Observer struct{ embedded.Int64Observer }
311
312 // Observe performs no operation.
313 func (Int64Observer) Observe(int64, ...metric.ObserveOption) {}
314
315 // Float64Observer is a recorder of float64 measurements that performs no
316 // operation.
317 type Float64Observer struct{ embedded.Float64Observer }
318
319 // Observe performs no operation.
320 func (Float64Observer) Observe(float64, ...metric.ObserveOption) {}