You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/best-practices/micro-frontends.mdx
+17-21Lines changed: 17 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,22 +21,22 @@ keywords:
21
21
"module metadata",
22
22
]
23
23
---
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>
24
27
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.
27
29
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.
29
31
30
32
<Note>
31
33
In all cases `Sentry.init()` must never be called more than once, doing so
32
34
will result in undefined behavior.
33
35
</Note>
34
36
35
-
## Automatically Route Errors to Different Projects Depending on Module
37
+
## Automatically Route Errors to Different Projects
36
38
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.
40
40
41
41
<Note>
42
42
<ul>
@@ -49,11 +49,13 @@ occurred.
49
49
</ul>
50
50
</Note>
51
51
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
53
53
which bundles were responsible for the error. You can do this with any of the
54
54
Sentry bundler plugins by enabling the `moduleMetadata` option. The example
55
55
below is for Webpack, but this is also supported in Vite, Rollup, and esbuild.
56
56
57
+
**Install the below code snippet in your micro frontend:**
). 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
0 commit comments