@@ -5,6 +5,7 @@ package global // import "go.opentelemetry.io/otel/internal/global"
5
5
6
6
import (
7
7
"container/list"
8
+ "reflect"
8
9
"sync"
9
10
"sync/atomic"
10
11
@@ -76,7 +77,7 @@ func (p *meterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me
76
77
return val
77
78
}
78
79
79
- t := & meter {name : name , opts : opts }
80
+ t := & meter {name : name , opts : opts , instruments : make ( map [ instID ] delegatedInstrument ) }
80
81
p .meters [key ] = t
81
82
return t
82
83
}
@@ -92,7 +93,7 @@ type meter struct {
92
93
opts []metric.MeterOption
93
94
94
95
mtx sync.Mutex
95
- instruments [ ]delegatedInstrument
96
+ instruments map [ instID ]delegatedInstrument
96
97
97
98
registry list.List
98
99
@@ -103,6 +104,18 @@ type delegatedInstrument interface {
103
104
setDelegate (metric.Meter )
104
105
}
105
106
107
+ // instID are the identifying properties of a instrument.
108
+ type instID struct {
109
+ // name is the name of the stream.
110
+ name string
111
+ // description is the description of the stream.
112
+ description string
113
+ // kind defines the functional group of the instrument.
114
+ kind reflect.Type
115
+ // unit is the unit of the stream.
116
+ unit string
117
+ }
118
+
106
119
// setDelegate configures m to delegate all Meter functionality to Meters
107
120
// created by provider.
108
121
//
@@ -139,7 +152,14 @@ func (m *meter) Int64Counter(name string, options ...metric.Int64CounterOption)
139
152
m .mtx .Lock ()
140
153
defer m .mtx .Unlock ()
141
154
i := & siCounter {name : name , opts : options }
142
- m .instruments = append (m .instruments , i )
155
+ cfg := metric .NewInt64CounterConfig (options ... )
156
+ id := instID {
157
+ name : name ,
158
+ kind : reflect .TypeOf (i ),
159
+ description : cfg .Description (),
160
+ unit : cfg .Unit (),
161
+ }
162
+ m .instruments [id ] = i
143
163
return i , nil
144
164
}
145
165
@@ -150,7 +170,14 @@ func (m *meter) Int64UpDownCounter(name string, options ...metric.Int64UpDownCou
150
170
m .mtx .Lock ()
151
171
defer m .mtx .Unlock ()
152
172
i := & siUpDownCounter {name : name , opts : options }
153
- m .instruments = append (m .instruments , i )
173
+ cfg := metric .NewInt64UpDownCounterConfig (options ... )
174
+ id := instID {
175
+ name : name ,
176
+ kind : reflect .TypeOf (i ),
177
+ description : cfg .Description (),
178
+ unit : cfg .Unit (),
179
+ }
180
+ m .instruments [id ] = i
154
181
return i , nil
155
182
}
156
183
@@ -161,7 +188,14 @@ func (m *meter) Int64Histogram(name string, options ...metric.Int64HistogramOpti
161
188
m .mtx .Lock ()
162
189
defer m .mtx .Unlock ()
163
190
i := & siHistogram {name : name , opts : options }
164
- m .instruments = append (m .instruments , i )
191
+ cfg := metric .NewInt64HistogramConfig (options ... )
192
+ id := instID {
193
+ name : name ,
194
+ kind : reflect .TypeOf (i ),
195
+ description : cfg .Description (),
196
+ unit : cfg .Unit (),
197
+ }
198
+ m .instruments [id ] = i
165
199
return i , nil
166
200
}
167
201
@@ -172,7 +206,14 @@ func (m *meter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (met
172
206
m .mtx .Lock ()
173
207
defer m .mtx .Unlock ()
174
208
i := & siGauge {name : name , opts : options }
175
- m .instruments = append (m .instruments , i )
209
+ cfg := metric .NewInt64GaugeConfig (options ... )
210
+ id := instID {
211
+ name : name ,
212
+ kind : reflect .TypeOf (i ),
213
+ description : cfg .Description (),
214
+ unit : cfg .Unit (),
215
+ }
216
+ m .instruments [id ] = i
176
217
return i , nil
177
218
}
178
219
@@ -183,7 +224,14 @@ func (m *meter) Int64ObservableCounter(name string, options ...metric.Int64Obser
183
224
m .mtx .Lock ()
184
225
defer m .mtx .Unlock ()
185
226
i := & aiCounter {name : name , opts : options }
186
- m .instruments = append (m .instruments , i )
227
+ cfg := metric .NewInt64ObservableCounterConfig (options ... )
228
+ id := instID {
229
+ name : name ,
230
+ kind : reflect .TypeOf (i ),
231
+ description : cfg .Description (),
232
+ unit : cfg .Unit (),
233
+ }
234
+ m .instruments [id ] = i
187
235
return i , nil
188
236
}
189
237
@@ -194,7 +242,14 @@ func (m *meter) Int64ObservableUpDownCounter(name string, options ...metric.Int6
194
242
m .mtx .Lock ()
195
243
defer m .mtx .Unlock ()
196
244
i := & aiUpDownCounter {name : name , opts : options }
197
- m .instruments = append (m .instruments , i )
245
+ cfg := metric .NewInt64ObservableUpDownCounterConfig (options ... )
246
+ id := instID {
247
+ name : name ,
248
+ kind : reflect .TypeOf (i ),
249
+ description : cfg .Description (),
250
+ unit : cfg .Unit (),
251
+ }
252
+ m .instruments [id ] = i
198
253
return i , nil
199
254
}
200
255
@@ -205,7 +260,14 @@ func (m *meter) Int64ObservableGauge(name string, options ...metric.Int64Observa
205
260
m .mtx .Lock ()
206
261
defer m .mtx .Unlock ()
207
262
i := & aiGauge {name : name , opts : options }
208
- m .instruments = append (m .instruments , i )
263
+ cfg := metric .NewInt64ObservableGaugeConfig (options ... )
264
+ id := instID {
265
+ name : name ,
266
+ kind : reflect .TypeOf (i ),
267
+ description : cfg .Description (),
268
+ unit : cfg .Unit (),
269
+ }
270
+ m .instruments [id ] = i
209
271
return i , nil
210
272
}
211
273
@@ -216,7 +278,14 @@ func (m *meter) Float64Counter(name string, options ...metric.Float64CounterOpti
216
278
m .mtx .Lock ()
217
279
defer m .mtx .Unlock ()
218
280
i := & sfCounter {name : name , opts : options }
219
- m .instruments = append (m .instruments , i )
281
+ cfg := metric .NewFloat64CounterConfig (options ... )
282
+ id := instID {
283
+ name : name ,
284
+ kind : reflect .TypeOf (i ),
285
+ description : cfg .Description (),
286
+ unit : cfg .Unit (),
287
+ }
288
+ m .instruments [id ] = i
220
289
return i , nil
221
290
}
222
291
@@ -227,7 +296,14 @@ func (m *meter) Float64UpDownCounter(name string, options ...metric.Float64UpDow
227
296
m .mtx .Lock ()
228
297
defer m .mtx .Unlock ()
229
298
i := & sfUpDownCounter {name : name , opts : options }
230
- m .instruments = append (m .instruments , i )
299
+ cfg := metric .NewFloat64UpDownCounterConfig (options ... )
300
+ id := instID {
301
+ name : name ,
302
+ kind : reflect .TypeOf (i ),
303
+ description : cfg .Description (),
304
+ unit : cfg .Unit (),
305
+ }
306
+ m .instruments [id ] = i
231
307
return i , nil
232
308
}
233
309
@@ -238,7 +314,14 @@ func (m *meter) Float64Histogram(name string, options ...metric.Float64Histogram
238
314
m .mtx .Lock ()
239
315
defer m .mtx .Unlock ()
240
316
i := & sfHistogram {name : name , opts : options }
241
- m .instruments = append (m .instruments , i )
317
+ cfg := metric .NewFloat64HistogramConfig (options ... )
318
+ id := instID {
319
+ name : name ,
320
+ kind : reflect .TypeOf (i ),
321
+ description : cfg .Description (),
322
+ unit : cfg .Unit (),
323
+ }
324
+ m .instruments [id ] = i
242
325
return i , nil
243
326
}
244
327
@@ -249,7 +332,14 @@ func (m *meter) Float64Gauge(name string, options ...metric.Float64GaugeOption)
249
332
m .mtx .Lock ()
250
333
defer m .mtx .Unlock ()
251
334
i := & sfGauge {name : name , opts : options }
252
- m .instruments = append (m .instruments , i )
335
+ cfg := metric .NewFloat64GaugeConfig (options ... )
336
+ id := instID {
337
+ name : name ,
338
+ kind : reflect .TypeOf (i ),
339
+ description : cfg .Description (),
340
+ unit : cfg .Unit (),
341
+ }
342
+ m .instruments [id ] = i
253
343
return i , nil
254
344
}
255
345
@@ -260,7 +350,14 @@ func (m *meter) Float64ObservableCounter(name string, options ...metric.Float64O
260
350
m .mtx .Lock ()
261
351
defer m .mtx .Unlock ()
262
352
i := & afCounter {name : name , opts : options }
263
- m .instruments = append (m .instruments , i )
353
+ cfg := metric .NewFloat64ObservableCounterConfig (options ... )
354
+ id := instID {
355
+ name : name ,
356
+ kind : reflect .TypeOf (i ),
357
+ description : cfg .Description (),
358
+ unit : cfg .Unit (),
359
+ }
360
+ m .instruments [id ] = i
264
361
return i , nil
265
362
}
266
363
@@ -271,7 +368,14 @@ func (m *meter) Float64ObservableUpDownCounter(name string, options ...metric.Fl
271
368
m .mtx .Lock ()
272
369
defer m .mtx .Unlock ()
273
370
i := & afUpDownCounter {name : name , opts : options }
274
- m .instruments = append (m .instruments , i )
371
+ cfg := metric .NewFloat64ObservableUpDownCounterConfig (options ... )
372
+ id := instID {
373
+ name : name ,
374
+ kind : reflect .TypeOf (i ),
375
+ description : cfg .Description (),
376
+ unit : cfg .Unit (),
377
+ }
378
+ m .instruments [id ] = i
275
379
return i , nil
276
380
}
277
381
@@ -282,7 +386,14 @@ func (m *meter) Float64ObservableGauge(name string, options ...metric.Float64Obs
282
386
m .mtx .Lock ()
283
387
defer m .mtx .Unlock ()
284
388
i := & afGauge {name : name , opts : options }
285
- m .instruments = append (m .instruments , i )
389
+ cfg := metric .NewFloat64ObservableGaugeConfig (options ... )
390
+ id := instID {
391
+ name : name ,
392
+ kind : reflect .TypeOf (i ),
393
+ description : cfg .Description (),
394
+ unit : cfg .Unit (),
395
+ }
396
+ m .instruments [id ] = i
286
397
return i , nil
287
398
}
288
399
0 commit comments