honeybadger/lib.rs
1//! An unofficial Honeybadger Rust client
2//!
3//! # Description
4//!
5//! [Honeybadger][1] is a service that receives, stores and alerts on
6//! application errors and outages. This library is a community-provided client for the [Honeybadger Exceptions API](https://docs.honeybadger.io/api/exceptions.html).
7//!
8//! Underneath, the client uses a [Tokio](https://tokio.rs/)-based version of
9//! [Hyper](https://hyper.rs/). Familiarity with Tokio-based systems is recommended.
10//!
11//! # Error library compatibility
12//!
13//! The library provides convenience conversion traits and methods to generate a Honeybadger payload for use in the [`Honeybadger::notify`](https://docs.rs/honeybadger/0.1.3/honeybadger/struct.Honeybadger.html#method.notify) API endpoint, based on popular error Rust libraries.
14//!
15//! - a [From](https://doc.rust-lang.org/std/convert/trait.From.html) conversion trait enables use of a `failure::Error`, if using the
16//! [failure](https://rust-lang-nursery.github.io/failure/) crate.
17//!
18//! - the
19//! [`notice::Error::new`](./notice/struct.Error.html#method.new) convenience method creates a `notice::Error` Honeybadger
20//! payload, if using the [error_chain](https://docs.rs/error-chain/0.12.0/error_chain/) crate.
21//!
22//! - alternatively, a [From](https://doc.rust-lang.org/std/convert/trait.From.html) trait allows use of a simple `Box<std::error::Error>`, if using errors from the Rust standard library.
23//!
24//! Backtraces are only supported in the ErrorChain and Failure crates.
25//!
26//! # Example
27//!
28//! Assuming the project is setup to use
29//! [ErrorChain](http://brson.github.io/2016/11/30/starting-with-error-chain), the following
30//! example will execute code in `do_work`, send a honeybadger exception if it fails, and
31//! subsequently end the program.
32//!
33//! ```rust
34//! # #[macro_use] extern crate error_chain;
35//! # extern crate honeybadger;
36//! # extern crate tokio;
37//! # error_chain! {
38//! # }
39//! use tokio::prelude::*;
40//! use tokio::prelude::future::result;
41//! use tokio::runtime::run;
42//!
43//! fn do_work() -> Result<()> {
44//!
45//! // write code ...
46//!
47//! Ok(())
48//! }
49//!
50//! # fn main() {
51//! # use honeybadger::{ConfigBuilder, Honeybadger};
52//! # let api_token = "ffffff";
53//! // let api_token = "...";
54//! let config = ConfigBuilder::new(api_token).build();
55//! let mut hb = Honeybadger::new(config).unwrap();
56//!
57//! let work = result(do_work())
58//! .or_else(move |e| hb.notify(honeybadger::notice::Error::new(&e), None))
59//! .map_err(|e| println!("error = {:?}", e));
60//!
61//! run(work);
62//! # }
63//! ```
64//![1]: https://www.honeybadger.io/
65//!
66//! Please check the examples folder for further alternatives.
67//!
68//
69// Increase the compiler's recursion limit for the `error_chain` crate.
70#![recursion_limit = "1024"]
71
72extern crate backtrace;
73#[macro_use]
74extern crate error_chain;
75extern crate failure;
76extern crate futures;
77extern crate hostname;
78extern crate http;
79extern crate hyper;
80extern crate hyper_tls;
81#[macro_use]
82extern crate log;
83extern crate os_type;
84//extern crate native_tls;
85#[macro_use]
86extern crate serde_derive;
87extern crate serde;
88extern crate serde_json;
89extern crate tokio;
90#[cfg(test)]
91extern crate yup_hyper_mock as hyper_mock;
92
93pub mod errors;
94mod honeybadger;
95pub mod notice;
96
97// export
98pub use honeybadger::{ConfigBuilder, Honeybadger};