@@ -174,8 +174,18 @@ func TestMeterCreatesInstruments(t *testing.T) {
174
174
ctx , cancel := context .WithCancel (context .Background ())
175
175
cancel ()
176
176
177
- attrs := attribute .NewSet (attribute .String ("name" , "alice" ))
178
- opt := metric .WithAttributeSet (attrs )
177
+ alice := attribute .NewSet (
178
+ attribute .String ("name" , "Alice" ),
179
+ attribute .Bool ("admin" , true ),
180
+ )
181
+ optAlice := metric .WithAttributeSet (alice )
182
+
183
+ bob := attribute .NewSet (
184
+ attribute .String ("name" , "Bob" ),
185
+ attribute .Bool ("admin" , false ),
186
+ )
187
+ optBob := metric .WithAttributeSet (bob )
188
+
179
189
testCases := []struct {
180
190
name string
181
191
fn func (* testing.T , metric.Meter )
@@ -184,11 +194,17 @@ func TestMeterCreatesInstruments(t *testing.T) {
184
194
{
185
195
name : "ObservableInt64Count" ,
186
196
fn : func (t * testing.T , m metric.Meter ) {
187
- cback := func (_ context.Context , o metric.Int64Observer ) error {
188
- o .Observe (4 , opt )
189
- return nil
190
- }
191
- ctr , err := m .Int64ObservableCounter ("aint" , metric .WithInt64Callback (cback ))
197
+ ctr , err := m .Int64ObservableCounter (
198
+ "aint" ,
199
+ metric .WithInt64Callback (func (_ context.Context , o metric.Int64Observer ) error {
200
+ o .Observe (4 , optAlice )
201
+ return nil
202
+ }),
203
+ metric .WithInt64Callback (func (_ context.Context , o metric.Int64Observer ) error {
204
+ o .Observe (5 , optBob )
205
+ return nil
206
+ }),
207
+ )
192
208
assert .NoError (t , err )
193
209
_ , err = m .RegisterCallback (func (_ context.Context , o metric.Observer ) error {
194
210
o .ObserveInt64 (ctr , 3 )
@@ -202,7 +218,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
202
218
Temporality : metricdata .CumulativeTemporality ,
203
219
IsMonotonic : true ,
204
220
DataPoints : []metricdata.DataPoint [int64 ]{
205
- {Attributes : attrs , Value : 4 },
221
+ {Attributes : alice , Value : 4 },
222
+ {Attributes : bob , Value : 5 },
206
223
{Value : 3 },
207
224
},
208
225
},
@@ -211,11 +228,17 @@ func TestMeterCreatesInstruments(t *testing.T) {
211
228
{
212
229
name : "ObservableInt64UpDownCount" ,
213
230
fn : func (t * testing.T , m metric.Meter ) {
214
- cback := func (_ context.Context , o metric.Int64Observer ) error {
215
- o .Observe (4 , opt )
216
- return nil
217
- }
218
- ctr , err := m .Int64ObservableUpDownCounter ("aint" , metric .WithInt64Callback (cback ))
231
+ ctr , err := m .Int64ObservableUpDownCounter (
232
+ "aint" ,
233
+ metric .WithInt64Callback (func (_ context.Context , o metric.Int64Observer ) error {
234
+ o .Observe (4 , optAlice )
235
+ return nil
236
+ }),
237
+ metric .WithInt64Callback (func (_ context.Context , o metric.Int64Observer ) error {
238
+ o .Observe (5 , optBob )
239
+ return nil
240
+ }),
241
+ )
219
242
assert .NoError (t , err )
220
243
_ , err = m .RegisterCallback (func (_ context.Context , o metric.Observer ) error {
221
244
o .ObserveInt64 (ctr , 11 )
@@ -229,7 +252,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
229
252
Temporality : metricdata .CumulativeTemporality ,
230
253
IsMonotonic : false ,
231
254
DataPoints : []metricdata.DataPoint [int64 ]{
232
- {Attributes : attrs , Value : 4 },
255
+ {Attributes : alice , Value : 4 },
256
+ {Attributes : bob , Value : 5 },
233
257
{Value : 11 },
234
258
},
235
259
},
@@ -238,11 +262,17 @@ func TestMeterCreatesInstruments(t *testing.T) {
238
262
{
239
263
name : "ObservableInt64Gauge" ,
240
264
fn : func (t * testing.T , m metric.Meter ) {
241
- cback := func (_ context.Context , o metric.Int64Observer ) error {
242
- o .Observe (4 , opt )
243
- return nil
244
- }
245
- gauge , err := m .Int64ObservableGauge ("agauge" , metric .WithInt64Callback (cback ))
265
+ gauge , err := m .Int64ObservableGauge (
266
+ "agauge" ,
267
+ metric .WithInt64Callback (func (_ context.Context , o metric.Int64Observer ) error {
268
+ o .Observe (4 , optAlice )
269
+ return nil
270
+ }),
271
+ metric .WithInt64Callback (func (_ context.Context , o metric.Int64Observer ) error {
272
+ o .Observe (5 , optBob )
273
+ return nil
274
+ }),
275
+ )
246
276
assert .NoError (t , err )
247
277
_ , err = m .RegisterCallback (func (_ context.Context , o metric.Observer ) error {
248
278
o .ObserveInt64 (gauge , 11 )
@@ -254,7 +284,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
254
284
Name : "agauge" ,
255
285
Data : metricdata.Gauge [int64 ]{
256
286
DataPoints : []metricdata.DataPoint [int64 ]{
257
- {Attributes : attrs , Value : 4 },
287
+ {Attributes : alice , Value : 4 },
288
+ {Attributes : bob , Value : 5 },
258
289
{Value : 11 },
259
290
},
260
291
},
@@ -263,11 +294,17 @@ func TestMeterCreatesInstruments(t *testing.T) {
263
294
{
264
295
name : "ObservableFloat64Count" ,
265
296
fn : func (t * testing.T , m metric.Meter ) {
266
- cback := func (_ context.Context , o metric.Float64Observer ) error {
267
- o .Observe (4 , opt )
268
- return nil
269
- }
270
- ctr , err := m .Float64ObservableCounter ("afloat" , metric .WithFloat64Callback (cback ))
297
+ ctr , err := m .Float64ObservableCounter (
298
+ "afloat" ,
299
+ metric .WithFloat64Callback (func (_ context.Context , o metric.Float64Observer ) error {
300
+ o .Observe (4 , optAlice )
301
+ return nil
302
+ }),
303
+ metric .WithFloat64Callback (func (_ context.Context , o metric.Float64Observer ) error {
304
+ o .Observe (5 , optBob )
305
+ return nil
306
+ }),
307
+ )
271
308
assert .NoError (t , err )
272
309
_ , err = m .RegisterCallback (func (_ context.Context , o metric.Observer ) error {
273
310
o .ObserveFloat64 (ctr , 3 )
@@ -281,7 +318,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
281
318
Temporality : metricdata .CumulativeTemporality ,
282
319
IsMonotonic : true ,
283
320
DataPoints : []metricdata.DataPoint [float64 ]{
284
- {Attributes : attrs , Value : 4 },
321
+ {Attributes : alice , Value : 4 },
322
+ {Attributes : bob , Value : 5 },
285
323
{Value : 3 },
286
324
},
287
325
},
@@ -290,11 +328,17 @@ func TestMeterCreatesInstruments(t *testing.T) {
290
328
{
291
329
name : "ObservableFloat64UpDownCount" ,
292
330
fn : func (t * testing.T , m metric.Meter ) {
293
- cback := func (_ context.Context , o metric.Float64Observer ) error {
294
- o .Observe (4 , opt )
295
- return nil
296
- }
297
- ctr , err := m .Float64ObservableUpDownCounter ("afloat" , metric .WithFloat64Callback (cback ))
331
+ ctr , err := m .Float64ObservableUpDownCounter (
332
+ "afloat" ,
333
+ metric .WithFloat64Callback (func (_ context.Context , o metric.Float64Observer ) error {
334
+ o .Observe (4 , optAlice )
335
+ return nil
336
+ }),
337
+ metric .WithFloat64Callback (func (_ context.Context , o metric.Float64Observer ) error {
338
+ o .Observe (5 , optBob )
339
+ return nil
340
+ }),
341
+ )
298
342
assert .NoError (t , err )
299
343
_ , err = m .RegisterCallback (func (_ context.Context , o metric.Observer ) error {
300
344
o .ObserveFloat64 (ctr , 11 )
@@ -308,7 +352,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
308
352
Temporality : metricdata .CumulativeTemporality ,
309
353
IsMonotonic : false ,
310
354
DataPoints : []metricdata.DataPoint [float64 ]{
311
- {Attributes : attrs , Value : 4 },
355
+ {Attributes : alice , Value : 4 },
356
+ {Attributes : bob , Value : 5 },
312
357
{Value : 11 },
313
358
},
314
359
},
@@ -317,11 +362,17 @@ func TestMeterCreatesInstruments(t *testing.T) {
317
362
{
318
363
name : "ObservableFloat64Gauge" ,
319
364
fn : func (t * testing.T , m metric.Meter ) {
320
- cback := func (_ context.Context , o metric.Float64Observer ) error {
321
- o .Observe (4 , opt )
322
- return nil
323
- }
324
- gauge , err := m .Float64ObservableGauge ("agauge" , metric .WithFloat64Callback (cback ))
365
+ gauge , err := m .Float64ObservableGauge (
366
+ "agauge" ,
367
+ metric .WithFloat64Callback (func (_ context.Context , o metric.Float64Observer ) error {
368
+ o .Observe (4 , optAlice )
369
+ return nil
370
+ }),
371
+ metric .WithFloat64Callback (func (_ context.Context , o metric.Float64Observer ) error {
372
+ o .Observe (5 , optBob )
373
+ return nil
374
+ }),
375
+ )
325
376
assert .NoError (t , err )
326
377
_ , err = m .RegisterCallback (func (_ context.Context , o metric.Observer ) error {
327
378
o .ObserveFloat64 (gauge , 11 )
@@ -333,7 +384,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
333
384
Name : "agauge" ,
334
385
Data : metricdata.Gauge [float64 ]{
335
386
DataPoints : []metricdata.DataPoint [float64 ]{
336
- {Attributes : attrs , Value : 4 },
387
+ {Attributes : alice , Value : 4 },
388
+ {Attributes : bob , Value : 5 },
337
389
{Value : 11 },
338
390
},
339
391
},
0 commit comments