Giter Club home page Giter Club logo

mightybadger-rocket's Introduction

Honeybadger Notifier for Rust

Honeybadger is an error-tracking service run by Honeybadger Industries LLC.

mightybadger-rs is an unofficial Honeybadger notifier for Rust, which hooks into panics and error responses, collects related information, and sends reports to the Honeybadger API server.

In addition to standalone configuration, it provides middlewares for Rocket, Gotham, and Actix Web.

Standalone

[dependencies]
mightybadger = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
extern crate mightybadger;

use std::fs::File;

fn main() {
    mightybadger::setup();

    match File::open("quux.quux") {
        Ok(_) => eprintln!("quux.quux exists."),
        Err(e) => mightybadger::notify(&e),
    };

    panic!("test panic");
}
HONEYBADGER_API_KEY=your_own_api_key cargo run

With Rocket

[dependencies]
mightybadger = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
mightybadger-rocket = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
extern crate mightybadger;
extern crate mightybadger_rocket;

...

fn main() {
    mightybadger::setup();
    rocket::ignite()
        ...
        .attach(mightybadger_rocket::HoneybadgerHook::new())
        .launch();
}

With Gotham

[dependencies]
mightybadger = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
mightybadger-gotham = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
extern crate mightybadger;
extern crate mightybadger_gotham;

...

fn router() -> Router {
    let (chain, pipelines) = single_pipeline(
        new_pipeline()
            .add(mightybadger_gotham::HoneybadgerMiddleware)
            .build(),
    );
    build_router(chain, pipelines, |route| { ... })
}

...

fn main() {
    mightybadger::setup();
    gotham::start(..., router())
}

With Actix Web

[dependencies]
mightybadger = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
mightybadger-actix-web = { git = "https://github.com/qnighy/mightybadger-rs.git", rev = "da98547" }
extern crate mightybadger;
extern crate mightybadger_actix_web;

...

fn main() {
    mightybadger::setup();

    server::new(|| {
        App::new()
            .middleware(mightybadger_actiX_web::HoneybadgerMiddleware::new())
            ..
    }).bind(..)
        .unwrap()
        .run();
}

Configuration

It automatically reads the following environment variables at mightybadger::setup():

  • HONEYBADGER_API_KEY
  • HONEYBADGER_ENV
  • HONEYBADGER_REPORT_DATA
  • HONEYBADGER_ROOT
  • HONEYBADGER_REVISION
  • HONEYBADGER_HOSTNAME

Moreover, you can programmatically configure the Honeybadger client as follows:

fn main() {
    mightybadger::setup();
    mightybadger::configure(|config| {
        if config.api_key.is_none() {
            config.api_key = Some("abcd1234".to_string());
        }
        config.env = Some("production".to_string());
        config.report_data = Some(true);
        config.root = Some("/home/ubuntu/app".to_string());
        config.revision = Some("0123456789abcdef0123456789abcdef01234567".to_string());
        config.hostname = Some("api.example.com".to_string());
        config.request.filter_keys = Some(vec![
            "password".to_string(),
            "HTTP_AUTHORIZATION".to_string(),
            "passcode".to_string(),
        ]);
    });
}

Development Status

Note: it's still in its early stage and the Rust API is subject to change. I strongly recommend you to insert rev = ".." attribute in the dependencies to prevent breakage.

  • Assemble notification payload
    • Notifier information
    • Error messages
    • Backtraces
    • Error classes
      • Custom error classes
    • Error chain
    • Server information from global configuration
    • Stats from /proc
  • Send the payload to the Honeybadger API server
  • Panic hook
  • Notify custom errors with failure
  • Pluggable RequestInfo injection
    • Built-in support for futures/tokio
  • Context injection
  • Framework supports
    • Rocket: RequestInfo injection
      • CGI Data
      • URL
      • Query Params
      • Rails-like component
      • Rails-like action
      • Session
    • Rocket: error response hook
    • Gotham: RequestInfo injection
      • CGI Data
      • URL
      • Query Params
      • Rails-like component
      • Rails-like action
      • Session
    • Gotham: error response hook
    • Actix Web: RequestInfo injection (error response only)
      • CGI Data
      • URL (except for hostname)
      • Query Params
      • Rails-like component
      • Rails-like action
      • Session
    • Actix Web: error response hook
    • Iron
    • Nickel
    • Rouille
  • Password filtering
  • Global configuration via environment variables
  • Global configuration via YAML
  • Global configuration via Rust functions
  • Travis
  • Docs
  • Rust API stabilization

License

MIT License

mightybadger-rocket's People

Contributors

qnighy avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.