@@ -39,6 +39,7 @@ import {
3939 io ,
4040 getSocketIoSpans ,
4141 expectSpan ,
42+ expectSpans ,
4243 isV2 ,
4344} from './utils' ;
4445
@@ -56,7 +57,7 @@ describe('SocketIoInstrumentation', () => {
5657 it ( 'emit is instrumented' , ( ) => {
5758 const io = createServerInstance ( ) ;
5859 io . emit ( 'test' ) ;
59- expectSpan ( '/ send' , span => {
60+ expectSpan ( 'send / ' , span => {
6061 expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
6162 expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual ( 'socket.io' ) ;
6263 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION_KIND ] ) . toEqual (
@@ -87,14 +88,14 @@ describe('SocketIoInstrumentation', () => {
8788 } catch ( error ) { }
8889 if ( isV2 ) {
8990 // only for v2: connect do not throw, but are just ignored
90- return expectSpan ( '/ send' , span => {
91+ return expectSpan ( 'send / ' , span => {
9192 expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
9293 expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual (
9394 'socket.io'
9495 ) ;
9596 } ) ;
9697 }
97- expectSpan ( '/ send' , span => {
98+ expectSpan ( 'send / ' , span => {
9899 expect ( span . status . code ) . toEqual ( SpanStatusCode . ERROR ) ;
99100 expect ( span . status . message ) . toEqual (
100101 '"connect" is a reserved event name'
@@ -105,7 +106,7 @@ describe('SocketIoInstrumentation', () => {
105106 it ( 'send is instrumented' , ( ) => {
106107 const io = createServerInstance ( ) ;
107108 io . send ( 'test' ) ;
108- expectSpan ( '/ send' , span => {
109+ expectSpan ( 'send / ' , span => {
109110 expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
110111 expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual ( 'socket.io' ) ;
111112 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION_KIND ] ) . toEqual (
@@ -125,7 +126,7 @@ describe('SocketIoInstrumentation', () => {
125126
126127 const io = createServerInstance ( ) ;
127128 io . emit ( 'test' , 1234 ) ;
128- expectSpan ( '/ send' , span => {
129+ expectSpan ( 'send / ' , span => {
129130 expect ( span . attributes [ 'payload' ] ) . toEqual ( JSON . stringify ( [ 1234 ] ) ) ;
130131 } ) ;
131132 } ) ;
@@ -164,17 +165,22 @@ describe('SocketIoInstrumentation', () => {
164165 socket . on ( 'test_reply' , data => {
165166 client . close ( ) ;
166167 sio . close ( ) ;
168+
167169 //trace is created after the listener method is completed
168170 setTimeout ( ( ) => {
169- expectSpan (
170- 'test_reply receive' ,
171- span => {
171+ expectSpans (
172+ 'receive / ' ,
173+ spans => {
172174 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 (
178184 JSON . stringify ( [ data ] )
179185 ) ;
180186 done ( ) ;
@@ -207,7 +213,7 @@ describe('SocketIoInstrumentation', () => {
207213 sio . on ( 'connection' , ( ) => {
208214 //trace is created after the listener method is completed
209215 setTimeout ( ( ) => {
210- expectSpan ( 'connection receive' , span => {
216+ expectSpan ( 'receive / ' , span => {
211217 expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
212218 expect ( span . attributes [ SEMATTRS_MESSAGING_SYSTEM ] ) . toEqual (
213219 'socket.io'
@@ -238,7 +244,7 @@ describe('SocketIoInstrumentation', () => {
238244 //trace is created after the listener method is completed
239245 setTimeout ( ( ) => {
240246 expectSpan (
241- 'test_reply receive' ,
247+ 'receive / ' ,
242248 span => {
243249 try {
244250 expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
@@ -291,7 +297,7 @@ describe('SocketIoInstrumentation', () => {
291297 const roomName = 'room' ;
292298 const sio = createServerInstance ( ) ;
293299 sio . to ( roomName ) . emit ( 'broadcast' , '1234' ) ;
294- expectSpan ( '/[room] send' , span => {
300+ expectSpan ( 'send / ' , span => {
295301 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual ( '/' ) ;
296302 expect (
297303 span . attributes [ SocketIoInstrumentationAttributes . SOCKET_IO_ROOMS ]
@@ -302,7 +308,7 @@ describe('SocketIoInstrumentation', () => {
302308 it ( 'broadcast to multiple rooms' , ( ) => {
303309 const sio = createServerInstance ( ) ;
304310 sio . to ( 'room1' ) . to ( 'room2' ) . emit ( 'broadcast' , '1234' ) ;
305- expectSpan ( '/[room1,room2] send' , span => {
311+ expectSpan ( 'send / ' , span => {
306312 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual ( '/' ) ;
307313 expect (
308314 span . attributes [ SocketIoInstrumentationAttributes . SOCKET_IO_ROOMS ]
@@ -316,7 +322,7 @@ describe('SocketIoInstrumentation', () => {
316322 const io = createServerInstance ( ) ;
317323 const namespace = io . of ( '/testing' ) ;
318324 namespace . emit ( 'namespace' ) ;
319- expectSpan ( '/testing send ' , span => {
325+ expectSpan ( 'send /testing' , span => {
320326 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
321327 '/testing'
322328 ) ;
@@ -331,7 +337,7 @@ describe('SocketIoInstrumentation', () => {
331337 const io = createServerInstance ( ) ;
332338 const namespace = io . of ( '/testing' ) ;
333339 namespace . to ( roomName ) . emit ( 'broadcast' , '1234' ) ;
334- expectSpan ( '/testing[room] send ' , span => {
340+ expectSpan ( 'send /testing' , span => {
335341 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
336342 '/testing'
337343 ) ;
@@ -348,7 +354,7 @@ describe('SocketIoInstrumentation', () => {
348354 const io = createServerInstance ( ) ;
349355 const namespace = io . of ( '/testing' ) ;
350356 namespace . to ( 'room1' ) . to ( 'room2' ) . emit ( 'broadcast' , '1234' ) ;
351- expectSpan ( '/testing[room1,room2] send ' , span => {
357+ expectSpan ( 'send /testing' , span => {
352358 expect ( span . attributes [ SEMATTRS_MESSAGING_DESTINATION ] ) . toEqual (
353359 '/testing'
354360 ) ;
@@ -379,7 +385,7 @@ describe('SocketIoInstrumentation', () => {
379385 //trace is created after the listener method is completed
380386 setTimeout ( ( ) => {
381387 expectSpan (
382- '/testing test_reply receive ' ,
388+ 'receive /testing' ,
383389 span => {
384390 try {
385391 expect ( span . kind ) . toEqual ( SpanKind . CONSUMER ) ;
@@ -421,7 +427,7 @@ describe('SocketIoInstrumentation', () => {
421427 client . close ( ) ;
422428 sio . close ( ) ;
423429 expectSpan (
424- `/[ ${ socket . id } ] send` ,
430+ ' send /' ,
425431 span => {
426432 try {
427433 expect ( span . kind ) . toEqual ( SpanKind . PRODUCER ) ;
0 commit comments