Skip to content

Commit d2950fa

Browse files
committed
Auto merge of #2961 - Turbo87:backend-sentry, r=pietroalbini
Report errors and slow requests on the backend to Sentry This PR implements initial Sentry integration for our backend API via https://github.com/getsentry/sentry-rust. It will automatically report panics to Sentry, as well as internal server errors (unfortunately without stacktrace for now) and slow requests, similar to our current `println!()` logging. r? `@pietroalbini`
2 parents 9730c0b + 29bfde8 commit d2950fa

File tree

5 files changed

+301
-1
lines changed

5 files changed

+301
-1
lines changed

.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ export GH_CLIENT_SECRET=
5656
# export MAILGUN_SMTP_LOGIN=
5757
# export MAILGUN_SMTP_PASSWORD=
5858
# export MAILGUN_SMTP_SERVER=
59+
60+
# Credentials for connecting to the Sentry error reporting service.
61+
# export SENTRY_DSN_API=
62+
export SENTRY_ENV_API=local

Cargo.lock

Lines changed: 176 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ regex = "1.3.9"
7676
reqwest = { version = "0.10", features = ["blocking", "gzip", "json"] }
7777
scheduled-thread-pool = "0.2.0"
7878
semver = { version = "0.10", features = ["diesel", "serde"] }
79+
sentry = "0.20.1"
7980
serde = { version = "1.0.0", features = ["derive"] }
8081
serde_json = "1.0.0"
8182
sha2 = "0.9"

src/bin/server.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use cargo_registry::{boot, App, Env};
44
use std::{
5+
borrow::Cow,
56
fs::File,
67
sync::{mpsc::channel, Arc, Mutex},
78
thread,
@@ -12,6 +13,7 @@ use civet::Server as CivetServer;
1213
use conduit_hyper::Service;
1314
use futures_util::future::FutureExt;
1415
use reqwest::blocking::Client;
16+
use sentry::{ClientOptions, IntoDsn};
1517

1618
const CORE_THREADS: usize = 4;
1719

@@ -24,6 +26,21 @@ enum Server {
2426
use Server::*;
2527

2628
fn main() -> Result<(), Box<dyn std::error::Error>> {
29+
let _sentry = dotenv::var("SENTRY_DSN_API")
30+
.ok()
31+
.into_dsn()
32+
.expect("SENTRY_DSN_API is not a valid Sentry DSN value")
33+
.map(|dsn| {
34+
let mut opts = ClientOptions::from(dsn);
35+
opts.environment = Some(
36+
dotenv::var("SENTRY_ENV_API")
37+
.map(Cow::Owned)
38+
.expect("SENTRY_ENV_API must be set when using SENTRY_DSN_API"),
39+
);
40+
41+
sentry::init(opts)
42+
});
43+
2744
// Initialize logging
2845
env_logger::init();
2946

0 commit comments

Comments
 (0)