Skip to content

Commit

Permalink
fix(browser): Send client outcomes through tunnel if configured (#4031)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Oct 6, 2021
1 parent 24ab018 commit 8a5db68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/browser/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export abstract class BaseTransport implements Transport {

const url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
// Envelope header is required to be at least an empty object
const envelopeHeader = JSON.stringify({});
const envelopeHeader = JSON.stringify({ ...(this.options.tunnel && { dsn: this._api.getDsn().toString() }) });
const itemHeaders = JSON.stringify({
type: 'client_report',
});
Expand Down
19 changes: 19 additions & 0 deletions packages/browser/test/unit/transports/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ describe('BaseTransport', () => {
`{}\n{"type":"client_report"}\n{"timestamp":12.345,"discarded_events":${JSON.stringify(outcomes)}}`,
);
});

it('attaches DSN to envelope header if tunnel is configured', () => {
const tunnel = 'https://hello.com/world';
const transport = new SimpleTransport({ dsn: testDsn, sendClientReports: true, tunnel });

transport.recordLostEvent(Outcome.BeforeSend, 'event');

visibilityState = 'hidden';
document.dispatchEvent(new Event('visibilitychange'));

const outcomes = [{ reason: Outcome.BeforeSend, category: 'error', quantity: 1 }];

expect(sendBeaconSpy).toHaveBeenCalledWith(
tunnel,
`{"dsn":"${testDsn}"}\n{"type":"client_report"}\n{"timestamp":12.345,"discarded_events":${JSON.stringify(
outcomes,
)}}`,
);
});
});

it('doesnt provide sendEvent() implementation', () => {
Expand Down

0 comments on commit 8a5db68

Please sign in to comment.