Skip to content

Commit 9e45696

Browse files
feat: add sentry
1 parent 86bef71 commit 9e45696

File tree

6 files changed

+112
-68
lines changed

6 files changed

+112
-68
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
VITE_MOVIES_PALETTES_API=http://localhost:5174/api
2+
VITE_SENTRY_DSN="your-sentry-dsn-here"
3+
VITE_ENVIRONMENT="local"

.github/workflows/deploy_prod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
environment: production
3535
env:
3636
VITE_MOVIES_PALETTES_API: "https://movies-palettes.adriencarpentier.com/api"
37+
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
38+
VITE_ENVIRONMENT: "production"
3739
needs: bump-version
3840
steps:
3941

.github/workflows/deploy_staging.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
environment: staging
1414
env:
1515
VITE_MOVIES_PALETTES_API: "https://movies-palettes.adriencarpentier.com/api"
16+
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
17+
VITE_ENVIRONMENT: "staging"
1618
steps:
1719

1820
- name: Checkout repo

bun.lock

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
"": {
55
"name": "cyclic-cellular-automaton",
66
"dependencies": {
7+
"@sentry/browser": "^9.0.0",
78
"chroma-js": "^3.1.2",
89
"three": "^0.171.0",
910
"tweakpane": "^4.0.5",
1011
},
1112
"devDependencies": {
1213
"@biomejs/biome": "^1.9.4",
1314
"@types/bun": "latest",
14-
"@types/node": "^22.12.0",
15-
"vite": "^6.0.11",
15+
"@types/node": "^22.13.1",
16+
"vite": "^6.1.0",
1617
},
1718
"peerDependencies": {
1819
"typescript": "^5.7.3",
@@ -126,6 +127,18 @@
126127

127128
"@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.31.0", "", { "os": "win32", "cpu": "x64" }, "sha512-ul8rnCsUumNln5YWwz0ted2ZHFhzhRRnkpBZ+YRuHoRAlUji9KChpOUOndY7uykrPEPXVbHLlsdo6v5yXo/TXw=="],
128129

130+
"@sentry-internal/browser-utils": ["@sentry-internal/browser-utils@9.0.0", "", { "dependencies": { "@sentry/core": "9.0.0" } }, "sha512-J5aBL0RV42WNx9xlw2a2MK1BBXAOwxYT2Hc9VNkuygwGzVEFimZEUKlaYKaDbM/XRUA0TRcYQaKkmGKqpDbxxw=="],
131+
132+
"@sentry-internal/feedback": ["@sentry-internal/feedback@9.0.0", "", { "dependencies": { "@sentry/core": "9.0.0" } }, "sha512-4k4MxnvNFYbA8mPBOgY0gbK/e6dFA8JTDmt88NppSuBowu1uIYnVEFB3DWyaLvi60RXcbT4LnKvo70LTCpIEfQ=="],
133+
134+
"@sentry-internal/replay": ["@sentry-internal/replay@9.0.0", "", { "dependencies": { "@sentry-internal/browser-utils": "9.0.0", "@sentry/core": "9.0.0" } }, "sha512-TqcOA6QhEqq4afR34rb/e0rpusafGh3XujW6hO0AIuv0inpfWhCN6i71hGR0Qt0gJNJaStiNu4Rrwj1AsebGTQ=="],
135+
136+
"@sentry-internal/replay-canvas": ["@sentry-internal/replay-canvas@9.0.0", "", { "dependencies": { "@sentry-internal/replay": "9.0.0", "@sentry/core": "9.0.0" } }, "sha512-KjN7Dx9CctwU06xfTEQjWz/MK00fDbHF2GUStDYe83Rt+8CmYXUHMRTr/UEMQxL8rH1O4JEGUH5fFWxTWu2gxw=="],
137+
138+
"@sentry/browser": ["@sentry/browser@9.0.0", "", { "dependencies": { "@sentry-internal/browser-utils": "9.0.0", "@sentry-internal/feedback": "9.0.0", "@sentry-internal/replay": "9.0.0", "@sentry-internal/replay-canvas": "9.0.0", "@sentry/core": "9.0.0" } }, "sha512-+BgusObsLnHwiA+xLm9d3YmdzRXFSUTG7YSSZYZ94NpQdnQlEb6a0ER6abCzmxmKAhNykf5MzLrPRz65bL83WQ=="],
139+
140+
"@sentry/core": ["@sentry/core@9.0.0", "", {}, "sha512-oaOOC1rQ5NHuOJ5ciw5NjdvmgG+q3UJS5v+s1d2eFzi/n5OpxULvqce4aG3XDBJ/Hu+fxW+fbVW96JwAKNk2Tg=="],
141+
129142
"@types/bun": ["@types/bun@1.2.2", "", { "dependencies": { "bun-types": "1.2.2" } }, "sha512-tr74gdku+AEDN5ergNiBnplr7hpDp3V1h7fqI2GcR/rsUaM39jpSeKH0TFibRvU0KwniRx5POgaYnaXbk0hU+w=="],
130143

131144
"@types/estree": ["@types/estree@1.0.6", "", {}, "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw=="],

main.ts

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,31 @@ import { CCA3D } from "./3d/cca_3d"
2323
import type { AutomatonBase } from "./types/Automaton"
2424
import type { Settings } from "./types/Settings"
2525
import { fetchMoviePalettes, moviePalettes } from "./utils/fetchMoviePalettes"
26+
import * as Sentry from "@sentry/browser"
2627

2728
let pane: Pane
2829
let settings: Settings
2930
let automaton: AutomatonBase
3031

3132
const MOVIES_PALETTES_API = import.meta.env.VITE_MOVIES_PALETTES_API
3233

34+
// Initialize Sentry before any other code
35+
Sentry.init({
36+
dsn: import.meta.env.VITE_SENTRY_DSN,
37+
environment: import.meta.env.VITE_ENVIRONMENT,
38+
release: APP_VERSION,
39+
integrations: [
40+
Sentry.browserTracingIntegration(),
41+
Sentry.replayIntegration(),
42+
],
43+
// Tracing
44+
tracesSampleRate: 1.0, // Capture 100% of the transactions
45+
// Session Replay
46+
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
47+
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
48+
})
49+
50+
3351
window.onload = () => {
3452
const getInitialAlgo = () => {
3553
const path = window.location.pathname.slice(1) // Remove leading slash
@@ -393,72 +411,78 @@ const createAutomaton = async (
393411
height: number,
394412
settings: Settings,
395413
): Promise<AutomatonBase> => {
396-
const resolution: number = settings.resolution || 5
397-
const paletteColors = settings.palette
398-
? moviePalettes.get(settings.palette)?.colors
399-
: undefined
400-
401-
switch (settings.algo) {
402-
case "cca-1D":
403-
return new CCA1D(
404-
canvasEl,
405-
width,
406-
height,
407-
settings.cca1dColorsCount || 4,
408-
paletteColors,
409-
)
410-
case "cca-2D":
411-
return new CCA2D(
412-
settings.cca2dThreshold,
413-
canvasEl,
414-
width,
415-
height,
416-
resolution,
417-
settings.cca2dColorsCount,
418-
paletteColors,
419-
)
420-
case "cca-3D":
421-
return new CCA3D(
422-
canvasEl,
423-
width,
424-
height,
425-
settings.cca3dCubeDimension,
426-
settings.cca3dThreshold,
427-
settings.cca3dColorsCount,
428-
paletteColors,
429-
)
430-
case "conway":
431-
return new ConwayAutomaton(canvasEl, width, height, resolution)
432-
case "immigration":
433-
return new ImmigrationAutomaton(
434-
canvasEl,
435-
width,
436-
height,
437-
resolution,
438-
undefined, // colorsCount (will be forced to 3)
439-
paletteColors, // Pass palette colors
440-
)
441-
case "quadlife":
442-
return new QuadLifeAutomaton(
443-
canvasEl,
444-
width,
445-
height,
446-
resolution,
447-
undefined, // colorsCount (will be forced to 5)
448-
paletteColors, // Pass palette colors
449-
)
450-
case "langton":
451-
return new LangtonAutomaton(canvasEl, width, height, resolution)
452-
case "entropy":
453-
return new EntropyAutomaton(
454-
canvasEl,
455-
width,
456-
height,
457-
resolution,
458-
settings.entropyColorsCount,
459-
)
460-
default:
461-
throw new Error(`Unknown algorithm: ${settings.algo}`)
414+
try {
415+
const resolution: number = settings.resolution || 5
416+
const paletteColors = settings.palette
417+
? moviePalettes.get(settings.palette)?.colors
418+
: undefined
419+
420+
switch (settings.algo) {
421+
case "cca-1D":
422+
return new CCA1D(
423+
canvasEl,
424+
width,
425+
height,
426+
settings.cca1dColorsCount || 4,
427+
paletteColors,
428+
)
429+
case "cca-2D":
430+
return new CCA2D(
431+
settings.cca2dThreshold,
432+
canvasEl,
433+
width,
434+
height,
435+
resolution,
436+
settings.cca2dColorsCount,
437+
paletteColors,
438+
)
439+
case "cca-3D":
440+
return new CCA3D(
441+
canvasEl,
442+
width,
443+
height,
444+
settings.cca3dCubeDimension,
445+
settings.cca3dThreshold,
446+
settings.cca3dColorsCount,
447+
paletteColors,
448+
)
449+
case "conway":
450+
return new ConwayAutomaton(canvasEl, width, height, resolution)
451+
case "immigration":
452+
return new ImmigrationAutomaton(
453+
canvasEl,
454+
width,
455+
height,
456+
resolution,
457+
undefined, // colorsCount (will be forced to 3)
458+
paletteColors, // Pass palette colors
459+
)
460+
case "quadlife":
461+
return new QuadLifeAutomaton(
462+
canvasEl,
463+
width,
464+
height,
465+
resolution,
466+
undefined, // colorsCount (will be forced to 5)
467+
paletteColors, // Pass palette colors
468+
)
469+
case "langton":
470+
return new LangtonAutomaton(canvasEl, width, height, resolution)
471+
case "entropy":
472+
return new EntropyAutomaton(
473+
canvasEl,
474+
width,
475+
height,
476+
resolution,
477+
settings.entropyColorsCount,
478+
)
479+
default:
480+
throw new Error(`Unknown algorithm: ${settings.algo}`)
481+
}
482+
} catch (error) {
483+
Sentry.captureException(error)
484+
console.error("Failed to create automaton:", error)
485+
throw error
462486
}
463487
}
464488

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"check": "biome check --write ."
1111
},
1212
"dependencies": {
13+
"@sentry/browser": "^9.0.0",
1314
"chroma-js": "^3.1.2",
1415
"three": "^0.171.0",
1516
"tweakpane": "^4.0.5"

0 commit comments

Comments
 (0)