@@ -95,6 +95,8 @@ func TestMeterInstrumentConcurrency(t *testing.T) {
95
95
wg .Wait ()
96
96
}
97
97
98
+ var emptyCallback metric.Callback = func (ctx context.Context ) error { return nil }
99
+
98
100
// A Meter Should be able register Callbacks Concurrently.
99
101
func TestMeterCallbackCreationConcurrency (t * testing.T ) {
100
102
wg := & sync.WaitGroup {}
@@ -103,19 +105,19 @@ func TestMeterCallbackCreationConcurrency(t *testing.T) {
103
105
m := NewMeterProvider ().Meter ("callback-concurrency" )
104
106
105
107
go func () {
106
- _ , _ = m .RegisterCallback ([]instrument.Asynchronous {}, func ( ctx context. Context ) {} )
108
+ _ , _ = m .RegisterCallback ([]instrument.Asynchronous {}, emptyCallback )
107
109
wg .Done ()
108
110
}()
109
111
go func () {
110
- _ , _ = m .RegisterCallback ([]instrument.Asynchronous {}, func ( ctx context. Context ) {} )
112
+ _ , _ = m .RegisterCallback ([]instrument.Asynchronous {}, emptyCallback )
111
113
wg .Done ()
112
114
}()
113
115
wg .Wait ()
114
116
}
115
117
116
118
func TestNoopCallbackUnregisterConcurrency (t * testing.T ) {
117
119
m := NewMeterProvider ().Meter ("noop-unregister-concurrency" )
118
- reg , err := m .RegisterCallback (nil , func ( ctx context. Context ) {} )
120
+ reg , err := m .RegisterCallback (nil , emptyCallback )
119
121
require .NoError (t , err )
120
122
121
123
wg := & sync.WaitGroup {}
@@ -143,11 +145,11 @@ func TestCallbackUnregisterConcurrency(t *testing.T) {
143
145
require .NoError (t , err )
144
146
145
147
i := []instrument.Asynchronous {actr }
146
- regCtr , err := meter .RegisterCallback (i , func ( ctx context. Context ) {} )
148
+ regCtr , err := meter .RegisterCallback (i , emptyCallback )
147
149
require .NoError (t , err )
148
150
149
151
i = []instrument.Asynchronous {ag }
150
- regG , err := meter .RegisterCallback (i , func ( ctx context. Context ) {} )
152
+ regG , err := meter .RegisterCallback (i , emptyCallback )
151
153
require .NoError (t , err )
152
154
153
155
wg := & sync.WaitGroup {}
@@ -183,8 +185,9 @@ func TestMeterCreatesInstruments(t *testing.T) {
183
185
}
184
186
ctr , err := m .Int64ObservableCounter ("aint" , instrument .WithInt64Callback (cback ))
185
187
assert .NoError (t , err )
186
- _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
188
+ _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
187
189
ctr .Observe (ctx , 3 )
190
+ return nil
188
191
})
189
192
assert .NoError (t , err )
190
193
@@ -212,8 +215,9 @@ func TestMeterCreatesInstruments(t *testing.T) {
212
215
}
213
216
ctr , err := m .Int64ObservableUpDownCounter ("aint" , instrument .WithInt64Callback (cback ))
214
217
assert .NoError (t , err )
215
- _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
218
+ _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
216
219
ctr .Observe (ctx , 11 )
220
+ return nil
217
221
})
218
222
assert .NoError (t , err )
219
223
@@ -241,8 +245,9 @@ func TestMeterCreatesInstruments(t *testing.T) {
241
245
}
242
246
gauge , err := m .Int64ObservableGauge ("agauge" , instrument .WithInt64Callback (cback ))
243
247
assert .NoError (t , err )
244
- _ , err = m .RegisterCallback ([]instrument.Asynchronous {gauge }, func (ctx context.Context ) {
248
+ _ , err = m .RegisterCallback ([]instrument.Asynchronous {gauge }, func (ctx context.Context ) error {
245
249
gauge .Observe (ctx , 11 )
250
+ return nil
246
251
})
247
252
assert .NoError (t , err )
248
253
@@ -268,8 +273,9 @@ func TestMeterCreatesInstruments(t *testing.T) {
268
273
}
269
274
ctr , err := m .Float64ObservableCounter ("afloat" , instrument .WithFloat64Callback (cback ))
270
275
assert .NoError (t , err )
271
- _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
276
+ _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
272
277
ctr .Observe (ctx , 3 )
278
+ return nil
273
279
})
274
280
assert .NoError (t , err )
275
281
@@ -297,8 +303,9 @@ func TestMeterCreatesInstruments(t *testing.T) {
297
303
}
298
304
ctr , err := m .Float64ObservableUpDownCounter ("afloat" , instrument .WithFloat64Callback (cback ))
299
305
assert .NoError (t , err )
300
- _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
306
+ _ , err = m .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
301
307
ctr .Observe (ctx , 11 )
308
+ return nil
302
309
})
303
310
assert .NoError (t , err )
304
311
@@ -326,8 +333,9 @@ func TestMeterCreatesInstruments(t *testing.T) {
326
333
}
327
334
gauge , err := m .Float64ObservableGauge ("agauge" , instrument .WithFloat64Callback (cback ))
328
335
assert .NoError (t , err )
329
- _ , err = m .RegisterCallback ([]instrument.Asynchronous {gauge }, func (ctx context.Context ) {
336
+ _ , err = m .RegisterCallback ([]instrument.Asynchronous {gauge }, func (ctx context.Context ) error {
330
337
gauge .Observe (ctx , 11 )
338
+ return nil
331
339
})
332
340
assert .NoError (t , err )
333
341
@@ -501,16 +509,18 @@ func TestMetersProvideScope(t *testing.T) {
501
509
m1 := mp .Meter ("scope1" )
502
510
ctr1 , err := m1 .Float64ObservableCounter ("ctr1" )
503
511
assert .NoError (t , err )
504
- _ , err = m1 .RegisterCallback ([]instrument.Asynchronous {ctr1 }, func (ctx context.Context ) {
512
+ _ , err = m1 .RegisterCallback ([]instrument.Asynchronous {ctr1 }, func (ctx context.Context ) error {
505
513
ctr1 .Observe (ctx , 5 )
514
+ return nil
506
515
})
507
516
assert .NoError (t , err )
508
517
509
518
m2 := mp .Meter ("scope2" )
510
519
ctr2 , err := m2 .Int64ObservableCounter ("ctr2" )
511
520
assert .NoError (t , err )
512
- _ , err = m1 .RegisterCallback ([]instrument.Asynchronous {ctr2 }, func (ctx context.Context ) {
521
+ _ , err = m1 .RegisterCallback ([]instrument.Asynchronous {ctr2 }, func (ctx context.Context ) error {
513
522
ctr2 .Observe (ctx , 7 )
523
+ return nil
514
524
})
515
525
assert .NoError (t , err )
516
526
@@ -594,7 +604,10 @@ func TestUnregisterUnregisters(t *testing.T) {
594
604
floag64Counter ,
595
605
floag64UpDownCounter ,
596
606
floag64Gauge ,
597
- }, func (context.Context ) { called = true })
607
+ }, func (context.Context ) error {
608
+ called = true
609
+ return nil
610
+ })
598
611
require .NoError (t , err )
599
612
600
613
ctx := context .Background ()
@@ -644,7 +657,10 @@ func TestRegisterCallbackDropAggregations(t *testing.T) {
644
657
floag64Counter ,
645
658
floag64UpDownCounter ,
646
659
floag64Gauge ,
647
- }, func (context.Context ) { called = true })
660
+ }, func (context.Context ) error {
661
+ called = true
662
+ return nil
663
+ })
648
664
require .NoError (t , err )
649
665
650
666
data , err := r .Collect (context .Background ())
@@ -669,9 +685,10 @@ func TestAttributeFilter(t *testing.T) {
669
685
if err != nil {
670
686
return err
671
687
}
672
- _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
688
+ _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
673
689
ctr .Observe (ctx , 1.0 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 1 ))
674
690
ctr .Observe (ctx , 2.0 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 2 ))
691
+ return nil
675
692
})
676
693
return err
677
694
},
@@ -696,9 +713,10 @@ func TestAttributeFilter(t *testing.T) {
696
713
if err != nil {
697
714
return err
698
715
}
699
- _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
716
+ _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
700
717
ctr .Observe (ctx , 1.0 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 1 ))
701
718
ctr .Observe (ctx , 2.0 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 2 ))
719
+ return nil
702
720
})
703
721
return err
704
722
},
@@ -723,9 +741,10 @@ func TestAttributeFilter(t *testing.T) {
723
741
if err != nil {
724
742
return err
725
743
}
726
- _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
744
+ _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
727
745
ctr .Observe (ctx , 1.0 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 1 ))
728
746
ctr .Observe (ctx , 2.0 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 2 ))
747
+ return nil
729
748
})
730
749
return err
731
750
},
@@ -748,9 +767,10 @@ func TestAttributeFilter(t *testing.T) {
748
767
if err != nil {
749
768
return err
750
769
}
751
- _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
770
+ _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
752
771
ctr .Observe (ctx , 10 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 1 ))
753
772
ctr .Observe (ctx , 20 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 2 ))
773
+ return nil
754
774
})
755
775
return err
756
776
},
@@ -775,9 +795,10 @@ func TestAttributeFilter(t *testing.T) {
775
795
if err != nil {
776
796
return err
777
797
}
778
- _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
798
+ _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
779
799
ctr .Observe (ctx , 10 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 1 ))
780
800
ctr .Observe (ctx , 20 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 2 ))
801
+ return nil
781
802
})
782
803
return err
783
804
},
@@ -802,9 +823,10 @@ func TestAttributeFilter(t *testing.T) {
802
823
if err != nil {
803
824
return err
804
825
}
805
- _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) {
826
+ _ , err = mtr .RegisterCallback ([]instrument.Asynchronous {ctr }, func (ctx context.Context ) error {
806
827
ctr .Observe (ctx , 10 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 1 ))
807
828
ctr .Observe (ctx , 20 , attribute .String ("foo" , "bar" ), attribute .Int ("version" , 2 ))
829
+ return nil
808
830
})
809
831
return err
810
832
},
0 commit comments