Skip to content

Commit c812eb2

Browse files
lizokmLms24coolguyzone
authored
Update micro-frontends.mdx (#12040)
* Update micro-frontends.mdx Update micro frontend docs based on user feedback. * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx Co-authored-by: Lukas Stracke <[email protected]> * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx Co-authored-by: Lukas Stracke <[email protected]> * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx Co-authored-by: Alex Krawiec <[email protected]> * Update docs/platforms/javascript/common/best-practices/micro-frontends.mdx --------- Co-authored-by: Lukas Stracke <[email protected]> Co-authored-by: Alex Krawiec <[email protected]>
1 parent 007f1da commit c812eb2

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ keywords:
2121
"module metadata",
2222
]
2323
---
24+
<Alert>
25+
To ensure the Sentry JavaScript SDK works with your micro frontends, make sure all micro frontends that import from a `@sentry/*` package are using the same version of the Sentry SDK.
26+
</Alert>
2427

25-
If your frontend includes JavaScript bundles from multiple sources with
26-
different release cycles, you may want to identify these or route events to specific projects. This is especially useful if you've set up [module federation](https://module-federation.github.io/) or a similar frontend architecture.
28+
If your app uses micro frontends, it’s very useful to be able to track which one an error is coming from. To do this with Sentry, you can create either an automatic or a manual setup where you send events to separate Sentry projects representing each of your micro frontends. This makes it easier to see what’s going wrong and where, helping you track issues and fix them faster, especially in complex frontend architectures.
2729

28-
Below we offer two approaches.
30+
Below you'll find setup instructions for both an automatic and a manual way to route errors to different Sentry projects.
2931

3032
<Note>
3133
In all cases `Sentry.init()` must never be called more than once, doing so
3234
will result in undefined behavior.
3335
</Note>
3436

35-
## Automatically Route Errors to Different Projects Depending on Module
37+
## Automatically Route Errors to Different Projects
3638

37-
`ModuleMetadata` and `makeMultiplexedTransport` can be used together to automatically route
38-
events to different Sentry projects based on the module where the error
39-
occurred.
39+
`ModuleMetadata` and `makeMultiplexedTransport` can be used together to automatically route events to specific Sentry projects that represent your micro frontend services. Events will be routed once the service where the error occurred has been identified, ensuring errors are tracked in the correct project.
4040

4141
<Note>
4242
<ul>
@@ -49,11 +49,13 @@ occurred.
4949
</ul>
5050
</Note>
5151

52-
First, to identify the source of an error, you must inject metadata that helps identify
52+
To identify the source of an error, you must first inject metadata that helps identify
5353
which bundles were responsible for the error. You can do this with any of the
5454
Sentry bundler plugins by enabling the `moduleMetadata` option. The example
5555
below is for Webpack, but this is also supported in Vite, Rollup, and esbuild.
5656

57+
**Install the below code snippet in your micro frontend:**
58+
5759
```javascript
5860
// webpack.config.js
5961
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
@@ -76,7 +78,7 @@ which bundles may be responsible for an error. Once the destination is determine
7678
store it as a list of DSN-release pairs in `event.extra[MULTIPLEXED_TRANSPORT_EXTRA_KEY]`
7779
for the multiplexed transport to reference for routing.
7880

79-
In practice, here is what your Sentry initialization should look like:
81+
**Install the below code snippet in your host:**
8082

8183
```javascript
8284
import {
@@ -138,14 +140,13 @@ will return matches for errors, transactions, and replays.
138140
139141
## Manually Route Errors to Different Projects
140142
141-
If, however, you would like to have more control over the routing of errors to the point
142-
where you explicitly specify the destination for each individual `captureException`,
143-
you can do that with the more advanced interface multiplexed transport offers.
143+
If you want more control to be able to explicitly specify the destination for each individual `captureException`,
144+
you can use the more advanced interface multiplexed transport offers.
144145
145146
<Note>Requires SDK version `7.59.0` or higher.</Note>
146147
147148
The example below uses a `feature` tag to determine which Sentry project to
148-
send the event to. If the event does not have a `feature` tag, we send it to the
149+
send the event to. If the event doesn't have a `feature` tag, we send it to the
149150
fallback DSN defined in `Sentry.init`.
150151
151152
```js
@@ -176,14 +177,9 @@ init({
176177
You can then set tags/contexts on events in individual micro-frontends to decide which Sentry project to send the event to as follows:
177178
178179
<Note>
179-
It is important to always use a local scope when setting the tag (either as
180-
shown below or using{" "}
181-
<PlatformLink to="/enriching-events/scopes/#local-scopes">
182-
withScope documentation
183-
</PlatformLink>
184-
). Using a global scope e.g. through `Sentry.setTag()` will result in all
185-
subsequent events being routed to the same DSN regardless of where they
186-
originate.
180+
It's important to always use a local scope when setting the tag (either as shown below or using{" "} <PlatformLink to="/enriching-events/scopes/#local-scopes">
181+
withScope documentation </PlatformLink>). Using a global scope, for example, through `Sentry.setTag()` will result in all subsequent events being routed to the
182+
same DSN regardless of where they originated.
187183
</Note>
188184
189185
```typescript

0 commit comments

Comments
 (0)