77 "context"
88 "testing"
99
10+ "go.opentelemetry.io/otel/attribute"
1011 "go.opentelemetry.io/otel/metric"
1112 "go.opentelemetry.io/otel/metric/embedded"
1213 "go.opentelemetry.io/otel/metric/noop"
@@ -98,29 +99,50 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
9899}
99100
100101func TestSyncInstrumentSetDelegateConcurrentSafe (t * testing.T ) {
102+ alice := attribute .NewSet (attribute .String ("name" , "alice" ))
103+ bob := attribute .NewSet (attribute .String ("name" , "bob" ))
104+ aliceOpt := metric .WithAttributeSet (alice )
105+ bobOpt := metric .WithAttributeSet (bob )
106+
101107 // Float64 Instruments
102108 t .Run ("Float64" , func (* testing.T ) {
103109 t .Run ("Counter" , func (* testing.T ) {
104110 delegate := & sfCounter {}
105- f := func (v float64 ) { delegate .Add (t .Context (), v ) }
111+ f := func (v float64 ) {
112+ delegate .Add (t .Context (), v , bobOpt )
113+ delegate .Add (t .Context (), v , aliceOpt )
114+ delegate .Remove (t .Context (), bobOpt )
115+ }
106116 testFloat64ConcurrentSafe (f , delegate .setDelegate )
107117 })
108118
109119 t .Run ("UpDownCounter" , func (* testing.T ) {
110120 delegate := & sfUpDownCounter {}
111- f := func (v float64 ) { delegate .Add (t .Context (), v ) }
121+ f := func (v float64 ) {
122+ delegate .Add (t .Context (), v , aliceOpt )
123+ delegate .Add (t .Context (), v , bobOpt )
124+ delegate .Remove (t .Context (), aliceOpt )
125+ }
112126 testFloat64ConcurrentSafe (f , delegate .setDelegate )
113127 })
114128
115129 t .Run ("Histogram" , func (* testing.T ) {
116130 delegate := & sfHistogram {}
117- f := func (v float64 ) { delegate .Record (t .Context (), v ) }
131+ f := func (v float64 ) {
132+ delegate .Record (t .Context (), v , aliceOpt )
133+ delegate .Record (t .Context (), v , bobOpt )
134+ delegate .Remove (t .Context (), aliceOpt )
135+ }
118136 testFloat64ConcurrentSafe (f , delegate .setDelegate )
119137 })
120138
121139 t .Run ("Gauge" , func (* testing.T ) {
122140 delegate := & sfGauge {}
123- f := func (v float64 ) { delegate .Record (t .Context (), v ) }
141+ f := func (v float64 ) {
142+ delegate .Record (t .Context (), v , bobOpt )
143+ delegate .Record (t .Context (), v , aliceOpt )
144+ delegate .Remove (t .Context (), bobOpt )
145+ }
124146 testFloat64ConcurrentSafe (f , delegate .setDelegate )
125147 })
126148 })
@@ -130,25 +152,41 @@ func TestSyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
130152 t .Run ("Int64" , func (* testing.T ) {
131153 t .Run ("Counter" , func (* testing.T ) {
132154 delegate := & siCounter {}
133- f := func (v int64 ) { delegate .Add (t .Context (), v ) }
155+ f := func (v int64 ) {
156+ delegate .Add (t .Context (), v , aliceOpt )
157+ delegate .Add (t .Context (), v , bobOpt )
158+ delegate .Remove (t .Context (), aliceOpt )
159+ }
134160 testInt64ConcurrentSafe (f , delegate .setDelegate )
135161 })
136162
137163 t .Run ("UpDownCounter" , func (* testing.T ) {
138164 delegate := & siUpDownCounter {}
139- f := func (v int64 ) { delegate .Add (t .Context (), v ) }
165+ f := func (v int64 ) {
166+ delegate .Add (t .Context (), v , aliceOpt )
167+ delegate .Add (t .Context (), v , bobOpt )
168+ delegate .Remove (t .Context (), aliceOpt )
169+ }
140170 testInt64ConcurrentSafe (f , delegate .setDelegate )
141171 })
142172
143173 t .Run ("Histogram" , func (* testing.T ) {
144174 delegate := & siHistogram {}
145- f := func (v int64 ) { delegate .Record (t .Context (), v ) }
175+ f := func (v int64 ) {
176+ delegate .Record (t .Context (), v , aliceOpt )
177+ delegate .Record (t .Context (), v , bobOpt )
178+ delegate .Remove (t .Context (), aliceOpt )
179+ }
146180 testInt64ConcurrentSafe (f , delegate .setDelegate )
147181 })
148182
149183 t .Run ("Gauge" , func (* testing.T ) {
150184 delegate := & siGauge {}
151- f := func (v int64 ) { delegate .Record (t .Context (), v ) }
185+ f := func (v int64 ) {
186+ delegate .Record (t .Context (), v , aliceOpt )
187+ delegate .Record (t .Context (), v , bobOpt )
188+ delegate .Remove (t .Context (), aliceOpt )
189+ }
152190 testInt64ConcurrentSafe (f , delegate .setDelegate )
153191 })
154192 })
@@ -158,24 +196,27 @@ type testCountingFloatInstrument struct {
158196 count int
159197
160198 metric.Float64Observable
161- embedded.Float64Counter
162199 embedded.Float64UpDownCounter
163200 embedded.Float64Histogram
164201 embedded.Float64Gauge
165- embedded.Float64ObservableCounter
166202 embedded.Float64ObservableUpDownCounter
167203 embedded.Float64ObservableGauge
204+ embedded.Float64Counter
205+ embedded.Float64ObservableCounter
168206}
169207
170208func (i * testCountingFloatInstrument ) observe () {
171209 i .count ++
172210}
173211
174- func (i * testCountingFloatInstrument ) Add (context.Context , float64 , ... metric.AddOption ) {
212+ func (i * testCountingFloatInstrument ) Record (context.Context , float64 , ... metric.RecordOption ) {
175213 i .count ++
176214}
177215
178- func (i * testCountingFloatInstrument ) Record (context.Context , float64 , ... metric.RecordOption ) {
216+ func (* testCountingFloatInstrument ) Remove (context.Context , ... metric.MeasurementOption ) {
217+ }
218+
219+ func (i * testCountingFloatInstrument ) Add (context.Context , float64 , ... metric.AddOption ) {
179220 i .count ++
180221}
181222
@@ -192,11 +233,14 @@ type testCountingIntInstrument struct {
192233 embedded.Int64ObservableGauge
193234}
194235
195- func (i * testCountingIntInstrument ) observe ( ) {
236+ func (i * testCountingIntInstrument ) Add (context. Context , int64 , ... metric. AddOption ) {
196237 i .count ++
197238}
198239
199- func (i * testCountingIntInstrument ) Add (context.Context , int64 , ... metric.AddOption ) {
240+ func (* testCountingIntInstrument ) Remove (context.Context , ... metric.MeasurementOption ) {
241+ }
242+
243+ func (i * testCountingIntInstrument ) observe () {
200244 i .count ++
201245}
202246
0 commit comments