-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Include DSN in envelope header for sessions (#3680)
* fix: Include DSN in envelope header for sessions * Add url tests for non-tunnel requests
- Loading branch information
1 parent
e9c6d6a
commit ab9efb2
Showing
2 changed files
with
32 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,12 @@ import { DebugMeta, Event, SentryRequest, TransactionSamplingMethod } from '@sen | |
import { API } from '../../src/api'; | ||
import { eventToSentryRequest, sessionToSentryRequest } from '../../src/request'; | ||
|
||
const api = new API('https://[email protected]/12312012', { | ||
const ingestDsn = 'https://[email protected]/12312012'; | ||
const ingestUrl = | ||
'https://squirrelchasers.ingest.sentry.io/api/12312012/envelope/?sentry_key=dogsarebadatkeepingsecrets&sentry_version=7'; | ||
const tunnel = 'https://hello.com/world'; | ||
|
||
const api = new API(ingestDsn, { | ||
sdk: { | ||
integrations: ['AWSLambda'], | ||
name: 'sentry.javascript.browser', | ||
|
@@ -12,9 +17,6 @@ const api = new API('https://[email protected] | |
}, | ||
}); | ||
|
||
const ingestDsn = 'https://[email protected]/12312012'; | ||
const tunnel = 'https://hello.com/world'; | ||
|
||
function parseEnvelopeRequest(request: SentryRequest): any { | ||
const [envelopeHeaderString, itemHeaderString, eventString] = request.body.split('\n'); | ||
|
||
|
@@ -26,19 +28,9 @@ function parseEnvelopeRequest(request: SentryRequest): any { | |
} | ||
|
||
describe('eventToSentryRequest', () => { | ||
let api: API; | ||
let event: Event; | ||
|
||
beforeEach(() => { | ||
api = new API(ingestDsn, { | ||
sdk: { | ||
integrations: ['AWSLambda'], | ||
name: 'sentry.javascript.browser', | ||
version: `12.31.12`, | ||
packages: [{ name: 'npm:@sentry/browser', version: `12.31.12` }], | ||
}, | ||
}); | ||
|
||
event = { | ||
contexts: { trace: { trace_id: '1231201211212012', span_id: '12261980', op: 'pageload' } }, | ||
environment: 'dogpark', | ||
|
@@ -140,17 +132,15 @@ describe('eventToSentryRequest', () => { | |
}); | ||
|
||
it('uses tunnel as the url if it is configured', () => { | ||
api = new API(ingestDsn, {}, tunnel); | ||
const tunnelRequest = eventToSentryRequest(event, new API(ingestDsn, {}, tunnel)); | ||
expect(tunnelRequest.url).toEqual(tunnel); | ||
|
||
const result = eventToSentryRequest(event, api); | ||
|
||
expect(result.url).toEqual(tunnel); | ||
const defaultRequest = eventToSentryRequest(event, new API(ingestDsn, {})); | ||
expect(defaultRequest.url).toEqual(ingestUrl); | ||
}); | ||
|
||
it('adds dsn to envelope header if tunnel is configured', () => { | ||
api = new API(ingestDsn, {}, tunnel); | ||
|
||
const result = eventToSentryRequest(event, api); | ||
const result = eventToSentryRequest(event, new API(ingestDsn, {}, tunnel)); | ||
const envelope = parseEnvelopeRequest(result); | ||
|
||
expect(envelope.envelopeHeader).toEqual( | ||
|
@@ -161,10 +151,9 @@ describe('eventToSentryRequest', () => { | |
}); | ||
|
||
it('adds default "event" item type to item header if tunnel is configured', () => { | ||
api = new API(ingestDsn, {}, tunnel); | ||
delete event.type; | ||
|
||
const result = eventToSentryRequest(event, api); | ||
const result = eventToSentryRequest(event, new API(ingestDsn, {}, tunnel)); | ||
const envelope = parseEnvelopeRequest(result); | ||
|
||
expect(envelope.itemHeader).toEqual( | ||
|
@@ -202,4 +191,23 @@ describe('sessionToSentryRequest', () => { | |
}), | ||
); | ||
}); | ||
|
||
it('uses tunnel as the url if it is configured', () => { | ||
const tunnelRequest = sessionToSentryRequest({ aggregates: [] }, new API(ingestDsn, {}, tunnel)); | ||
expect(tunnelRequest.url).toEqual(tunnel); | ||
|
||
const defaultRequest = sessionToSentryRequest({ aggregates: [] }, new API(ingestDsn, {})); | ||
expect(defaultRequest.url).toEqual(ingestUrl); | ||
}); | ||
|
||
it('adds dsn to envelope header if tunnel is configured', () => { | ||
const result = sessionToSentryRequest({ aggregates: [] }, new API(ingestDsn, {}, tunnel)); | ||
const envelope = parseEnvelopeRequest(result); | ||
|
||
expect(envelope.envelopeHeader).toEqual( | ||
expect.objectContaining({ | ||
dsn: ingestDsn, | ||
}), | ||
); | ||
}); | ||
}); |