https://github.com/backtrace-labs/backtrace-rust
https://github.com/backtrace-labs/backtrace-rust
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/backtrace-labs/backtrace-rust
- Owner: backtrace-labs
- Created: 2022-03-16T18:30:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-24T19:39:05.000Z (over 2 years ago)
- Last Synced: 2025-10-11T05:09:00.481Z (3 months ago)
- Language: Rust
- Size: 21.5 KB
- Stars: 0
- Watchers: 8
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Backtrace error submission crate
# Installation
```
[dependencies]
backtraceio = "0.1"
```
# Usage
## Global error handler
Pass your custom token and upload url from your Backtrace account and a report
modification closure/function to the `backtraceio::register_error_handler`
function.
```
backtraceio::register_error_handler(
"https://UNIVERSE.sp.backtrace.io:6098",
"YOURTOKEN",
closure
);
```
### `Report` modification function
The error handler will pass the `Report` and `std::panic::PanicInfo` objects
back to the user, in case there are additional attributes/annotations to be
defined (described more in detail [here][1]). It should accept `&mut Report`,
`&PanicInfo`, making any changes desired to the report.
# Example
```rust
use backtraceio::Report;
fn main() {
backtraceio::register_error_handler(
"https://UNIVERSE.sp.backtrace.io:6098",
"YOUR_TOKEN",
|r: &mut Report, _| {
let cpus = num_cpus::get();
let cpus = cpus.to_string();
r.attributes.insert(String::from("cpu.cores"), cpus);
},
);
println!("Hello, world!");
panic!("{:?}", 69);
}
```
[1]: https://api.backtrace.io/#tag/submit-crash