Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

feat: add sentry panic reporting #1089

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions autopush_rs/Cargo.lock

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

1 change: 1 addition & 0 deletions autopush_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ libc = "0.2"
# log: Use this for release builds (leave in for commits)
log = { version = "0.3", features = ["max_level_trace", "release_max_level_warn"] }
openssl = "0.9"
sentry = "0.2.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
1 change: 1 addition & 0 deletions autopush_rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern crate httparse;
extern crate hyper;
extern crate libc;
extern crate openssl;
extern crate sentry;
extern crate serde;
#[macro_use]
extern crate serde_derive;
Expand Down
22 changes: 22 additions & 0 deletions autopush_rs/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ use std::ffi::CStr;
use std::io;
use std::net::{IpAddr, ToSocketAddrs};
use std::panic;
use std::panic::PanicInfo;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::thread;
use std::time::{Instant, Duration};

use cadence::StatsdClient;
use futures;
use futures::sync::oneshot;
use futures::task;
use futures::{Stream, Future, Sink, Async, Poll, AsyncSink, StartSend};
use libc::c_char;
use openssl::ssl::SslAcceptor;
use sentry;
use serde_json;
use time;
use tokio_core::net::TcpListener;
Expand Down Expand Up @@ -297,6 +300,25 @@ impl Server {
}

fn new(opts: &Arc<ServerOptions>, tx: queue::Sender) -> Result<(Rc<Server>, Core)> {
// Setup Sentry logging if a SENTRY_DSN exists
let sentry_dsn_option = option_env!("SENTRY_DSN");
if let Some(sentry_dsn) = sentry_dsn_option {
// Spin up a new thread with a new reactor core for the sentry handler
thread::spawn(move || {
let creds = sentry_dsn
.parse::<sentry::SentryCredential>()
.expect("Invalid Sentry DSN specified");
let mut core = Core::new().expect("Unable to create core");
let sentry = sentry::Sentry::from_settings(core.handle(), Default::default(), creds);
// Get the prior panic hook
let hook = panic::take_hook();
sentry.register_panic_handler(Some(move |info: &PanicInfo| -> () {
hook(info);
}));
core.run(futures::empty::<(), ()>()).expect("Error starting sentry thread");
});
}

let core = Core::new()?;
let srv = Rc::new(Server {
opts: opts.clone(),
Expand Down