File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ export abstract class BaseTransport implements Transport {
114
114
115
115
const url = this . _api . getEnvelopeEndpointWithUrlEncodedAuth ( ) ;
116
116
// Envelope header is required to be at least an empty object
117
- const envelopeHeader = JSON . stringify ( { } ) ;
117
+ const envelopeHeader = JSON . stringify ( { ... ( this . options . tunnel && { dsn : this . _api . getDsn ( ) . toString ( ) } ) } ) ;
118
118
const itemHeaders = JSON . stringify ( {
119
119
type : 'client_report' ,
120
120
} ) ;
Original file line number Diff line number Diff line change @@ -92,6 +92,25 @@ describe('BaseTransport', () => {
92
92
`{}\n{"type":"client_report"}\n{"timestamp":12.345,"discarded_events":${ JSON . stringify ( outcomes ) } }` ,
93
93
) ;
94
94
} ) ;
95
+
96
+ it ( 'attaches DSN to envelope header if tunnel is configured' , ( ) => {
97
+ const tunnel = 'https://hello.com/world' ;
98
+ const transport = new SimpleTransport ( { dsn : testDsn , sendClientReports : true , tunnel } ) ;
99
+
100
+ transport . recordLostEvent ( Outcome . BeforeSend , 'event' ) ;
101
+
102
+ visibilityState = 'hidden' ;
103
+ document . dispatchEvent ( new Event ( 'visibilitychange' ) ) ;
104
+
105
+ const outcomes = [ { reason : Outcome . BeforeSend , category : 'error' , quantity : 1 } ] ;
106
+
107
+ expect ( sendBeaconSpy ) . toHaveBeenCalledWith (
108
+ tunnel ,
109
+ `{"dsn":"${ testDsn } "}\n{"type":"client_report"}\n{"timestamp":12.345,"discarded_events":${ JSON . stringify (
110
+ outcomes ,
111
+ ) } }`,
112
+ ) ;
113
+ } ) ;
95
114
} ) ;
96
115
97
116
it ( 'doesnt provide sendEvent() implementation' , ( ) => {
You can’t perform that action at this time.
0 commit comments