-
-
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.
feat(browser): Add
multiplexedtransport.js
CDN bundle (#15043)
Add a pluggable CDN bundle for `makeMultiplexedTransport`, an API we export from `@sentry/browser` but not from the browser SDK CDN bundles for bundle size reasons.
- Loading branch information
Showing
6 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
dev-packages/browser-integration-tests/suites/transport/multiplexed/init.js
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
import { makeMultiplexedTransport } from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
transport: makeMultiplexedTransport(Sentry.makeFetchTransport, ({ getEvent }) => { | ||
const event = getEvent('event'); | ||
|
||
if (event.tags.to === 'a') { | ||
return ['https://public@dsn.ingest.sentry.io/1337']; | ||
} else if (event.tags.to === 'b') { | ||
return ['https://public@dsn.ingest.sentry.io/1337']; | ||
} else { | ||
throw new Error('Unknown destination'); | ||
} | ||
}), | ||
}); |
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/transport/multiplexed/subject.js
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
setTimeout(() => { | ||
Sentry.withScope(scope => { | ||
scope.setTag('to', 'a'); | ||
Sentry.captureException(new Error('Error a')); | ||
}); | ||
Sentry.withScope(scope => { | ||
scope.setTag('to', 'b'); | ||
Sentry.captureException(new Error('Error b')); | ||
}); | ||
}, 0); |
20 changes: 20 additions & 0 deletions
20
dev-packages/browser-integration-tests/suites/transport/multiplexed/test.ts
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/core'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers'; | ||
|
||
sentryTest('sends event to DSNs specified in makeMultiplexedTransport', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
const errorEvents = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { envelopeType: 'event', url }); | ||
|
||
expect(errorEvents).toHaveLength(2); | ||
|
||
const [evt1, evt2] = errorEvents; | ||
|
||
const errorA = evt1?.tags?.to === 'a' ? evt1 : evt2; | ||
const errorB = evt1?.tags?.to === 'b' ? evt1 : evt2; | ||
|
||
expect(errorA.tags?.to).toBe('a'); | ||
expect(errorB.tags?.to).toBe('b'); | ||
}); |
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
1 change: 1 addition & 0 deletions
1
packages/browser/src/pluggable-exports-bundle/index.multiplexedtransport.ts
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { makeMultiplexedTransport } from '@sentry/core'; |