diff --git a/bun.lock b/bun.lock index 95a8219aac..23aebbde6a 100644 --- a/bun.lock +++ b/bun.lock @@ -227,6 +227,7 @@ "dependencies": { "@opencode-ai/app": "workspace:*", "@opencode-ai/ui": "workspace:*", + "@sentry/solid": "catalog:", "@solid-primitives/i18n": "2.2.1", "@solid-primitives/storage": "catalog:", "@solidjs/meta": "catalog:", @@ -242,6 +243,7 @@ }, "devDependencies": { "@actions/artifact": "4.0.0", + "@sentry/vite-plugin": "catalog:", "@types/bun": "catalog:", "@types/node": "catalog:", "@typescript/native-preview": "catalog:", diff --git a/packages/desktop-electron/electron.vite.config.ts b/packages/desktop-electron/electron.vite.config.ts index 6903d5ed20..f23ec7b708 100644 --- a/packages/desktop-electron/electron.vite.config.ts +++ b/packages/desktop-electron/electron.vite.config.ts @@ -1,3 +1,4 @@ +import { sentryVitePlugin } from "@sentry/vite-plugin" import { defineConfig } from "electron-vite" import appPlugin from "@opencode-ai/app/vite" @@ -7,6 +8,23 @@ const channel = (() => { return "dev" })() +const sentry = + process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT + ? sentryVitePlugin({ + authToken: process.env.SENTRY_AUTH_TOKEN, + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, + telemetry: false, + release: { + name: process.env.SENTRY_RELEASE ?? process.env.VITE_SENTRY_RELEASE, + }, + sourcemaps: { + assets: "./out/renderer/**", + filesToDeleteAfterUpload: "./out/renderer/**/*.map", + }, + }) + : false + export default defineConfig({ main: { define: { @@ -26,10 +44,11 @@ export default defineConfig({ }, }, renderer: { - plugins: [appPlugin], + plugins: [appPlugin, sentry], publicDir: "../../../app/public", root: "src/renderer", build: { + sourcemap: true, rollupOptions: { input: { main: "src/renderer/index.html", diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index bcb80d9e69..d23bd8aded 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -26,6 +26,7 @@ "dependencies": { "@opencode-ai/app": "workspace:*", "@opencode-ai/ui": "workspace:*", + "@sentry/solid": "catalog:", "@solid-primitives/i18n": "2.2.1", "@solid-primitives/storage": "catalog:", "@solidjs/meta": "catalog:", @@ -41,6 +42,7 @@ }, "devDependencies": { "@actions/artifact": "4.0.0", + "@sentry/vite-plugin": "catalog:", "@types/bun": "catalog:", "@types/node": "catalog:", "@typescript/native-preview": "catalog:", diff --git a/packages/desktop-electron/src/renderer/index.tsx b/packages/desktop-electron/src/renderer/index.tsx index 30e882e237..2f3f3fd73b 100644 --- a/packages/desktop-electron/src/renderer/index.tsx +++ b/packages/desktop-electron/src/renderer/index.tsx @@ -9,6 +9,7 @@ import { ServerConnection, useCommand, } from "@opencode-ai/app" +import * as Sentry from "@sentry/solid" import type { AsyncStorage } from "@solid-primitives/storage" import { MemoryRouter } from "@solidjs/router" import { createEffect, createResource, onCleanup, onMount, Show } from "solid-js" @@ -25,6 +26,19 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) { throw new Error(t("error.dev.rootNotFound")) } +if (!import.meta.env.DEV && import.meta.env.VITE_SENTRY_DSN) { + Sentry.init({ + dsn: import.meta.env.VITE_SENTRY_DSN, + environment: import.meta.env.VITE_SENTRY_ENVIRONMENT ?? import.meta.env.MODE, + release: import.meta.env.VITE_SENTRY_RELEASE ?? `desktop-electron@${pkg.version}`, + initialScope: { + tags: { + platform: "desktop-electron", + }, + }, + }) +} + void initI18n() const deepLinkEvent = "opencode:deep-link"