Skip to content

Commit 61c8660

Browse files
sentry-junior[bot]Junior
andauthored
docs(js): Add CDN tab to manual multiplexed transport examples (#17334)
## Summary Adds CDN/Loader Bundle code tabs to the **Manually Route Errors to Different Projects** section of the [micro-frontends best practices page](https://docs.sentry.io/platforms/javascript/best-practices/micro-frontends/). Previously, the 'Automatically Route Errors' section already had NPM + CDN tabs, but both manual sub-sections ('Using the Default Matcher' and 'Using a Custom Matcher') only showed NPM code. ### Changes - **Using the Default Matcher**: added a CDN tab that loads `bundle.min.js` + `multiplexedtransport.min.js` and calls `Sentry.makeMultiplexedTransport` / `Sentry.captureException` via the global `Sentry` object, including `Sentry.MULTIPLEXED_TRANSPORT_EXTRA_KEY`. - **Using a Custom Matcher**: added a CDN tab that loads the same two bundles and shows the custom matcher callback via the global object. - Promoted the two bare ```js``` fences to ```javascript {tabTitle:NPM}``` to match the tab convention used in the rest of the file. The pattern follows the existing CDN tab in the 'Automatically Route Errors' section directly above, using the same `@inject` version/checksum helpers for integrity attributes. Fixes a gap reported via Slack support where CDN-only users (e.g. customers not bundling) couldn't find guidance on using `makeMultiplexedTransport` without npm. Co-authored-by: Junior <junior@sentry.io>
1 parent 6354b55 commit 61c8660

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

docs/platforms/javascript/common/best-practices/micro-frontends.mdx

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ you can use the multiplexed transport's API to route events to specific projects
225225
226226
The simplest way to manually route events is by using the default matcher with `MULTIPLEXED_TRANSPORT_EXTRA_KEY`:
227227
228-
```js
228+
```javascript {tabTitle:NPM}
229229
import {
230230
captureException,
231231
init,
@@ -250,13 +250,44 @@ captureException(new Error("oh no!"), {
250250
});
251251
```
252252
253+
```html {tabTitle:CDN/Loader Bundle}
254+
<script
255+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/bundle.min.js"
256+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'bundle.min.js', 'sha384-base64') }}"
257+
crossorigin="anonymous"
258+
></script>
259+
260+
<script
261+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/multiplexedtransport.min.js"
262+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'multiplexedtransport.min.js', 'sha384-base64') }}"
263+
crossorigin="anonymous"
264+
></script>
265+
266+
<script>
267+
Sentry.init({
268+
dsn: "__FALLBACK_DSN__",
269+
transport: Sentry.makeMultiplexedTransport(Sentry.makeFetchTransport),
270+
});
271+
272+
// Route a specific error to different projects
273+
Sentry.captureException(new Error("oh no!"), {
274+
extra: {
275+
[Sentry.MULTIPLEXED_TRANSPORT_EXTRA_KEY]: [
276+
{ dsn: "__CART_DSN__", release: "cart@1.0.0" },
277+
{ dsn: "__GALLERY_DSN__", release: "gallery@1.2.0" },
278+
],
279+
},
280+
});
281+
</script>
282+
```
283+
253284
### Using a Custom Matcher
254285
255286
For more advanced routing logic, you can provide a custom matcher function. The example below uses a `feature` tag to determine which Sentry project to
256287
send the event to. If the event doesn't have a `feature` tag, we send it to the
257288
fallback DSN defined in `Sentry.init`.
258289
259-
```js
290+
```javascript {tabTitle:NPM}
260291
import {
261292
captureException,
262293
init,
@@ -281,6 +312,41 @@ init({
281312
});
282313
```
283314
315+
```html {tabTitle:CDN/Loader Bundle}
316+
<script
317+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/bundle.min.js"
318+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'bundle.min.js', 'sha384-base64') }}"
319+
crossorigin="anonymous"
320+
></script>
321+
322+
<script
323+
src="https://browser.sentry-cdn.com/{{@inject packages.version('sentry.javascript.browser') }}/multiplexedtransport.min.js"
324+
integrity="sha384-{{@inject packages.checksum('sentry.javascript.browser', 'multiplexedtransport.min.js', 'sha384-base64') }}"
325+
crossorigin="anonymous"
326+
></script>
327+
328+
<script>
329+
Sentry.init({
330+
dsn: "__FALLBACK_DSN__",
331+
transport: Sentry.makeMultiplexedTransport(
332+
Sentry.makeFetchTransport,
333+
({ getEvent }) => {
334+
const event = getEvent();
335+
336+
// Send to different DSNs, based on the event payload
337+
if (event?.tags?.feature === "cart") {
338+
return [{ dsn: "__CART_DSN__", release: "cart@1.0.0" }];
339+
} else if (event?.tags?.feature === "gallery") {
340+
return [{ dsn: "__GALLERY_DSN__", release: "gallery@1.2.0" }];
341+
} else {
342+
return [];
343+
}
344+
}
345+
),
346+
});
347+
</script>
348+
```
349+
284350
<Alert>
285351
**Replace the placeholder DSN values with your actual Sentry project DSNs:**
286352
- Replace `__FALLBACK_DSN__` with the DSN for your fallback/default Sentry project

0 commit comments

Comments
 (0)