Skip to content

Commit

Permalink
feat: Sentry integration for autoendpoint (#196)
Browse files Browse the repository at this point in the history
* Update sentry to 0.19

* Override status_code() in ApiError's ResponseError impl

* Use the default Sentry transport and work around a Sentry issue

Working around this issue by using the `debug-logs` feature:
getsentry/sentry-rust#237

* Add custom Sentry middleware

Closes #155
  • Loading branch information
AzureMarker committed Jul 27, 2020
1 parent 068f54d commit 674d7d2
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 64 deletions.
146 changes: 96 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ regex = "1.3"
reqwest = "0.10.6"
rusoto_core = "0.44.0"
rusoto_dynamodb = "0.44.0"
sentry = { version = "0.18", features = ["with_curl_transport"] }
# Using debug-logs avoids https://github.com/getsentry/sentry-rust/issues/237
sentry = { version = "0.19", features = ["debug-logs"] }
serde = { version = "1.0", features = ["derive"] }
serde_dynamodb = "0.5.1"
serde_json = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions autoendpoint/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ impl From<ApiError> for HttpResponse {
}

impl ResponseError for ApiError {
fn status_code(&self) -> StatusCode {
self.kind.status()
}

fn error_response(&self) -> HttpResponse {
HttpResponse::build(self.kind.status()).json(self)
}
Expand Down
18 changes: 5 additions & 13 deletions autoendpoint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ mod extractors;
mod headers;
mod logging;
mod metrics;
mod middleware;
mod routers;
mod routes;
mod server;
mod settings;
mod tags;

use docopt::Docopt;
use sentry::internals::ClientInitGuard;
use sentry::ClientInitGuard;
use serde::Deserialize;
use std::error::Error;

Expand Down Expand Up @@ -59,19 +60,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

fn configure_sentry() -> ClientInitGuard {
let curl_transport_factory = |options: &sentry::ClientOptions| {
Box::new(sentry::transports::CurlHttpTransport::new(&options))
as Box<dyn sentry::internals::Transport>
};
let sentry = sentry::init(sentry::ClientOptions {
transport: Box::new(curl_transport_factory),
let options = sentry::ClientOptions {
release: sentry::release_name!(),
..sentry::ClientOptions::default()
});

if sentry.is_enabled() {
sentry::integrations::panic::register_panic_handler();
}
};

sentry
sentry::init(options)
}
3 changes: 3 additions & 0 deletions autoendpoint/src/middleware/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Actix middleware

pub mod sentry;
Loading

0 comments on commit 674d7d2

Please sign in to comment.