Skip to content

Commit d8b640b

Browse files
betegonclaude
andauthored
feat(docs): add Sentry SDK for error tracking, replay, and metrics (#122)
## Summary Adds @sentry/astro to the docs website for monitoring errors, user sessions, and performance. Also tracks custom metrics when users interact with the hero install command section. ## Changes - Integrates `@sentry/astro` with client and server configs - Enables error tracking, session replay (10% sample, 100% on error), and tracing - Adds two custom metrics: - `hero_command_copied` - tracks when users copy an install command - `hero_install_method_selected` - tracks when users switch between curl/npx/npm/pnpm/bun ## Test Plan 1. Run `cd docs && bun run dev` 2. Open browser console and verify Sentry initializes (enable `debug: true` in client config if needed) 3. Click the dropdown to change install method → metric sent 4. Click copy button → metric sent 5. Check Sentry project **Insights > Metrics** for the custom metrics ## Notes - `SENTRY_AUTH_TOKEN` env var needed for source maps upload in production - SDK is enabled in all environments including dev for testing --- Closes #117 --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1db571c commit d8b640b

6 files changed

Lines changed: 418 additions & 1 deletion

File tree

docs/astro.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import starlight from "@astrojs/starlight";
2+
import sentry from "@sentry/astro";
23
import { defineConfig } from "astro/config";
34

45
// Allow base path override via environment variable for PR previews
@@ -8,6 +9,14 @@ export default defineConfig({
89
site: "https://cli.sentry.dev",
910
base,
1011
integrations: [
12+
sentry({
13+
project: "cli-website",
14+
org: "sentry",
15+
authToken: process.env.SENTRY_AUTH_TOKEN,
16+
sourceMapsUploadOptions: {
17+
enabled: !!process.env.SENTRY_AUTH_TOKEN,
18+
},
19+
}),
1120
starlight({
1221
title: "Sentry CLI",
1322
favicon: "/favicon.png",

docs/bun.lock

Lines changed: 353 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@astrojs/starlight": "^0.31.1",
12+
"@sentry/astro": "^10.38.0",
1213
"astro": "^5.1.1",
1314
"sharp": "^0.33.5",
1415
"shiki": "^3.21.0"

docs/sentry.client.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Sentry from "@sentry/astro";
2+
3+
Sentry.init({
4+
dsn: "https://2aca5fe97c71868bc3aa7fb48620dc39@o1.ingest.us.sentry.io/4510798755856384",
5+
sendDefaultPii: true,
6+
integrations: [
7+
Sentry.browserTracingIntegration(),
8+
Sentry.replayIntegration(),
9+
],
10+
enableLogs: true,
11+
tracesSampleRate: 1.0,
12+
replaysSessionSampleRate: 0.1,
13+
replaysOnErrorSampleRate: 1.0,
14+
// Enable in all environments (including development)
15+
enabled: true,
16+
// Uncomment to debug Sentry initialization
17+
// debug: true,
18+
});
19+
20+
// Expose globally for inline scripts
21+
window.Sentry = Sentry;

docs/sentry.server.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from "@sentry/astro";
2+
3+
Sentry.init({
4+
dsn: "https://2aca5fe97c71868bc3aa7fb48620dc39@o1.ingest.us.sentry.io/4510798755856384",
5+
sendDefaultPii: true,
6+
enableLogs: true,
7+
tracesSampleRate: 1.0,
8+
// Enable in all environments (including development)
9+
enabled: true,
10+
});

docs/src/components/InstallSelector.astro

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,18 @@ const defaultOption = highlightedOptions[defaultIndex];
329329
});
330330
option.classList.add('selected');
331331
option.setAttribute('aria-selected', 'true');
332-
332+
333+
// Track install method selection with Sentry metrics
334+
try {
335+
if (typeof Sentry !== 'undefined' && Sentry.metrics && newLabel) {
336+
Sentry.metrics.count('hero_install_method_selected', 1, {
337+
attributes: { install_method: newLabel },
338+
});
339+
}
340+
} catch (e) {
341+
// Sentry not available, ignore
342+
}
343+
333344
// Close dropdown and return focus
334345
installBox.classList.remove('open');
335346
trigger.setAttribute('aria-expanded', 'false');
@@ -461,6 +472,18 @@ const defaultOption = highlightedOptions[defaultIndex];
461472
await navigator.clipboard.writeText(command);
462473
copyBtn.classList.add('copied');
463474
setTimeout(function() { copyBtn.classList.remove('copied'); }, 2000);
475+
476+
// Track copy event with Sentry metrics
477+
try {
478+
if (typeof Sentry !== 'undefined' && Sentry.metrics) {
479+
const installMethod = label ? label.textContent : 'unknown';
480+
Sentry.metrics.count('hero_command_copied', 1, {
481+
attributes: { install_method: installMethod },
482+
});
483+
}
484+
} catch (e) {
485+
// Sentry not available, ignore
486+
}
464487
}
465488
});
466489
}

0 commit comments

Comments
 (0)