1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//! Airbrake Rust is an [Airbrake][airbrake.io] notifier library for the Rust
//! Programming language. The library provides minimalist API that enables the
//! ability to send Rust errors to the Airbrake dashboard.
//!
//! Installation
//! ------------
//!
//! Add the crate to your Cargo.toml:
//!
//! ```toml
//! [dependencies]
//! airbrake = "0.1"
//! ```
//!
//! Examples
//! --------
//!
//! ### Basic example
//!
//! This is the minimal example that you can use to test Airbrake Rust with your
//! project:
//!
//! ```
//! 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();
//! }
//! ```
//!
//! Configuration
//! -------------
//!
//! ### project_key & project_id
//!
//! You **must** set both `project_id` & `project_key`.
//!
//! To find your `project_id` and `project_key` navigate to your project's _General
//! Settings_ and copy the values from the right sidebar.
//!
//! ![][project-idkey]
//!
//! ```
//! let mut airbrake = airbrake::configure(|config| {
//! config.project_id = "113743".to_owned();
//! config.project_key = "81bbff95d52f8856c770bb39e827f3f6".to_owned();
//! });
//! ```
//!
//! ### host
//!
//! By default, it is set to `https://airbrake.io`. A `host` is a web address
//! containing a scheme ("http" or "https"), a host and a port. You can omit the
//! port (80 will be assumed).
//!
//! ```
//! let mut airbrake = airbrake::configure(|config| {
//! config.host = "http://localhost:8080".to_owned();
//! });
//! ```
//!
//! ### workers
//!
//! The number of threads that handle notice sending. The default value is 1.
//!
//! ```
//! let mut airbrake = airbrake::configure(|config| {
//! config.workers = 5;
//! });
//! ```
//!
//! ### proxy
//!
//! If your server is not able to directly reach Airbrake, you can use proxy
//! support. By default, Airbrake Rust uses direct connection. Note: proxy
//! authentication is not supported yet.
//!
//! ```
//! let mut airbrake = airbrake::configure(|config| {
//! config.proxy = "127.0.0.1:8080".to_owned();
//! });
//! ```
//!
//! ### app_version
//!
//! The version of your application that you can pass to differentiate errors
//! between multiple versions. It's not set by default.
//!
//! ```
//! let mut airbrake = airbrake::configure(|config| {
//! config.app_version = "1.0.0".to_owned();
//! });
//! ```
//!
//! API
//! ---
//!
//! ## airbrake
//!
//! #### airbrake.notify
//!
//! Sends an error to Airbrake *asynchronously*. `error` must implement the
//! [`std::error::Error`][stderror] trait. Returns `()`.
//!
//! ```
//! 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());
//! ```
//!
//! As the second parameter, accepts a hash with additional data. That data will be
//! displayed in the _Params_ tab in your project's dashboard.
//!
//! #### airbrake.notify_sync
//!
//! Sends an error to Airbrake *synchronously*. `error` must implement the
//! [`std::error::Error`][stderror] trait. Returns
//! [`rustc_serialize::json::Json`][json-object]. Accepts the same
//! parameters as [`Airbrake.notify`](#airbrakenotify).
//!
//! ```
//! 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());
//! ```
//!
//! [airbrake.io]: https://airbrake.io
//! [notice-v3]: https://airbrake.io/docs/#create-notice-v3
//! [env_logger]: https://crates.io/crates/env_logger
//! [project-idkey]: https://s3.amazonaws.com/airbrake-github-assets/airbrake-ruby/project-id-key.png
//! [stderror]: https://doc.rust-lang.org/std/error
//! [json-object]: https://doc.rust-lang.org/rustc-serialize/rustc_serialize/json/enum.Json.html
extern crate hyper;
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate log;
use Notifier;
use Config;
/// Configures an Airbrake notifier.
///
/// # Examples
///
/// ```
/// let mut airbrake = airbrake::configure(|config| {
/// config.project_id = "113743".to_owned();
/// config.project_key = "81bbff95d52f8856c770bb39e827f3f6".to_owned();
/// });