@@ -31,7 +31,6 @@ import {SpanStatusCode} from '@opentelemetry/api';
31
31
32
32
// eslint-disable-next-line n/no-extraneous-require
33
33
const { SimpleSpanProcessor} = require ( '@opentelemetry/sdk-trace-base' ) ;
34
- const { generateWithAllSpansHaveDBName} = require ( './helper' ) ;
35
34
36
35
const fakePfy = extend ( { } , pfy , {
37
36
promisifyAll ( klass , options ) {
@@ -83,6 +82,12 @@ describe('Table', () => {
83
82
84
83
const NAME = 'table-name' ;
85
84
85
+ const ROW = { } ;
86
+
87
+ const mutateRowsOptions = {
88
+ requestOptions : { transactionTag : 'transaction-tag' } ,
89
+ } ;
90
+
86
91
before ( ( ) => {
87
92
Table = proxyquire ( '../src/table.js' , {
88
93
'@google-cloud/promisify' : fakePfy ,
@@ -102,10 +107,6 @@ describe('Table', () => {
102
107
traceExporter . reset ( ) ;
103
108
} ) ;
104
109
105
- const withAllSpansHaveDBName = generateWithAllSpansHaveDBName (
106
- DATABASE . formattedName_
107
- ) ;
108
-
109
110
function getExportedSpans ( minCount : number ) {
110
111
traceExporter . forceFlush ( ) ;
111
112
const spans = traceExporter . getFinishedSpans ( ) ;
@@ -131,6 +132,13 @@ describe('Table', () => {
131
132
return actualSpanNames ;
132
133
}
133
134
135
+ function verifySpanAttributes ( span ) {
136
+ const attributes = span . attributes ;
137
+ assert . strictEqual ( attributes [ 'transaction.tag' ] , 'transaction-tag' ) ;
138
+ assert . strictEqual ( attributes [ 'db.sql.table' ] , 'table-name' ) ;
139
+ assert . strictEqual ( attributes [ 'db.name' ] , 'formatted-db-name' ) ;
140
+ }
141
+
134
142
it ( 'deleteRows' , done => {
135
143
const KEYS = [ 'key' ] ;
136
144
const stub = (
@@ -141,39 +149,39 @@ describe('Table', () => {
141
149
callback ( ) ;
142
150
} ) ;
143
151
144
- table . deleteRows ( KEYS , err => {
152
+ table . deleteRows ( KEYS , mutateRowsOptions , err => {
145
153
assert . ifError ( err ) ;
146
154
assert . strictEqual ( stub . callCount , 1 ) ;
147
- const actualSpanNames = spanNames ( getExportedSpans ( 1 ) ) ;
155
+ const spans = getExportedSpans ( 1 ) ;
156
+ const actualSpanNames = spanNames ( spans ) ;
148
157
const expectedSpanNames = [ 'CloudSpanner.Table.deleteRows' ] ;
149
158
assert . deepStrictEqual (
150
159
actualSpanNames ,
151
160
expectedSpanNames ,
152
161
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
153
162
) ;
154
-
163
+ verifySpanAttributes ( spans [ 0 ] ) ;
155
164
done ( ) ;
156
165
} ) ;
157
166
} ) ;
158
167
159
- const ROW = { } ;
160
-
161
168
it ( 'insert' , done => {
162
169
const stub = (
163
170
sandbox . stub ( transaction , 'insert' ) as sinon . SinonStub
164
171
) . withArgs ( table . name , ROW ) ;
165
172
166
- table . insert ( ROW , err => {
173
+ table . insert ( ROW , mutateRowsOptions , err => {
167
174
assert . ifError ( err ) ;
168
175
assert . strictEqual ( stub . callCount , 1 ) ;
169
- const actualSpanNames = spanNames ( getExportedSpans ( 1 ) ) ;
176
+ const spans = getExportedSpans ( 1 ) ;
177
+ const actualSpanNames = spanNames ( spans ) ;
170
178
const expectedSpanNames = [ 'CloudSpanner.Table.insert' ] ;
171
179
assert . deepStrictEqual (
172
180
actualSpanNames ,
173
181
expectedSpanNames ,
174
182
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
175
183
) ;
176
-
184
+ verifySpanAttributes ( spans [ 0 ] ) ;
177
185
done ( ) ;
178
186
} ) ;
179
187
} ) ;
@@ -184,7 +192,7 @@ describe('Table', () => {
184
192
. stub ( DATABASE , 'runTransaction' )
185
193
. callsFake ( ( opts , callback ) => callback ( fakeError ) ) ;
186
194
187
- table . insert ( ROW , err => {
195
+ table . insert ( ROW , mutateRowsOptions , err => {
188
196
assert . strictEqual ( err , fakeError ) ;
189
197
190
198
const gotSpans = getExportedSpans ( 1 ) ;
@@ -207,7 +215,7 @@ describe('Table', () => {
207
215
expectedSpanNames ,
208
216
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
209
217
) ;
210
-
218
+ verifySpanAttributes ( gotSpans [ 0 ] ) ;
211
219
done ( ) ;
212
220
} ) ;
213
221
} ) ;
@@ -217,12 +225,11 @@ describe('Table', () => {
217
225
sandbox . stub ( transaction , 'upsert' ) as sinon . SinonStub
218
226
) . withArgs ( table . name , ROW ) ;
219
227
220
- table . upsert ( ROW , err => {
228
+ table . upsert ( ROW , mutateRowsOptions , err => {
221
229
assert . ifError ( err ) ;
222
230
assert . strictEqual ( stub . callCount , 1 ) ;
223
231
224
232
const gotSpans = getExportedSpans ( 1 ) ;
225
- withAllSpansHaveDBName ( gotSpans ) ;
226
233
227
234
const actualSpanNames = spanNames ( gotSpans ) ;
228
235
const expectedSpanNames = [ 'CloudSpanner.Table.upsert' ] ;
@@ -232,7 +239,7 @@ describe('Table', () => {
232
239
expectedSpanNames ,
233
240
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
234
241
) ;
235
-
242
+ verifySpanAttributes ( gotSpans [ 0 ] ) ;
236
243
done ( ) ;
237
244
} ) ;
238
245
} ) ;
@@ -243,11 +250,10 @@ describe('Table', () => {
243
250
. stub ( DATABASE , 'runTransaction' )
244
251
. callsFake ( ( opts , callback ) => callback ( fakeError ) ) ;
245
252
246
- table . upsert ( ROW , err => {
253
+ table . upsert ( ROW , mutateRowsOptions , err => {
247
254
assert . strictEqual ( err , fakeError ) ;
248
255
249
256
const gotSpans = getExportedSpans ( 1 ) ;
250
- withAllSpansHaveDBName ( gotSpans ) ;
251
257
252
258
const gotSpanStatus = gotSpans [ 0 ] . status ;
253
259
const wantSpanStatus = {
@@ -268,6 +274,7 @@ describe('Table', () => {
268
274
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
269
275
) ;
270
276
277
+ verifySpanAttributes [ gotSpans [ 0 ] ] ;
271
278
done ( ) ;
272
279
} ) ;
273
280
} ) ;
@@ -277,12 +284,11 @@ describe('Table', () => {
277
284
sandbox . stub ( transaction , 'replace' ) as sinon . SinonStub
278
285
) . withArgs ( table . name , ROW ) ;
279
286
280
- table . replace ( ROW , err => {
287
+ table . replace ( ROW , mutateRowsOptions , err => {
281
288
assert . ifError ( err ) ;
282
289
assert . strictEqual ( stub . callCount , 1 ) ;
283
290
284
291
const gotSpans = getExportedSpans ( 1 ) ;
285
- withAllSpansHaveDBName ( gotSpans ) ;
286
292
287
293
const actualSpanNames = spanNames ( gotSpans ) ;
288
294
const expectedSpanNames = [ 'CloudSpanner.Table.replace' ] ;
@@ -292,6 +298,7 @@ describe('Table', () => {
292
298
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
293
299
) ;
294
300
301
+ verifySpanAttributes ( gotSpans [ 0 ] ) ;
295
302
done ( ) ;
296
303
} ) ;
297
304
} ) ;
@@ -302,7 +309,7 @@ describe('Table', () => {
302
309
. stub ( DATABASE , 'runTransaction' )
303
310
. callsFake ( ( opts , callback ) => callback ( fakeError ) ) ;
304
311
305
- table . replace ( ROW , err => {
312
+ table . replace ( ROW , mutateRowsOptions , err => {
306
313
assert . strictEqual ( err , fakeError ) ;
307
314
const gotSpans = getExportedSpans ( 1 ) ;
308
315
const gotSpanStatus = gotSpans [ 0 ] . status ;
@@ -316,15 +323,14 @@ describe('Table', () => {
316
323
`mismatch in span status:\n\tGot: ${ JSON . stringify ( gotSpanStatus ) } \n\tWant: ${ JSON . stringify ( wantSpanStatus ) } `
317
324
) ;
318
325
319
- withAllSpansHaveDBName ( gotSpans ) ;
320
-
321
326
const actualSpanNames = spanNames ( gotSpans ) ;
322
327
const expectedSpanNames = [ 'CloudSpanner.Table.replace' ] ;
323
328
assert . deepStrictEqual (
324
329
actualSpanNames ,
325
330
expectedSpanNames ,
326
331
`span names mismatch:\n\tGot: ${ actualSpanNames } \n\tWant: ${ expectedSpanNames } `
327
332
) ;
333
+ verifySpanAttributes ( gotSpans [ 0 ] ) ;
328
334
329
335
done ( ) ;
330
336
} ) ;
0 commit comments