Skip to content
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
This repository was archived by the owner on Oct 29, 2026. It is now read-only.

@sentry/vite-plugin silently breaks event capture when combined with tauri-plugin-sentry #916

Closed

Description

@ottosson

I'm having problems using @sentry/vite-plugin with Tauri as it breaks the error logging. I've narrowed it to be the source maps generation. If I disable it the errors shows up in Sentry, if I enable it again the errors does not... I have a minimal reproducible example here: https://github.com/ottosson/sentry-vite-plugin-repro.

I've used Claude to find the problem and generate an issue (slop warning):


Summary

In a Tauri 2 app that uses tauri-plugin-sentry (which injects @sentry/browser into the webview and routes envelopes through a Tauri IPC transport to the Rust SDK), activating @sentry/vite-plugin at build time silently prevents most runtime errors from reaching Sentry. Manual Sentry.captureException(new Error(...)) still works, but errors thrown inside React event handlers, setTimeout callbacks, or any code path wrapped by browserApiErrorsIntegration are dropped. The SDK returns a looking-fine event ID; no envelope is ever produced.

The failure is narrowed to the plugin's per-chunk debug-ID injection:

  • Plugin skipped (SENTRY_AUTH_TOKEN unset at build) → every capture arrives.
  • Plugin active with sourcemaps.disable: true → every capture arrives.
  • Plugin active with default config → only manual captures arrive.

Minimal reproducer

https://github.com/ottosson/sentry-vite-plugin-repro (please fork/upload from the attached repro folder)

Three-button Tauri 2 app; each button exercises a different capture path. README walks through the three build variants.

Steps:

  1. npm install
  2. Replace DSN in src-tauri/src/lib.rs and org/project in vite.config.ts.
  3. Build with plugin active:
    $env:SENTRY_AUTH_TOKEN = "sntrys_..."
    npm run tauri build
  4. Install, click all three buttons.
  5. Observe in Sentry: only button 3 (manual capture) lands. Buttons 1 and 2 show Uncaught Error: ... in devtools console but produce no Sentry events.
  6. Rebuild with SENTRY_AUTH_TOKEN unset, or with sourcemaps: { disable: true } in the plugin config → all three buttons now produce events.

Environment

  • @sentry/vite-plugin 5.2.0 (also reproduces on 5.1.1)
  • @sentry/browser 10.46.0 (transitively via tauri-plugin-sentry)
  • tauri-plugin-sentry latest on main (timfish/sentry-tauri)
  • Tauri 2.10.x, React 19.2.x, react-dom 19.2.x
  • Vite 8.0.x, @vitejs/plugin-react 6.0.x
  • Windows 11, WebView2 Evergreen
  • Node 20+

Diagnostic observations

Hooking window.__TAURI_INTERNALS__.invoke to observe plugin:sentry|envelope calls:

  • Path A (plugin active): Sentry.captureException(err) invocations for React-onClick errors return an event ID but no envelope is invoked at the IPC level.
  • Path B (plugin absent): same code path produces an envelope.

Other observations that partially isolate the issue:

  • The thrown error has __sentry_captured__ === true after Sentry's browserApiErrorsIntegration wrapper runs. Explicitly stripping this marker does not restore delivery.
  • dedupeIntegration removal via integrations: (d) => d.filter((i) => i.name !== "Dedupe") does not restore delivery on its own.
  • setTimeout(() => Sentry.captureException(err), 0) deferral does not restore delivery.
  • Manual capture with a completely fresh new Error() (unique message + fresh stack) does land — which is why we suspect dedupe or marker-based gating at first, but those turn out not to be the individual cause.
  • Only avoiding the plugin's chunk-level debug-ID injection (either via sourcemaps.disable: true on the plugin, or by skipping the plugin entirely) restores delivery.

The injected snippet the plugin prepends to each chunk:

try {
  globalThis._sentryDebugIds = globalThis._sentryDebugIds || {};
  globalThis._sentryDebugIds[new Error().stack] = "<uuid>";
} catch {}

Something about this snippet — its timing, or the Error creation/stack capture, or the globalThis mutation — interacts with @sentry/browser v10's browserApiErrorsIntegration + dedupeIntegration in a way that causes the wrapper's own internal capture (and any subsequent application capture of the same error) to be silently dropped. I have not been able to pin it to a single integration.

What we need

