@@ -38,35 +38,23 @@ function hexToBase64(hexString: string): string {
3838}
3939
4040describe ( 'exportRootSpanAfterLoadEvent' , ( ) => {
41- let realOcwAgent : string | undefined ;
41+ let realOcAgent : string | undefined ;
4242 let realTraceparent : string | undefined ;
4343 let sendSpy : jasmine . Spy ;
4444 beforeEach ( ( ) => {
4545 jasmine . clock ( ) . install ( ) ;
4646 spyOn ( XMLHttpRequest . prototype , 'open' ) ;
4747 sendSpy = spyOn ( XMLHttpRequest . prototype , 'send' ) ;
4848 spyOn ( XMLHttpRequest . prototype , 'setRequestHeader' ) ;
49- realOcwAgent = windowWithOcwGlobals . ocAgent ;
49+ realOcAgent = windowWithOcwGlobals . ocAgent ;
5050 realTraceparent = windowWithOcwGlobals . traceparent ;
5151 } ) ;
5252 afterEach ( ( ) => {
5353 jasmine . clock ( ) . uninstall ( ) ;
54- windowWithOcwGlobals . ocAgent = realOcwAgent ;
54+ windowWithOcwGlobals . ocAgent = realOcAgent ;
5555 windowWithOcwGlobals . traceparent = realTraceparent ;
5656 } ) ;
5757
58- it ( 'exports spans to agent if agent is configured' , ( ) => {
59- windowWithOcwGlobals . ocAgent = 'http://agent' ;
60- windowWithOcwGlobals . traceparent = undefined ;
61-
62- exportRootSpanAfterLoadEvent ( ) ;
63-
64- jasmine . clock ( ) . tick ( 300000 ) ;
65- expect ( XMLHttpRequest . prototype . open )
66- . toHaveBeenCalledWith ( 'POST' , 'http://agent/v1/trace' ) ;
67- expect ( XMLHttpRequest . prototype . send ) . toHaveBeenCalled ( ) ;
68- } ) ;
69-
7058 it ( 'does not export if agent not configured' , ( ) => {
7159 windowWithOcwGlobals . ocAgent = undefined ;
7260 windowWithOcwGlobals . traceparent = undefined ;
@@ -96,7 +84,7 @@ describe('exportRootSpanAfterLoadEvent', () => {
9684 expect ( sendBody ) . toContain ( hexToBase64 ( traceId ) ) ;
9785 } ) ;
9886
99- it ( 'does not export spans if traceparent sampling hint not set' , ( ) => {
87+ it ( 'does not export spans if traceparent sampling hint set to zero ' , ( ) => {
10088 windowWithOcwGlobals . ocAgent = 'http://agent' ;
10189 windowWithOcwGlobals . traceparent =
10290 '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00' ;
@@ -107,4 +95,29 @@ describe('exportRootSpanAfterLoadEvent', () => {
10795 expect ( XMLHttpRequest . prototype . open ) . not . toHaveBeenCalled ( ) ;
10896 expect ( XMLHttpRequest . prototype . send ) . not . toHaveBeenCalled ( ) ;
10997 } ) ;
98+
99+ it ( 'does not export spans if traceparent unset and random is big' , ( ) => {
100+ spyOn ( Math , 'random' ) . and . returnValue ( 0.99 ) ;
101+ windowWithOcwGlobals . ocAgent = 'http://agent' ;
102+ windowWithOcwGlobals . traceparent = '' ;
103+
104+ exportRootSpanAfterLoadEvent ( ) ;
105+
106+ jasmine . clock ( ) . tick ( 300000 ) ;
107+ expect ( XMLHttpRequest . prototype . open ) . not . toHaveBeenCalled ( ) ;
108+ expect ( XMLHttpRequest . prototype . send ) . not . toHaveBeenCalled ( ) ;
109+ } ) ;
110+
111+ it ( 'exports spans if traceparent unset and random number is small' , ( ) => {
112+ spyOn ( Math , 'random' ) . and . returnValue ( 0 ) ;
113+ windowWithOcwGlobals . ocAgent = 'http://agent' ;
114+ windowWithOcwGlobals . traceparent = undefined ;
115+
116+ exportRootSpanAfterLoadEvent ( ) ;
117+
118+ jasmine . clock ( ) . tick ( 300000 ) ;
119+ expect ( XMLHttpRequest . prototype . open )
120+ . toHaveBeenCalledWith ( 'POST' , 'http://agent/v1/trace' ) ;
121+ expect ( XMLHttpRequest . prototype . send ) . toHaveBeenCalled ( ) ;
122+ } ) ;
110123} ) ;
0 commit comments