@@ -39,6 +39,7 @@ import {
39
39
io ,
40
40
getSocketIoSpans ,
41
41
expectSpan ,
42
+ expectSpans ,
42
43
isV2 ,
43
44
} from './utils' ;
44
45
@@ -56,7 +57,7 @@ describe('SocketIoInstrumentation', () => {
56
57
it ( 'emit is instrumented' , ( ) => {
57
58
const io = createServerInstance ( ) ;
58
59
io . emit ( 'test' ) ;
59
- expectSpan ( '/ send' , span => {
60
+ expectSpan ( 'send / ' , span => {
60
61
expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
61
62
expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual ( 'socket.io' ) ;
62
63
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION_KIND ] ) . toEqual (
@@ -87,14 +88,14 @@ describe('SocketIoInstrumentation', () => {
87
88
} catch ( error ) { }
88
89
if ( isV2 ) {
89
90
// only for v2: connect do not throw, but are just ignored
90
- return expectSpan ( '/ send' , span => {
91
+ return expectSpan ( 'send / ' , span => {
91
92
expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
92
93
expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual (
93
94
'socket.io'
94
95
) ;
95
96
} ) ;
96
97
}
97
- expectSpan ( '/ send' , span => {
98
+ expectSpan ( 'send / ' , span => {
98
99
expect ( span . status . code ) . toEqual ( SpanStatusCode . ERROR ) ;
99
100
expect ( span . status . message ) . toEqual (
100
101
'"connect" is a reserved event name'
@@ -105,7 +106,7 @@ describe('SocketIoInstrumentation', () => {
105
106
it ( 'send is instrumented' , ( ) => {
106
107
const io = createServerInstance ( ) ;
107
108
io . send ( 'test' ) ;
108
- expectSpan ( '/ send' , span => {
109
+ expectSpan ( 'send / ' , span => {
109
110
expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
110
111
expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual ( 'socket.io' ) ;
111
112
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION_KIND ] ) . toEqual (
@@ -125,7 +126,7 @@ describe('SocketIoInstrumentation', () => {
125
126
126
127
const io = createServerInstance ( ) ;
127
128
io . emit ( 'test' , 1234 ) ;
128
- expectSpan ( '/ send' , span => {
129
+ expectSpan ( 'send / ' , span => {
129
130
expect ( span . attributes [ 'payload' ] ) . toEqual ( JSON . stringify ( [ 1234 ] ) ) ;
130
131
} ) ;
131
132
} ) ;
@@ -164,17 +165,22 @@ describe('SocketIoInstrumentation', () => {
164
165
socket . on ( 'test_reply' , data => {
165
166
client . close ( ) ;
166
167
sio . close ( ) ;
168
+
167
169
//trace is created after the listener method is completed
168
170
setTimeout ( ( ) => {
169
- expectSpan (
170
- 'test_reply receive' ,
171
- span => {
171
+ expectSpans (
172
+ 'receive / ' ,
173
+ spans => {
172
174
try {
173
- expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
174
- expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual (
175
- 'socket.io'
176
- ) ;
177
- expect ( span . attributes [ 'payload' ] ) . toEqual (
175
+ expect ( spans [ 0 ] . kind ) . toEqual ( SpanKind . CONSUMER ) ;
176
+ expect (
177
+ spans [ 0 ] . attributes [ SEMATTRS_MESSAGING_SYSTEM ]
178
+ ) . toEqual ( 'socket.io' ) ;
179
+ expect ( spans [ 1 ] . kind ) . toEqual ( SpanKind . CONSUMER ) ;
180
+ expect (
181
+ spans [ 1 ] . attributes [ SEMATTRS_MESSAGING_SYSTEM ]
182
+ ) . toEqual ( 'socket.io' ) ;
183
+ expect ( spans [ 1 ] . attributes [ 'payload' ] ) . toEqual (
178
184
JSON . stringify ( [ data ] )
179
185
) ;
180
186
done ( ) ;
@@ -207,7 +213,7 @@ describe('SocketIoInstrumentation', () => {
207
213
sio . on ( 'connection' , ( ) => {
208
214
//trace is created after the listener method is completed
209
215
setTimeout ( ( ) => {
210
- expectSpan ( 'connection receive' , span => {
216
+ expectSpan ( 'receive / ' , span => {
211
217
expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
212
218
expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual (
213
219
'socket.io'
@@ -238,7 +244,7 @@ describe('SocketIoInstrumentation', () => {
238
244
//trace is created after the listener method is completed
239
245
setTimeout ( ( ) => {
240
246
expectSpan (
241
- 'test_reply receive' ,
247
+ 'receive / ' ,
242
248
span => {
243
249
try {
244
250
expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
@@ -291,7 +297,7 @@ describe('SocketIoInstrumentation', () => {
291
297
const roomName = 'room' ;
292
298
const sio = createServerInstance ( ) ;
293
299
sio . to ( roomName ) . emit ( 'broadcast' , '1234' ) ;
294
- expectSpan ( '/[room] send' , span => {
300
+ expectSpan ( 'send / ' , span => {
295
301
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual ( '/' ) ;
296
302
expect (
297
303
span . attributes [ SocketIoInstrumentationAttributes . SOCKET_IO_ROOMS ]
@@ -302,7 +308,7 @@ describe('SocketIoInstrumentation', () => {
302
308
it ( 'broadcast to multiple rooms' , ( ) => {
303
309
const sio = createServerInstance ( ) ;
304
310
sio . to ( 'room1' ) . to ( 'room2' ) . emit ( 'broadcast' , '1234' ) ;
305
- expectSpan ( '/[room1,room2] send' , span => {
311
+ expectSpan ( 'send / ' , span => {
306
312
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual ( '/' ) ;
307
313
expect (
308
314
span . attributes [ SocketIoInstrumentationAttributes . SOCKET_IO_ROOMS ]
@@ -316,7 +322,7 @@ describe('SocketIoInstrumentation', () => {
316
322
const io = createServerInstance ( ) ;
317
323
const namespace = io . of ( '/testing' ) ;
318
324
namespace . emit ( 'namespace' ) ;
319
- expectSpan ( '/testing send ' , span => {
325
+ expectSpan ( 'send /testing' , span => {
320
326
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
321
327
'/testing'
322
328
) ;
@@ -331,7 +337,7 @@ describe('SocketIoInstrumentation', () => {
331
337
const io = createServerInstance ( ) ;
332
338
const namespace = io . of ( '/testing' ) ;
333
339
namespace . to ( roomName ) . emit ( 'broadcast' , '1234' ) ;
334
- expectSpan ( '/testing[room] send ' , span => {
340
+ expectSpan ( 'send /testing' , span => {
335
341
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
336
342
'/testing'
337
343
) ;
@@ -348,7 +354,7 @@ describe('SocketIoInstrumentation', () => {
348
354
const io = createServerInstance ( ) ;
349
355
const namespace = io . of ( '/testing' ) ;
350
356
namespace . to ( 'room1' ) . to ( 'room2' ) . emit ( 'broadcast' , '1234' ) ;
351
- expectSpan ( '/testing[room1,room2] send ' , span => {
357
+ expectSpan ( 'send /testing' , span => {
352
358
expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
353
359
'/testing'
354
360
) ;
@@ -379,7 +385,7 @@ describe('SocketIoInstrumentation', () => {
379
385
//trace is created after the listener method is completed
380
386
setTimeout ( ( ) => {
381
387
expectSpan (
382
- '/testing test_reply receive ' ,
388
+ 'receive /testing' ,
383
389
span => {
384
390
try {
385
391
expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
@@ -421,7 +427,7 @@ describe('SocketIoInstrumentation', () => {
421
427
client . close ( ) ;
422
428
sio . close ( ) ;
423
429
expectSpan (
424
- `/[ ${ socket . id } ] send` ,
430
+ ' send /' ,
425
431
span => {
426
432
try {
427
433
expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
0 commit comments