Either:

  1. Confirmation that this combination (plugin + tauri-plugin-sentry's custom transport) is not a supported configuration, along with guidance on what to configure differently — or
  2. A fix in either the plugin's injection strategy or @sentry/browser's capture gating so that events produced during or after the wrapper's catch aren't silently discarded.

Activity

  1. linear-code commented on Apr 20, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 20, 2026
  3. added
    Bug
    on Apr 20, 2026
  4. logaretm commented on Apr 20, 2026

    @logaretm
    Member

    Thanks for reporting, our team is already looking into this and will report back.

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 20, 2026
  6. timfish commented on Apr 22, 2026

    @timfish
    Contributor

    @ottosson is your repro still private? I can't access it!

  7. ottosson commented on Apr 22, 2026

    @ottosson
    Author

    @timfish sorry about that! It's public now

  8. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 22, 2026
  9. timfish commented on Apr 24, 2026

    @timfish
    Contributor

    Struggling a bit to reproduce this. I appear to get issues for the first two buttons but I've only tried in development mode:

    Image
  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 24, 2026
  11. ottosson commented on Apr 24, 2026

    @ottosson
    Author

    Are you sure your VIte config is building with sentryVitePlugin set?
    I think I only got this issue when building for production. Not sure it's required, but worth a shot

  12. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 24, 2026
  13. timfish commented on Apr 24, 2026

    @timfish
    Contributor

    Yes, I removed the conditional and just add the plugin like this. With an invalid auth/org/project the plugin injects as usual and simply reports an error for uploading to Sentry.

    I will check production!

    Image
  14. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 24, 2026
  15. ottosson commented on Jun 2, 2026

    @ottosson
    Author

    I've used Claude (Opus 4.8) to really dig into this again. It claims to have found the root cause, which is not the Vite plugin apparently!

    I don't mean to bloat your inbox with loads of AI output, but I have verified the solution and it seems to work. I don't however know if the solution is the best approach. I leave that up to you :)

    Here's a fork with the fix: https://github.com/ottosson/sentry-tauri

    Claude:
    Root-caused — and it isn't @sentry/vite-plugin. Posting the full chain in case anyone else lands here; I think this issue can be closed on this repo and tracked downstream.

    TL;DR

    The plugin is behaving correctly. With debug-ID injection on, @sentry/browser attaches a source-map debug image to every event:

    "debug_meta": { "images": [ { "type": "sourcemap", "code_file": "...", "debug_id": "..." } ] }

    In a Tauri app that uses tauri-plugin-sentry, frontend events are sent over IPC to the Rust process, which deserializes them with sentry::Envelope::from_slice. That eagerly parses the event item — envelope.rs#L645:

    EnvelopeItemType::Event => serde_json::from_slice(payload).map(EnvelopeItem::Event),

    …into sentry_types::protocol::Event, and sentry-rust's DebugImage enum (v7.rs#L903-L915) is a closed #[serde(tag = "type")] with only apple/symbolic/proguard/wasm — no sourcemap variant and no catch-all:

    #[serde(rename_all = "snake_case", tag = "type")]
    pub enum DebugImage {
        Apple(AppleDebugImage),
        Symbolic(SymbolicDebugImage),
        Proguard(ProguardDebugImage),
        Wasm(WasmDebugImage),
    }

    So deserialization fails with EnvelopeError::InvalidItemPayload (envelope.rs#L39), from_slice returns Err, and tauri-plugin-sentry silently skips it — its if let Ok(envelope) has no error arm (commands.rs#L20-L22). Every frontend event is dropped. Setting sourcemaps: { disable: true } or removing the plugin drops debug_meta → events flow again, which is what made it look like a bundler-plugin bug.

    Versions: my app compiles sentry-types 0.42.0 (via sentry 0.42), but the gap is identical at 0.46.2 (latest) and 0.42.0, so a version bump doesn't fix it.

    Reproduction / proof

    Tauri 2 app + tauri-plugin-sentry + a frontend built with this plugin and SENTRY_AUTH_TOKEN set. Throw from a React handler. Verified end-to-end against a live project:

    • injection off → all events arrive;
    • injection on → 0 events; Rust-side Envelope::from_slice returns invalid item payload;
    • with fix (1) below → events arrive and symbolicate to original src/*.tsx frames.

    Where the actual fixes belong

    1. tauri-plugin-sentry — src/commands.rs, fn envelope.
    Today (L20-L22):

    let envelope = Envelope::from_slice(&buffer);   // L20
    if let Ok(envelope) = envelope {                // L22  (no else: silent drop on Err)

    Don't drop on parse failure — forward the raw bytes (keeps debug_meta, so server-side debug-ID symbolication still works). Envelope::from_bytes_raw already exists for this:

    let parsed = Envelope::from_slice(&buffer);
    if parsed.is_err() {
        if let Ok(raw) = Envelope::from_bytes_raw(buffer) {
            sentry_client.send_envelope(raw);
        }
        return;
    }
    if let Ok(envelope) = parsed {
        // ...existing typed path unchanged...
    }

    2. sentry-rust — sentry-types/src/protocol/v7.rs, enum DebugImage.
    Give it a SourceMap variant, or an Other(Map<String, Value>) catch-all so unknown/forward-compatible debug-image types round-trip instead of failing the whole event. There's direct precedent in the same file: the Context enum already ends with one — v7.rs#L1106-L1107:

    #[serde(rename = "unknown")]
    Other(Map<String, Value>),
  16. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 2, 2026
  17. timfish commented on Jun 3, 2026

    @timfish
    Contributor

    Thanks, this does sound like it's the cause and the fixes sound convincing!

    I'll take another look.

  18. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 3, 2026
  19. timfish commented on Aug 17, 2026

    @timfish
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions