Skip to content

Report errors and slow requests on the backend to Sentry #2961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 26, 2020
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
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ export GH_CLIENT_SECRET=
# export MAILGUN_SMTP_LOGIN=
# export MAILGUN_SMTP_PASSWORD=
# export MAILGUN_SMTP_SERVER=

# Credentials for connecting to the Sentry error reporting service.
# export SENTRY_DSN_API=
export SENTRY_ENV_API=local
176 changes: 176 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ regex = "1.3.9"
reqwest = { version = "0.10", features = ["blocking", "gzip", "json"] }
scheduled-thread-pool = "0.2.0"
semver = { version = "0.10", features = ["diesel", "serde"] }
sentry = "0.20.1"
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
sha2 = "0.9"
Expand Down
17 changes: 17 additions & 0 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use cargo_registry::{boot, App, Env};
use std::{
borrow::Cow,
fs::File,
sync::{mpsc::channel, Arc, Mutex},
thread,
Expand All @@ -12,6 +13,7 @@ use civet::Server as CivetServer;
use conduit_hyper::Service;
use futures_util::future::FutureExt;
use reqwest::blocking::Client;
use sentry::{ClientOptions, IntoDsn};

const CORE_THREADS: usize = 4;

Expand All @@ -24,6 +26,21 @@ enum Server {
use Server::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let _sentry = dotenv::var("SENTRY_DSN_API")
.ok()
.into_dsn()
.expect("SENTRY_DSN_API is not a valid Sentry DSN value")
.map(|dsn| {
let mut opts = ClientOptions::from(dsn);
opts.environment = Some(
dotenv::var("SENTRY_ENV_API")
.map(Cow::Owned)
.expect("SENTRY_ENV_API must be set when using SENTRY_DSN_API"),
);

sentry::init(opts)
});

// Initialize logging
env_logger::init();

Expand Down
Loading