@@ -24,6 +24,7 @@ import { DEFAULT_NAVIGATION_SPAN_NAME } from '../../src/js/tracing/span';
2424import { RN_GLOBAL_OBJ } from '../../src/js/utils/worldwide' ;
2525import { getDefaultTestClientOptions , TestClient } from '../mocks/client' ;
2626import { NATIVE } from '../mockWrapper' ;
27+ import { getDevServer } from './../../src/js/integrations/debugsymbolicatorutils' ;
2728import { createMockNavigationAndAttachTo } from './reactnavigationutils' ;
2829
2930const dummyRoute = {
@@ -32,6 +33,9 @@ const dummyRoute = {
3233} ;
3334
3435jest . mock ( '../../src/js/wrapper.ts' , ( ) => jest . requireActual ( '../mockWrapper.ts' ) ) ;
36+ jest . mock ( './../../src/js/integrations/debugsymbolicatorutils' , ( ) => ( {
37+ getDevServer : jest . fn ( ) ,
38+ } ) ) ;
3539jest . useFakeTimers ( { advanceTimers : true } ) ;
3640
3741class MockNavigationContainer {
@@ -392,6 +396,67 @@ describe('ReactNavigationInstrumentation', () => {
392396 } ) ;
393397 } ) ;
394398
399+ describe ( 'shouldCreateSpanForRequest' , ( ) => {
400+ it ( 'should return false for Dev Server URLs' , ( ) => {
401+ const devServerUrl = 'http://localhost:8081' ;
402+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : devServerUrl } ) ;
403+
404+ const rnTracing = reactNativeTracingIntegration ( ) ;
405+
406+ const result = rnTracing . options . shouldCreateSpanForRequest ( devServerUrl ) ;
407+
408+ expect ( result ) . toBe ( false ) ;
409+ } ) ;
410+
411+ it ( 'should return true for non Dev Server URLs' , ( ) => {
412+ const devServerUrl = 'http://localhost:8081' ;
413+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : devServerUrl } ) ;
414+
415+ const rnTracing = reactNativeTracingIntegration ( ) ;
416+
417+ const result = rnTracing . options . shouldCreateSpanForRequest ( 'http://some-other-url.com' ) ;
418+
419+ expect ( result ) . toBe ( true ) ;
420+ } ) ;
421+
422+ it ( 'should chain the user defined shouldCreateSpanForRequest if defined' , ( ) => {
423+ const devServerUrl = 'http://localhost:8081' ;
424+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : devServerUrl } ) ;
425+
426+ const userShouldCreateSpanForRequest = ( _url : string ) : boolean => {
427+ return false ;
428+ } ;
429+
430+ const rnTracing = reactNativeTracingIntegration ( { shouldCreateSpanForRequest : userShouldCreateSpanForRequest } ) ;
431+
432+ const result = rnTracing . options . shouldCreateSpanForRequest ( 'http://some-other-url.com' ) ;
433+
434+ expect ( result ) . toBe ( false ) ;
435+ } ) ;
436+
437+ it ( 'should handle undefined devServerUrls by using only the user defined shouldCreateSpanForRequest' , ( ) => {
438+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : undefined } ) ;
439+
440+ const userShouldCreateSpanForRequest = ( _url : string ) : boolean => {
441+ return true ;
442+ } ;
443+
444+ const rnTracing = reactNativeTracingIntegration ( { shouldCreateSpanForRequest : userShouldCreateSpanForRequest } ) ;
445+
446+ const result = rnTracing . options . shouldCreateSpanForRequest ( 'http://any-url.com' ) ;
447+
448+ expect ( result ) . toBe ( true ) ;
449+ } ) ;
450+
451+ it ( 'should not set the shouldCreateSpanForRequest if not user provided and the devServerUrl is undefined' , ( ) => {
452+ ( getDevServer as jest . Mock ) . mockReturnValue ( { url : undefined } ) ;
453+
454+ const rnTracing = reactNativeTracingIntegration ( ) ;
455+
456+ expect ( rnTracing . options . shouldCreateSpanForRequest ) . toBe ( undefined ) ;
457+ } ) ;
458+ } ) ;
459+
395460 function setupTestClient (
396461 setupOptions : {
397462 beforeSpanStart ?: ( options : StartSpanOptions ) => StartSpanOptions ;
0 commit comments