@@ -396,7 +396,8 @@ describe('Class: ProviderService', () => {
396396 // Act
397397 provider . instrumentFetch ( ) ;
398398 mockFetch ( {
399- origin : 'https://aws.amazon.com/blogs' ,
399+ origin : 'https://aws.amazon.com' ,
400+ path : '/blogs' ,
400401 headers : {
401402 'content-length' : '100' ,
402403 } ,
@@ -407,7 +408,7 @@ describe('Class: ProviderService', () => {
407408 expect ( segment . addNewSubsegment ) . toHaveBeenCalledWith ( 'aws.amazon.com' ) ;
408409 expect ( ( subsegment as HttpSubsegment ) . http ) . toEqual ( {
409410 request : {
410- url : 'aws.amazon.com' ,
411+ url : 'https:// aws.amazon.com/blogs ' ,
411412 method : 'GET' ,
412413 } ,
413414 response : {
@@ -438,7 +439,8 @@ describe('Class: ProviderService', () => {
438439 // Act
439440 provider . instrumentFetch ( ) ;
440441 mockFetch ( {
441- origin : new URL ( 'https://aws.amazon.com/blogs' ) ,
442+ origin : new URL ( 'https://aws.amazon.com' ) ,
443+ path : '/blogs' ,
442444 headers : {
443445 'content-type' : 'application/json' ,
444446 } ,
@@ -447,7 +449,7 @@ describe('Class: ProviderService', () => {
447449 // Assess
448450 expect ( ( subsegment as HttpSubsegment ) . http ) . toEqual ( {
449451 request : {
450- url : 'aws.amazon.com' ,
452+ url : 'https:// aws.amazon.com/blogs ' ,
451453 method : 'GET' ,
452454 } ,
453455 response : {
@@ -568,6 +570,56 @@ describe('Class: ProviderService', () => {
568570 expect ( subsegment . close ) . toHaveBeenCalledTimes ( 1 ) ;
569571 expect ( provider . setSegment ) . toHaveBeenLastCalledWith ( segment ) ;
570572 } ) ;
573+
574+ it ( 'skips the segment creation when the request has no origin' , async ( ) => {
575+ // Prepare
576+ const provider : ProviderService = new ProviderService ( ) ;
577+ const segment = new Subsegment ( '## dummySegment' ) ;
578+ jest . spyOn ( segment , 'addNewSubsegment' ) ;
579+ jest . spyOn ( provider , 'getSegment' ) . mockImplementation ( ( ) => segment ) ;
580+ jest . spyOn ( provider , 'setSegment' ) ;
581+
582+ // Act
583+ provider . instrumentFetch ( ) ;
584+ mockFetch ( { } ) ;
585+
586+ // Assess
587+ expect ( segment . addNewSubsegment ) . toHaveBeenCalledTimes ( 0 ) ;
588+ expect ( provider . setSegment ) . toHaveBeenCalledTimes ( 0 ) ;
589+ } ) ;
590+
591+ it ( 'does not add any path to the segment when the request has no path' , async ( ) => {
592+ // Prepare
593+ const provider : ProviderService = new ProviderService ( ) ;
594+ const segment = new Subsegment ( '## dummySegment' ) ;
595+ const subsegment = segment . addNewSubsegment ( 'aws.amazon.com' ) ;
596+ jest
597+ . spyOn ( segment , 'addNewSubsegment' )
598+ . mockImplementationOnce ( ( ) => subsegment ) ;
599+ jest
600+ . spyOn ( provider , 'getSegment' )
601+ . mockImplementationOnce ( ( ) => segment )
602+ . mockImplementationOnce ( ( ) => subsegment )
603+ . mockImplementationOnce ( ( ) => subsegment ) ;
604+ jest . spyOn ( subsegment , 'close' ) ;
605+ jest . spyOn ( provider , 'setSegment' ) ;
606+
607+ // Act
608+ provider . instrumentFetch ( ) ;
609+ mockFetch ( {
610+ origin : new URL ( 'https://aws.amazon.com' ) ,
611+ } ) ;
612+
613+ // Assess
614+ expect ( ( subsegment as HttpSubsegment ) . http ) . toEqual (
615+ expect . objectContaining ( {
616+ request : {
617+ url : 'https://aws.amazon.com/' ,
618+ method : 'GET' ,
619+ } ,
620+ } )
621+ ) ;
622+ } ) ;
571623 } ) ;
572624
573625 it ( 'closes the segment and adds a fault flag when the connection fails' , async ( ) => {
0 commit comments