Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/spotlight/src/electron-index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { init as ElectronSentryInit } from "@sentry/electron/renderer";
import { init as ReactSentryInit } from "@sentry/react";
import { _init } from "./index";
import { sentryBaseConfig } from "./sentry-config";
import { getIntegrations } from "./ui/lib/instrumentation";

// Static import - this blocks execution until Sentry loads
// Uses Sentry's recommended "Framework-Specific SDK" pattern for Electron v7+
// https://docs.sentry.io/platforms/javascript/guides/electron/#using-framework-specific-sdks
ElectronSentryInit(
{
...sentryBaseConfig,
dsn: "https://192df1a78878de014eb416a99ff70269@o1.ingest.sentry.io/4506400311934976",
environment: process.env.NODE_ENV,
release: `spotlight@${process.env.npm_package_version}`,
environment: process.env.NODE_ENV || sentryBaseConfig.environment,
integrations: getIntegrations(true),
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
Expand Down
7 changes: 6 additions & 1 deletion packages/spotlight/src/sentry-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Detect CI environment at runtime (not replaced by build process)
const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";

// Use build-time injected version for fossilized binaries, fallback to env var for npm/npx runs
declare const __SPOTLIGHT_VERSION__: string | undefined;
const version =
typeof __SPOTLIGHT_VERSION__ !== "undefined" ? __SPOTLIGHT_VERSION__ : process.env.npm_package_version;

export const sentryBaseConfig = {
enabled: Boolean(process.env.NODE_ENV) && process.env.NODE_ENV !== "development",
environment: isCI ? "github-ci" : process.env.NODE_ENV || "development",
release: `spotlight@${process.env.npm_package_version}`,
release: `spotlight@${version}`,
tracesSampleRate: 1,
enableLogs: true,
} as const;
7 changes: 6 additions & 1 deletion packages/spotlight/vite.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const aliases = {
export const defineProduction = {
"process.env.NODE_ENV": '"production"',
"process.env.npm_package_version": JSON.stringify(process.env.npm_package_version),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is redundant now then? Or __SPOTLIGHT_VERSION__ was never needed. Which one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are needed for different scenarios:

  • __SPOTLIGHT_VERSION__: Injected at build time via Vite define, so it's baked into the code and available everywhere, including fossilized binaries (CLI/Docker standalone executables) where process.env.npm_package_version is undefined
  • process.env.npm_package_version: Available at runtime for npm/npx runs, but not in fossilized binaries

The code in sentry-config.ts prefers __SPOTLIGHT_VERSION__ but falls back to process.env.npm_package_version as a safety net. This ensures:

  1. Fossilized binaries work (they only have __SPOTLIGHT_VERSION__)
  2. npm/npx runs work (both available, but __SPOTLIGHT_VERSION__ takes precedence)
  3. Development builds work (fallback to env var)

We keep process.env.npm_package_version in defineProduction because other parts of the codebase may reference it directly, not just Sentry.

// Injected version constant for runtime use (especially in fossilized binaries)
__SPOTLIGHT_VERSION__: JSON.stringify(process.env.npm_package_version),
// Set to false for tree-shaking; Electron config overrides to true
__IS_ELECTRON__: false,
};
Expand Down Expand Up @@ -42,9 +44,12 @@ export const sentryPluginOptions = {
org: process.env.MAIN_VITE_SENTRY_ORG,
authToken: process.env.MAIN_VITE_SENTRY_AUTH_TOKEN,
release: {
name: process.env.npm_package_version,
name: `spotlight@${process.env.npm_package_version}`, // Match runtime format
// Disable virtual module injection - release is set via Sentry.init() at runtime.
// This prevents circular dependency issues in Node 24.x when using preserveModules.
inject: false,
},
sourcemaps: {
filesToDeleteAfterUpload: ["**/*.js.map"],
},
};
4 changes: 4 additions & 0 deletions packages/spotlight/vite.electron.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default defineConfig(({ mode }) => {
publicDir: "public",
plugins: [
...reactPlugins,
sentryVitePlugin({
...sentryPluginOptions,
project: process.env.MAIN_VITE_SENTRY_PROJECT,
}),
electron({
main: {
entry: "src/electron/main/index.ts",
Expand Down
Loading