Skip to content

Integrate Sentry error tracking across Electron and Rust#7643

Open
jh-block wants to merge 15 commits intomainfrom
jhugo/sentry
Open

Integrate Sentry error tracking across Electron and Rust#7643
jh-block wants to merge 15 commits intomainfrom
jhugo/sentry

Conversation

@jh-block
Copy link
Collaborator

@jh-block jh-block commented Mar 4, 2026

Summary

Adds Sentry error tracking across the full stack — Electron desktop app and Rust backend — with the DSN injected at build time so it never appears in source code.

Sentry integration (Electron + Rust)

  • Main process: @sentry/electron/main initialized at app startup
  • Preload: @sentry/electron/preload imported for IPC bridge between main and renderer
  • Renderer: @sentry/electron/renderer initialized for frontend error capture
  • Rust: sentry crate with tower, tower-http, and tracing features; NewSentryLayer and SentryHttpLayer added to axum for distributed tracing

Telemetry consent gating

  • Sentry events are gated on user telemetry consent via beforeSend/beforeSendTransaction hooks (Electron) and is_telemetry_enabled() check (Rust)
  • Users must opt in to telemetry before any Sentry data is sent

Build-time DSN injection

The Sentry DSN is not hard-coded in source. Instead, it's injected at build time via the SENTRY_DSN environment variable:

  • Rust: option_env!("SENTRY_DSN") reads the env var at compile time; if unset, Sentry is fully disabled
  • Electron: process.env.SENTRY_DSN injected via Vite define block; if empty, Sentry SDK initializes in disabled mode
  • CI/CD: SENTRY_DSN passed as a GitHub Actions secret through release and canary workflows to all bundle-desktop reusable workflows
  • Cross-compilation: SENTRY_DSN added to Cross.toml passthrough list for Linux cross-compiled builds

This means:

Build scenario Sentry enabled?
Official release/canary build (CI has SENTRY_DSN secret) Yes
Clone + local build (no env var set) No
Clone + own DSN (SENTRY_DSN=... cargo build) Yes, with their DSN

Environment tagging

  • Electron passes GOOSE_ENVIRONMENT env var when spawning goosed (production for packaged app, development otherwise)
  • Rust reads GOOSE_ENVIRONMENT, defaulting to development if unset

Setup required

After merging, add a repository secret named SENTRY_DSN with the DSN value.

Test plan

  • Verify cargo check -p goose-server compiles without SENTRY_DSN set (no DSN baked in)
  • Verify SENTRY_DSN=test cargo check -p goose-server compiles with DSN baked in
  • Verify Electron app starts without errors when SENTRY_DSN is not set
  • After adding the repo secret, verify a canary build produces binaries with Sentry enabled

🤖 Generated with Claude Code

@jh-block jh-block marked this pull request as draft March 4, 2026 14:01
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 329a5ec0a9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jh-block jh-block marked this pull request as ready for review March 4, 2026 21:29
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5fc8531c3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0571a735a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca5bc55a62

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

jh-block and others added 9 commits March 5, 2026 13:43
- Add @sentry/electron to the desktop app (main, preload, renderer)
- Add sentry crate to goose-server with tower layers for distributed tracing
- Tag events with environment (production for packaged app, development otherwise)
- Pass GOOSE_ENVIRONMENT from Electron to goosed for consistent environment tagging
- Configure Vite to properly bundle @sentry/electron in preload and main builds
- Electron main: use beforeSend to drop events until telemetry is confirmed enabled
- Electron renderer: same beforeSend gate, enabled alongside existing analytics flag
- Rust: skip Sentry init entirely when telemetry is disabled (empty DSN)
- Respects GOOSE_TELEMETRY_OFF env var and GOOSE_TELEMETRY_ENABLED config
Remove the hard-coded Sentry DSN from source code and instead inject it
via the SENTRY_DSN environment variable at build time. This ensures that
cloned/forked builds don't send errors to our Sentry project, while
official release and canary builds get the DSN from a GitHub Actions
secret.

- Rust: use option_env!("SENTRY_DSN") for compile-time injection
- Electron: use process.env.SENTRY_DSN via Vite define block
- CI: pass SENTRY_DSN secret through release and canary workflows
- Cross.toml: add SENTRY_DSN to passthrough for cross-compiled builds

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Disable sentry's default features (which pull in native-tls/openssl-sys)
and explicitly enable the needed features with rustls instead, matching
the rest of the codebase which uses rustls with aws_lc_rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sentry was only initialized when is_telemetry_enabled() was true at
process startup, so first-run sessions (where the user opts in after
goosed starts) silently dropped all backend errors and traces. Mirror
the Electron pattern: always init Sentry when a DSN is present but use
before_send / traces_sampler hooks that re-evaluate consent on every
event, so opt-in (and opt-out) take effect immediately without restart.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TelemetrySettings treated null (no choice yet) as enabled, while
renderer.tsx and the Rust backend both treat it as disabled. This
caused the Settings toggle to show "on" even though telemetry was
actually off for the session. Use value === true consistently.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both renderer and main process called Sentry.init() at import time,
which started collecting breadcrumbs and scope data before the user
consented. The beforeSend hooks only filtered at send time, so the
first post-consent error could include pre-consent breadcrumbs.

Defer Sentry.init() into an ensureSentryInitialized() guard that
runs only when setSentryTelemetryEnabled(true) / enableSentryTelemetry(true)
is called. This ensures no data is collected before consent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Clean install to ensure all platform-specific optional dependencies
are present in the lockfile, fixing CI validation failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 61c5fb6dbd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Use app.getVersion() and app.isPackaged instead of process.env vars
that are only set during npm scripts. This ensures packaged desktop
builds report the correct release version and production environment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bd880b47d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

is_telemetry_enabled() calls Config::get_param() which reads and
parses the config file from disk on every invocation. In the Sentry
traces_sampler callback this runs on every transaction, adding
unnecessary latency. Cache the result in an AtomicBool with a
5-second TTL so consent changes still take effect promptly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80323f02e9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

jh-block and others added 2 commits March 5, 2026 15:09
Replace the TTL-based cache with a Lazy<AtomicBool> that is
initialised once from config and updated immediately via
set_telemetry_enabled() whenever the telemetry key is written
through the /config/upsert, /config/remove, or CLI configure paths.

This gives hot paths (Sentry before_send / traces_sampler) zero
disk I/O while ensuring opt-in and opt-out take effect instantly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b542d0ad89

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

The env-var kill switch is a hard disable. Prevent config writes
from re-enabling telemetry when GOOSE_TELEMETRY_OFF is set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant