Skip to content

Commit 09f2f41

Browse files
atilafassinaAbhiPrasadlizokm
authored
add guide to use Sentry with SolidJS (#8635)
Co-authored-by: Abhijeet Prasad <[email protected]> Co-authored-by: Liza Mock <[email protected]>
1 parent 30e4173 commit 09f2f41

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
To use the SDK, initialize it in your Solid entry point before bootstrapping your app. (In a typical Solid project that's the render-client.js, or render-client.tsx.)
2+
3+
<SignInNote />
4+
5+
```javascript {filename: render-client.jsx}
6+
import { render } from "solid-js/web";
7+
import App from "./app";
8+
import * as Sentry from "@sentry/browser";
9+
import { DEV } from "solid-js";
10+
11+
// this will only initialize your Sentry client in production builds.
12+
if (!DEV) {
13+
Sentry.init({
14+
dsn: "<Sentry DSN>",
15+
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
16+
17+
// Set tracesSampleRate to 1.0 to capture 100%
18+
// of transactions for performance monitoring.
19+
// We recommend adjusting this value in production
20+
tracesSampleRate: 1.0,
21+
22+
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
23+
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
24+
25+
// Capture Replay for 10% of all sessions,
26+
// plus 100% of sessions with an error
27+
replaysSessionSampleRate: 0.1,
28+
replaysOnErrorSampleRate: 1.0,
29+
});
30+
}
31+
32+
const app = document.getElementById("app");
33+
34+
if (!app) throw new Error("No #app element found in the DOM.");
35+
36+
render(() => <App />, app);
37+
```
38+
39+
Once you've done this, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance in the client.
40+
41+
It's also possible to add Client-Side routing to your app with [Solid-Router](https://docs.solidjs.com/guides/how-to-guides/routing-in-solid/solid-router) without changing any additional settings. As long as you use the default HTML History API to handle routing.
42+
43+
Once you've done this, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance in the client. You can also [manually capture errors](/platforms/javascript/guides/solid/usage).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```javascript
2+
<button
3+
type="button"
4+
onClick={() => {
5+
throw new Error("Sentry Frontend Error");
6+
}}
7+
>
8+
Throw error
9+
</button>
10+
```
11+
12+
This snippet adds a button that throws an error in any Solid component you choose. It's useful for testing. It's recommended to base wrap your app within an Error Boundary:
13+
14+
```javascript {filename: app.jsx}
15+
import { ErrorBoundary } from "solid-js";
16+
import Routes from "./routes.tsx";
17+
import ErrorFallbackComponent from "./components/error-fallback";
18+
import * as Sentry from "@sentry/browser";
19+
20+
export default function App() {
21+
const Routes = useRoutes(ROUTES);
22+
23+
return (
24+
<ErrorBoundary
25+
fallback={(error) => {
26+
Sentry.captureException(error);
27+
return <ErrorFallbackComponent />;
28+
}}
29+
>
30+
<Routes />
31+
</ErrorBoundary>
32+
);
33+
}
34+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Solid
2+
sdk: sentry.javascript.browser
3+
fallbackPlatform: javascript
4+
caseStyle: camelCase
5+
supportLevel: production
6+
categories:
7+
- browser

0 commit comments

Comments
 (0)