feat(error-tracking): add browser error tracking to all 19 SvelteKit web apps

Add @sentry/browser integration via shared-error-tracking/browser export
and hooks.client.ts in every web app for client-side error reporting to GlitchTip.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-22 19:16:21 +01:00
parent a4e41ee1ed
commit 7cad4073d4
40 changed files with 443 additions and 5 deletions

View file

@ -48,6 +48,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'calendar-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -38,6 +38,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'chat-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -41,6 +41,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'clock-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -40,6 +40,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-help-content": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'contacts-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -37,6 +37,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'context-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -48,6 +48,7 @@
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-config": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'manacore-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -34,6 +34,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-config": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'manadeck-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -37,6 +37,7 @@
"dependencies": {
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-i18n": "workspace:*",
"@manacore/shared-icons": "workspace:*",
"@manacore/shared-tailwind": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'matrix-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'mukke-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -43,6 +43,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'nutriphi-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -34,6 +34,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-help-content": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'photos-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -21,6 +21,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'picture-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -34,6 +34,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-i18n": "workspace:*",
"@manacore/shared-icons": "workspace:*",
"@manacore/shared-tailwind": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'planta-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -36,6 +36,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'presi-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -38,6 +38,7 @@
"@manacore/shared-utils": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-i18n": "workspace:*",
"@manacore/shared-icons": "workspace:*",
"@manacore/shared-tailwind": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'questions-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -38,6 +38,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-i18n": "workspace:*",
"@manacore/shared-icons": "workspace:*",
"@manacore/shared-tailwind": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'skilltree-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -42,6 +42,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'storage-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -44,6 +44,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'todo-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -36,6 +36,7 @@
"@manacore/shared-auth": "workspace:*",
"@manacore/shared-auth-ui": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/shared-i18n": "workspace:*",

View file

@ -0,0 +1,12 @@
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'zitare-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};

View file

@ -32,6 +32,8 @@ Self-hosted, open-source error tracking for all ManaCore apps using [GlitchTip](
## Project DSNs
### Backend DSNs
| App | Project ID | DSN |
|-----|-----------|-----|
| Calendar | 1 | `https://7dcf6e8648a04b85b2cb275921c059d5@glitchtip.mana.how/1` |
@ -43,6 +45,14 @@ Self-hosted, open-source error tracking for all ManaCore apps using [GlitchTip](
| Clock | 7 | `https://4d5ea890-019d-4a98-8e98-34bc3e374e0a@glitchtip.mana.how/7` |
| Zitare | 8 | `https://53b87191-3d86-4628-a8c7-cb97b3f69e06@glitchtip.mana.how/8` |
### Frontend DSNs
Frontend projects need to be created separately in GlitchTip so that browser errors are tracked in their own project (separate from backend errors).
To create frontend projects, use the Django shell command in the [Administration](#server-access) section with `platform="javascript"` and name them `{app}-web` (e.g., `calendar-web`).
Then set `PUBLIC_GLITCHTIP_DSN` in the web app's Docker environment.
## Integration
### Backend (NestJS)
@ -91,18 +101,56 @@ NestJS-specific (`@manacore/shared-error-tracking/nestjs`):
| `SentryExceptionFilter` | Global exception filter (captures 5xx only) |
| `setUserFromRequest(req)` | Set user context from JWT request |
### Web Apps (SvelteKit) - Future
### Web Apps (SvelteKit)
All 19 SvelteKit web apps have frontend error tracking via `hooks.client.ts`:
```typescript
// src/hooks.client.ts
import { initErrorTracking } from '@manacore/shared-error-tracking';
import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
import type { HandleClientError } from '@sveltejs/kit';
initErrorTracking({
serviceName: 'calendar-web',
dsn: import.meta.env.PUBLIC_GLITCHTIP_DSN,
serviceName: 'calendar-web',
dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
environment: import.meta.env.MODE,
});
export const handleError: HandleClientError = ({ error }) => {
handleSvelteError(error);
};
```
The DSN is injected at runtime via `hooks.server.ts` (same pattern as auth URL and backend URL):
```typescript
// In hooks.server.ts
const PUBLIC_GLITCHTIP_DSN = process.env.PUBLIC_GLITCHTIP_DSN || '';
// Injected into HTML as window.__PUBLIC_GLITCHTIP_DSN__
```
**What gets captured:**
- Unhandled JavaScript exceptions
- Unhandled promise rejections
- SvelteKit rendering errors (via `handleError` hook)
- Network errors, failed API calls
**Environment variable:**
```env
PUBLIC_GLITCHTIP_DSN=https://<key>@glitchtip.mana.how/<project-id>
```
Browser-specific exports (`@manacore/shared-error-tracking/browser`):
| Function | Purpose |
|----------|---------|
| `initErrorTracking(options)` | Initialize browser Sentry SDK |
| `handleSvelteError(error)` | Capture SvelteKit client errors |
| `captureException(error, context)` | Capture an error manually |
| `captureMessage(message, level)` | Capture a message |
| `setUser({ id, email })` | Set user context |
| `setTag(key, value)` | Set extra context tags |
## Docker Setup
In `docker-compose.macmini.yml`:
@ -160,13 +208,24 @@ print(f"DSN: https://{key.public_key}@glitchtip.mana.how/{proj.id}")
### Adding a New App
1. Create project in GlitchTip (via UI or Django shell)
**Backend:**
1. Create project in GlitchTip (via UI or Django shell, `platform="node"`)
2. Copy DSN
3. Add `@manacore/shared-error-tracking` to backend package.json
4. Create `src/instrument.ts`
5. Import `./instrument` as first line in `src/main.ts`
6. Set `GLITCHTIP_DSN` env variable
**Frontend (SvelteKit):**
1. Create project in GlitchTip (`platform="javascript"`, name: `{app}-web`)
2. Copy DSN
3. Create `src/hooks.client.ts` (see [Web Apps section](#web-apps-sveltekit))
4. Add `window.__PUBLIC_GLITCHTIP_DSN__` injection in `hooks.server.ts`
5. Add `https://glitchtip.mana.how` to CSP `connect-src` (if CSP is configured)
6. Set `PUBLIC_GLITCHTIP_DSN` env variable in Docker
## Monitoring
- GlitchTip Dashboard: https://glitchtip.mana.how

View file

@ -12,6 +12,10 @@
"./nestjs": {
"types": "./dist/nestjs.d.ts",
"default": "./dist/nestjs.js"
},
"./browser": {
"types": "./dist/browser.d.ts",
"default": "./dist/browser.js"
}
},
"files": [
@ -22,6 +26,7 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"@sentry/browser": "^9.0.0",
"@sentry/node": "^9.0.0"
},
"peerDependencies": {

View file

@ -0,0 +1,128 @@
/**
* Browser Error Tracking for ManaCore SvelteKit Apps
*
* Uses @sentry/browser with GlitchTip as the self-hosted backend.
* This is the browser counterpart to the Node.js `index.ts`.
*
* @example
* ```typescript
* // In hooks.client.ts
* import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser';
* import type { HandleClientError } from '@sveltejs/kit';
*
* initErrorTracking({
* serviceName: 'calendar-web',
* dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__,
* environment: import.meta.env.MODE,
* });
*
* export const handleError: HandleClientError = ({ error }) => {
* handleSvelteError(error);
* };
* ```
*/
import * as Sentry from '@sentry/browser';
export interface BrowserErrorTrackingOptions {
/** Service/app name (e.g. 'calendar-web', 'contacts-web') */
serviceName: string;
/** GlitchTip/Sentry DSN. If not set, error tracking is disabled. */
dsn?: string;
/** Environment (development, staging, production) */
environment?: string;
/** Release/version string */
release?: string;
/** Sample rate for error events (0.0 to 1.0, default: 1.0) */
sampleRate?: number;
/** Sample rate for performance traces (0.0 to 1.0, default: 0.1) */
tracesSampleRate?: number;
/** Enable debug mode (default: false) */
debug?: boolean;
}
let initialized = false;
/**
* Initialize browser error tracking.
* If no DSN is provided, error tracking is silently disabled.
*/
export function initErrorTracking(options: BrowserErrorTrackingOptions): void {
if (initialized) return;
if (typeof window === 'undefined') return;
const dsn = options.dsn;
if (!dsn) {
if (options.debug) {
console.log(`[ErrorTracking] No DSN configured for ${options.serviceName} - disabled`);
}
return;
}
Sentry.init({
dsn,
environment: options.environment || 'production',
release: options.release,
sampleRate: options.sampleRate ?? 1.0,
tracesSampleRate: options.tracesSampleRate ?? 0.1,
debug: options.debug ?? false,
initialScope: {
tags: { service: options.serviceName },
},
});
initialized = true;
if (options.debug) {
console.log(
`[ErrorTracking] Initialized for ${options.serviceName} (${options.environment || 'production'})`
);
}
}
/**
* Handle SvelteKit client errors.
* Use this in hooks.client.ts handleError export.
*/
export function handleSvelteError(error: unknown): void {
if (!initialized) return;
Sentry.captureException(error);
}
/**
* Capture an exception manually
*/
export function captureException(error: unknown, context?: Record<string, unknown>): void {
if (!initialized) return;
Sentry.captureException(error, { extra: context });
}
/**
* Capture a message
*/
export function captureMessage(
message: string,
level: 'fatal' | 'error' | 'warning' | 'info' | 'debug' = 'info'
): void {
if (!initialized) return;
Sentry.captureMessage(message, level);
}
/**
* Set user context for error reports
*/
export function setUser(user: { id: string; email?: string } | null): void {
if (!initialized) return;
Sentry.setUser(user);
}
/**
* Set extra context tags
*/
export function setTag(key: string, value: string): void {
if (!initialized) return;
Sentry.setTag(key, value);
}
export { Sentry };