Skip to content

Commit

Permalink
Add Sentry integration (#434)
Browse files Browse the repository at this point in the history
* Add Sentry integration

* Use env var for DSN

* Move to `optionalDependencies`

* Update docs
  • Loading branch information
dan-lee authored Dec 17, 2024
1 parent f9c0ac6 commit c306ef1
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 64 deletions.
41 changes: 41 additions & 0 deletions docs/pages/configuration/sentry.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
sidebar_icon: bug
---

# Sentry

Sentry is a popular error tracking tool that helps you monitor and fix crashes in real time. It provides you with detailed error reports, so you can quickly identify and resolve issues before they affect your users.

## Enable Sentry

1. To enable it you have to first install the optional dependency `@sentry/react`.

```bash
npm install --save @sentry/react
```

2. And then set the `SENTRY_DSN` environment variable in your Zudoku project.

```bash

SENTRY_DSN=https://your-sentry-dsn
```

## Release management

However this does not handle release management for you. For that you can [create a custom `vite.config.ts`](./vite-config) and use the `@sentry/vite-plugin` plugin.

```ts
import { sentryVitePlugin } from "@sentry/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [
sentryVitePlugin({
authToken: "your-token",
org: "your-org",
project: "your-project",
}),
],
});
```
56 changes: 0 additions & 56 deletions docs/sidebar.ts

This file was deleted.

1 change: 1 addition & 0 deletions docs/zudoku.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const config: ZudokuConfig = {
"configuration/navigation",
"configuration/search",
"configuration/authentication",
"configuration/sentry",
"configuration/vite-config",
],
},
Expand Down
3 changes: 2 additions & 1 deletion packages/zudoku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
},
"optionalDependencies": {
"@clerk/clerk-js": "5.11.0",
"@inkeep/widgets": "^0.2.289"
"@inkeep/widgets": "^0.2.289",
"@sentry/react": "^8.45.1"
}
}
6 changes: 6 additions & 0 deletions packages/zudoku/src/app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { getRoutesByConfig } from "./main.js";
const routes = getRoutesByConfig(config);
const root = document.getElementById("root")!;

if (process.env.SENTRY_DSN) {
void import("./sentry.js").then((mod) => {
mod.initSentry({ dsn: process.env.SENTRY_DSN as string });
});
}

if (root.childElementCount > 0) {
void hydrate(routes);
} else {
Expand Down
24 changes: 24 additions & 0 deletions packages/zudoku/src/app/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as Sentry from "@sentry/react";
import { useEffect } from "react";
import {
createRoutesFromChildren,
matchRoutes,
useLocation,
useNavigationType,
} from "react-router-dom";

export const initSentry = ({ dsn }: { dsn: string }) => {
Sentry.init({
dsn,
integrations: [
Sentry.reactRouterV6BrowserTracingIntegration({
useEffect,
useLocation,
useNavigationType,
createRoutesFromChildren,
matchRoutes,
}),
Sentry.replayIntegration(),
],
});
};
5 changes: 4 additions & 1 deletion packages/zudoku/src/vite/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export async function getViteConfig(
worker: {
format: "es",
},
define: {
"process.env.SENTRY_DSN": JSON.stringify(process.env.SENTRY_DSN),
},
ssr: {
target: "node",
noExternal: [],
Expand Down Expand Up @@ -228,7 +231,7 @@ export async function getViteConfig(
? getAppServerEntryPath()
: getAppClientEntryPath(),
],
include: ["react-dom/client"],
include: ["react-dom/client", "@sentry/react"],
exclude: [
// Vite does not like optimizing the worker dependency
"zudoku/openapi-worker",
Expand Down
1 change: 1 addition & 0 deletions packages/zudoku/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default defineConfig({
"react-dom",
"lucide-react",
/@radix-ui/,
"@sentry/react",

// Optional Modules (i.e. auth providers) are external as we don't
// want to bundle these in the library. Users will install these
Expand Down
87 changes: 81 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c306ef1

Please sign in to comment.