Skip to content

Commit 2bc3584

Browse files
authored
feat(v8/browser): Add multiplexedtransport.js CDN bundle (#15043) (#15046)
v8 backport of #15043 ref #15041
1 parent 50b0294 commit 2bc3584

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
import { makeMultiplexedTransport } from '@sentry/browser';
4+
5+
window.Sentry = Sentry;
6+
7+
Sentry.init({
8+
dsn: 'https://[email protected]/1337',
9+
transport: makeMultiplexedTransport(Sentry.makeFetchTransport, ({ getEvent }) => {
10+
const event = getEvent('event');
11+
12+
if (event.tags.to === 'a') {
13+
return ['https://[email protected]/1337'];
14+
} else if (event.tags.to === 'b') {
15+
return ['https://[email protected]/1337'];
16+
} else {
17+
throw new Error('Unknown destination');
18+
}
19+
}),
20+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
setTimeout(() => {
2+
Sentry.withScope(scope => {
3+
scope.setTag('to', 'a');
4+
Sentry.captureException(new Error('Error a'));
5+
});
6+
Sentry.withScope(scope => {
7+
scope.setTag('to', 'b');
8+
Sentry.captureException(new Error('Error b'));
9+
});
10+
}, 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/core';
3+
4+
import { sentryTest } from '../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers';
6+
7+
sentryTest('sends event to DSNs specified in makeMultiplexedTransport', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
const errorEvents = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { envelopeType: 'event', url });
10+
11+
expect(errorEvents).toHaveLength(2);
12+
13+
const [evt1, evt2] = errorEvents;
14+
15+
const errorA = evt1?.tags?.to === 'a' ? evt1 : evt2;
16+
const errorB = evt1?.tags?.to === 'b' ? evt1 : evt2;
17+
18+
expect(errorA.tags?.to).toBe('a');
19+
expect(errorB.tags?.to).toBe('b');
20+
});

dev-packages/browser-integration-tests/utils/generatePlugin.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import type { Package } from '@sentry/core';
3+
import { type Package } from '@sentry/core';
44
import HtmlWebpackPlugin, { createHtmlTagObject } from 'html-webpack-plugin';
55
import type { Compiler } from 'webpack';
66

@@ -38,6 +38,8 @@ const IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS: Record<string, string> = {
3838
sessionTimingIntegration: 'sessiontiming',
3939
feedbackIntegration: 'feedback',
4040
moduleMetadataIntegration: 'modulemetadata',
41+
// technically, this is not an integration, but let's add it anyway for simplicity
42+
makeMultiplexedTransport: 'multiplexedtransport',
4143
};
4244

4345
const BUNDLE_PATHS: Record<string, Record<string, string>> = {

packages/browser/rollup.bundle.config.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ reexportedPluggableIntegrationFiles.forEach(integrationName => {
3737
builds.push(...makeBundleConfigVariants(integrationsBundleConfig));
3838
});
3939

40+
// Bundle config for additional exports we don't want to include in the main SDK bundle
41+
// if we need more of these, we can generalize the config as for pluggable integrations
42+
builds.push(
43+
...makeBundleConfigVariants(
44+
makeBaseBundleConfig({
45+
bundleType: 'addon',
46+
entrypoints: ['src/pluggable-exports-bundle/index.multiplexedtransport.ts'],
47+
licenseTitle: '@sentry/browser - multiplexedtransport',
48+
outputFileBase: () => 'bundles/multiplexedtransport',
49+
}),
50+
),
51+
);
52+
4053
const baseBundleConfig = makeBaseBundleConfig({
4154
bundleType: 'standalone',
4255
entrypoints: ['src/index.bundle.ts'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { makeMultiplexedTransport } from '@sentry/core';

0 commit comments

Comments
 (0)