-
Notifications
You must be signed in to change notification settings - Fork 0
/
otelauto.go
312 lines (268 loc) · 11.9 KB
/
otelauto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package otelauto
// Package otelauto provides alternative and more handy constructors for the fundamental
// OpenTelemetry metric types inspired by github.com/prometheus/client_golang/prometheus/promauto.
// All constructors panic if the registration fails.
//
// The following example is a complete program to create a counter:
//
// package main
//
// import (
// "ctx"
//
// "github.com/mahboubii/otelauto"
// )
//
// var counter = Int64Counter("my.counter")
//
// func main() {
// counter.Add(context.Background(), 1)
// }
//
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
)
// Int64Counter returns a new instrument identified by name and configured
// with options. The instrument is used to synchronously record increasing
// int64 measurements during a computational operation.
func Int64Counter(name string, opts ...metric.Int64CounterOption) metric.Int64Counter {
return withDefault().Int64Counter(name, opts...)
}
// Int64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// int64 measurements during a computational operation.
func Int64UpDownCounter(name string, opts ...metric.Int64UpDownCounterOption) metric.Int64UpDownCounter {
return withDefault().Int64UpDownCounter(name, opts...)
}
// Int64Histogram returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// the distribution of int64 measurements during a computational operation.
func Int64Histogram(name string, opts ...metric.Int64HistogramOption) metric.Int64Histogram {
return withDefault().Int64Histogram(name, opts...)
}
// Int64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing int64 measurements once per a measurement collection cycle.
func Int64ObservableCounter(name string, opts ...metric.Int64ObservableCounterOption) metric.Int64ObservableCounter {
return withDefault().Int64ObservableCounter(name, opts...)
}
// Int64ObservableUpDownCounter returns a new instrument identified by name
// and configured with options. The instrument is used to asynchronously
// record int64 measurements once per a measurement collection cycle.
func Int64ObservableUpDownCounter(name string, opts ...metric.Int64ObservableUpDownCounterOption) metric.Int64ObservableUpDownCounter {
return withDefault().Int64ObservableUpDownCounter(name, opts...)
}
// Int64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous int64 measurements once per a measurement collection
// cycle.
func Int64ObservableGauge(name string, opts ...metric.Int64ObservableGaugeOption) metric.Int64ObservableGauge {
return withDefault().Int64ObservableGauge(name, opts...)
}
// Float64Counter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// increasing float64 measurements during a computational operation.
func Float64Counter(name string, opts ...metric.Float64CounterOption) metric.Float64Counter {
return withDefault().Float64Counter(name, opts...)
}
// Float64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// float64 measurements during a computational operation.
func Float64UpDownCounter(name string, opts ...metric.Float64UpDownCounterOption) metric.Float64UpDownCounter {
return withDefault().Float64UpDownCounter(name, opts...)
}
// Float64Histogram returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// the distribution of float64 measurements during a computational
// operation.
func Float64Histogram(name string, opts ...metric.Float64HistogramOption) metric.Float64Histogram {
return withDefault().Float64Histogram(name, opts...)
}
// Float64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing float64 measurements once per a measurement collection cycle.
func Float64ObservableCounter(name string, opts ...metric.Float64ObservableCounterOption) metric.Float64ObservableCounter {
return withDefault().Float64ObservableCounter(name, opts...)
}
// Float64ObservableUpDownCounter returns a new instrument identified by
// name and configured with options. The instrument is used to
// asynchronously record float64 measurements once per a measurement
// collection cycle.
func Float64ObservableUpDownCounter(name string, opts ...metric.Float64ObservableUpDownCounterOption) metric.Float64ObservableUpDownCounter {
return withDefault().Float64ObservableUpDownCounter(name, opts...)
}
// Float64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous float64 measurements once per a measurement collection
// cycle.
func Float64ObservableGauge(name string, opts ...metric.Float64ObservableGaugeOption) metric.Float64ObservableGauge {
return withDefault().Float64ObservableGauge(name, opts...)
}
// RegisterCallback registers f to be called during the collection of a
// measurement cycle.
//
// If Unregister of the returned Registration is called, f needs to be
// unregistered and not called during collection.
//
// The instruments f is registered with are the only instruments that f may
// observe values for.
//
// If no instruments are passed, f should not be registered nor called
// during collection.
func RegisterCallback(c metric.Callback, instruments ...metric.Observable) metric.Registration {
return withDefault().RegisterCallback(c, instruments...)
}
type Factory struct {
mp metric.Meter
}
// Int64Counter returns a new instrument identified by name and configured
// with options. The instrument is used to synchronously record increasing
// int64 measurements during a computational operation.
func (f Factory) Int64Counter(name string, opts ...metric.Int64CounterOption) metric.Int64Counter {
i, err := f.mp.Int64Counter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Int64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// int64 measurements during a computational operation.
func (f Factory) Int64UpDownCounter(name string, opts ...metric.Int64UpDownCounterOption) metric.Int64UpDownCounter {
i, err := f.mp.Int64UpDownCounter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Int64Histogram returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// the distribution of int64 measurements during a computational operation.
func (f Factory) Int64Histogram(name string, opts ...metric.Int64HistogramOption) metric.Int64Histogram {
i, err := f.mp.Int64Histogram(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Int64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing int64 measurements once per a measurement collection cycle.
func (f Factory) Int64ObservableCounter(name string, opts ...metric.Int64ObservableCounterOption) metric.Int64ObservableCounter {
i, err := f.mp.Int64ObservableCounter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Int64ObservableUpDownCounter returns a new instrument identified by name
// and configured with options. The instrument is used to asynchronously
// record int64 measurements once per a measurement collection cycle.
func (f Factory) Int64ObservableUpDownCounter(name string, opts ...metric.Int64ObservableUpDownCounterOption) metric.Int64ObservableUpDownCounter {
i, err := f.mp.Int64ObservableUpDownCounter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Int64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous int64 measurements once per a measurement collection
// cycle.
func (f Factory) Int64ObservableGauge(name string, opts ...metric.Int64ObservableGaugeOption) metric.Int64ObservableGauge {
i, err := f.mp.Int64ObservableGauge(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Float64Counter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// increasing float64 measurements during a computational operation.
func (f Factory) Float64Counter(name string, opts ...metric.Float64CounterOption) metric.Float64Counter {
i, err := f.mp.Float64Counter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Float64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// float64 measurements during a computational operation.
func (f Factory) Float64UpDownCounter(name string, opts ...metric.Float64UpDownCounterOption) metric.Float64UpDownCounter {
i, err := f.mp.Float64UpDownCounter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Float64Histogram returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// the distribution of float64 measurements during a computational
// operation.
func (f Factory) Float64Histogram(name string, opts ...metric.Float64HistogramOption) metric.Float64Histogram {
i, err := f.mp.Float64Histogram(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Float64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing float64 measurements once per a measurement collection cycle.
func (f Factory) Float64ObservableCounter(name string, opts ...metric.Float64ObservableCounterOption) metric.Float64ObservableCounter {
i, err := f.mp.Float64ObservableCounter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Float64ObservableUpDownCounter returns a new instrument identified by
// name and configured with options. The instrument is used to
// asynchronously record float64 measurements once per a measurement
// collection cycle.
func (f Factory) Float64ObservableUpDownCounter(name string, opts ...metric.Float64ObservableUpDownCounterOption) metric.Float64ObservableUpDownCounter {
i, err := f.mp.Float64ObservableUpDownCounter(name, opts...)
if err != nil {
panic(err)
}
return i
}
// Float64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous float64 measurements once per a measurement collection
// cycle.
func (f Factory) Float64ObservableGauge(name string, opts ...metric.Float64ObservableGaugeOption) metric.Float64ObservableGauge {
i, err := f.mp.Float64ObservableGauge(name, opts...)
if err != nil {
panic(err)
}
return i
}
// RegisterCallback registers f to be called during the collection of a
// measurement cycle.
//
// If Unregister of the returned Registration is called, f needs to be
// unregistered and not called during collection.
//
// The instruments f is registered with are the only instruments that f may
// observe values for.
//
// If no instruments are passed, f should not be registered nor called
// during collection.
func (f Factory) RegisterCallback(c metric.Callback, instruments ...metric.Observable) metric.Registration {
r, err := f.mp.RegisterCallback(c, instruments...)
if err != nil {
panic(err)
}
return r
}
// With creates a Factory using the provided Meter for registration of the
// created Collectors. If the provided Meter is nil, it will panic.
func With(mp metric.Meter) Factory {
return Factory{mp}
}
func withDefault() Factory {
return With(otel.GetMeterProvider().Meter("github.com/mahboubii/otelauto"))
}