Tauri Plugin for Sentry
npm install tauri-plugin-sentry-apitauri-plugin-sentryA Sentry plugin for Tauri v2.
It's perfectly reasonable to use Sentry's Rust and browser SDKs separately in a
Tauri app. However, this plugin passes browser breadcrumbs and events through
the Rust backend which has a number of advantages:
- Browser events are enriched with Rust, OS and device context
- Events from both Rust and browser will have the same app and device context
- Breadcrumbs are merged from both the Rust and browser SDKs
- See what was happening in the Rust backend and the browser frontend at the
time of the event
sentry-rust-minidump is re-exported by sentry-tauri so you don't need to add
it as dependencies.
Add sentry and tauri-plugin-sentry to dependencies in Cargo.toml:
``toml`
[dependencies]
sentry = "0.42"
tauri-plugin-sentry = "0.5"
Run one of these commands to add the capabilities:
- npm: npm run tauri add sentryyarn run tauri add sentry
- yarn: pnpm tauri add sentry
- pnpm: cargo tauri add sentry
- cargo:
however, make sure that you have sentry:default in your capabilities:
###### src-tauri/capabilities/*.json
`json`
{
"$schema": "./../gen/schemas/windows-schema.json",
"identifier": "main",
"local": true,
"windows": [
"main"
],
"permissions": [
"sentry:default" // <- important
]
}
This example also shows usage of
sentry_rust_minidump which
allows you to capture minidumps for native crashes from a separate crash
reporting process.
`rust
use sentry;
use tauri_plugin_sentry;
pub fn run() {
let client = sentry::init((
"__YOUR_DSN__",
sentry::ClientOptions {
release: sentry::release_name!(),
auto_session_tracking: true,
..Default::default()
},
));
// Caution! Everything before here runs in both app and crash reporter processes
#[cfg(not(target_os = "ios"))]
let _guard = tauri_plugin_sentry::minidump::init(&client);
// Everything after here runs in only the app process
tauri::Builder::default()
.plugin(tauri_plugin_sentry::init(&client))
.run(tauri::generate_context!())
.expect("error while running tauri app");
}
`
The Plugin:
- By default injects and initialises @sentry/browser in every web-viewtransport
- Includes custom and beforeBreadcrumb hook that passes events andinvoke
breadcrumbs to the Rust SDK via the Tauri APIserde
- Tauri + + existing Sentry Rust types = Deserialisation mostly Just
Works™️
By default the plugin injects a pre-minified version of @sentry/browser. IfSentry.init
you want to configure Sentry in the browser yourself, you can disable the
injection and pass the default config to .
Disable automatic injection:
`rust`
tauri::Builder::default()
.plugin(tauri_plugin_sentry::init_with_no_injection(&client))
.run(tauri::generate_context!())
.expect("error while running tauri app");
`ts
import { defaultOptions } from "tauri-plugin-sentry-api";
import * as Sentry from "@sentry/browser";
Sentry.init({
...defaultOptions,
/**
* Your custom configuration here
*/
});
`
Clone this repository and install dependencies:
`shell`
> yarn install
In examples/basic-app/src-tauri/src/main.rs replace the DSN with your DSN
Run in development mode:
`shell``
> yarn example