Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timfish/sentry-tauri
A Tauri plugin for Sentry
https://github.com/timfish/sentry-tauri
Last synced: about 9 hours ago
JSON representation
A Tauri plugin for Sentry
- Host: GitHub
- URL: https://github.com/timfish/sentry-tauri
- Owner: timfish
- Created: 2022-02-19T23:39:16.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-19T12:46:52.000Z (23 days ago)
- Last Synced: 2025-01-04T07:13:16.367Z (7 days ago)
- Language: Rust
- Size: 1.26 MB
- Stars: 65
- Watchers: 3
- Forks: 17
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-tauri - sentry-tauri - Capture JavaScript errors, Rust panics and native crash minidumps to Sentry. (Development / Plugins)
README
# `tauri-plugin-sentry`
A 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## Installation
`sentry` and `sentry-rust-minidump` are re-exported by `sentry-tauri` so you
don't need to add them as dependencies.Add `tauri-plugin-sentry` to dependencies in `Cargo.toml`:
```toml
[dependencies]
tauri-plugin-sentry = "0.3"
```Run one of these commands to add the capabilities:
- npm: `npm run tauri add sentry`
- yarn: `yarn run tauri add sentry`
- pnpm: `pnpm tauri add sentry`
- cargo: `cargo tauri add sentry`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
]
}
```## Usage
This example also shows usage of
[`sentry_rust_minidump`](https://github.com/timfish/sentry-rust-minidump) which
allows you to capture minidumps for native crashes from a separate crash
reporting process.```rust
use tauri_plugin_sentry::{minidump, 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 = minidump::init(&client);
// Everything after here runs in only the app processtauri::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-view
- Includes custom `transport` and `beforeBreadcrumb` hook that passes events and
breadcrumbs to the Rust SDK via the Tauri `invoke` API
- Tauri + `serde` + existing Sentry Rust types = Deserialisation mostly Just
Works™️## Custom Sentry Browser Configuration
By default the plugin injects a pre-minified version of `@sentry/browser`. If
you want to configure Sentry in the browser yourself, you can disable the
injection and pass the default config to `Sentry.init`.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
*/
});
```## Example App
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
```