#error #notifier #send #ability #dashboard #minimalist #io

airbrake

Airbrake Rust 是为 Rust 编程语言设计的 Airbrake(https://airbrake.io)通知库。该库提供了简约的 API,使得能够将 Rust 错误发送到 Airbrake 控制台。

2 个不稳定版本

使用旧的 Rust 2015

0.2.0 2017 年 5 月 13 日
0.1.0 2016 年 5 月 29 日

#1030 in 开发工具

MIT 协议

20KB
323

Airbrake Rust

Build Status

*/!\ 项目处于 alpha 阶段 /!*

简介

Airbrake Rust 是为 Rust 编程语言设计的 Airbrake 通知库。该库提供了简约的 API,使得能够将 Rust 错误发送到 Airbrake 控制台。

主要功能

  • 使用新的 Airbrake JSON API(v3)[链接]
  • 简单、一致且易于使用的库 API[链接]
  • 卓越的性能(查看我们的基准测试)[链接]
  • 异步错误报告[链接]
  • 通过 env_logger 支持日志记录[链接]
  • 支持代理[链接]
  • 支持环境[链接]
  • 支持过滤器(过滤掉不应发送的敏感或不必要的数据)[链接]
  • 能够根据任何条件忽略错误[链接]
  • SSL 支持(与 Airbrake 的所有通信默认加密)

安装

Cargo

将软件包添加到您的 Cargo.toml 文件中

[dependencies]
airbrake = "0.2"

示例

基本示例

这是您可以用来测试 Airbrake Rust 与您项目配合使用的最小示例

extern crate airbrake;

use std::num::ParseIntError;

fn double_number(number_str: &str) -> Result<i32, ParseIntError> {
   number_str.parse::<i32>().map(|n| 2 * n)
}

fn main() {
    let mut airbrake = airbrake::configure(|config| {
        config.project_id = "113743".to_owned();
        config.project_key = "81bbff95d52f8856c770bb39e827f3f6".to_owned();
    });

    match double_number("NOT A NUMBER") {
        Ok(n) => assert_eq!(n, 20),
        // Asynchronously sends the error to the dashboard.
        Err(err) => airbrake.notify(err),
    }

    // Joins worker threads.
    airbrake.close();
}

配置

project_key & project_id

必须 设置 project_idproject_key

要找到您的 project_idproject_key,请导航到您项目的 常规设置,并将右侧边栏中的值复制过来。

let mut airbrake = airbrake::configure(|config| {
    config.project_id = "113743".to_owned();
    config.project_key = "81bbff95d52f8856c770bb39e827f3f6".to_owned();
});

host

默认情况下,它设置为 https://airbrake.io。一个 host 是一个包含方案("http" 或 "https")、主机和端口的网络地址。您可以省略端口号(默认为 80)。

let mut airbrake = airbrake::configure(|config| {
    config.host = "https://127.0.0.1:8080".to_owned();
});

workers

处理通知发送的线程数。默认值为 1。

let mut airbrake = airbrake::configure(|config| {
    config.workers = 5;
});

proxy

如果您的服务器无法直接连接到Airbrake,您可以使用代理支持。默认情况下,Airbrake Rust使用直接连接。注意:尚未支持代理认证。

let mut airbrake = airbrake::configure(|config| {
    config.proxy = "127.0.0.1:8080".to_owned();
});

app_version

您可以将此版本传递给应用,以区分多个版本之间的错误。默认情况下未设置。

let mut airbrake = airbrake::configure(|config| {
    config.app_version = "1.0.0".to_owned();
});

API

airbrake

airbrake.notify

异步地将错误发送到Airbrake。代码error必须实现std::error::Error特质。返回值无。

let mut airbrake = airbrake::configure(|config| {
    config.project_id = "123".to_owned();
    config.project_key = "321".to_owned();
});

airbrake.notify(std::io::Error::last_os_error());

airbrake.notify_sync

同步地将错误发送到Airbrake。代码error必须实现std::error::Error特质。返回值rustc_serialize::json::Json。接受与Airbrake.notify相同的参数。

let mut airbrake = airbrake::configure(|config| {
    config.project_id = "123".to_owned();
    config.project_key = "321".to_owned();
});

airbrake.notify_sync(std::io::Error::last_os_error());

依赖项

~6.5MB
~148K SLoC