Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
fix(server): init sentry before the tokio runtime (#12)
Browse files Browse the repository at this point in the history
sentry docs recommend starting it before the tokio runtime
luizirber authored Jan 20, 2024
1 parent 26bebf0 commit b720205
Showing 4 changed files with 48 additions and 24 deletions.
45 changes: 29 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -29,5 +29,5 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] }

[profile.release]
debug = 1
#debug = 2
#lto = true # Enable link-time optimization
1 change: 1 addition & 0 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ license = "AGPL"

[dependencies]
clap.workspace = true
color-eyre.workspace = true
sourmash.workspace = true
serde_json.workspace = true
axum.workspace = true
24 changes: 17 additions & 7 deletions crates/server/src/main.rs
Original file line number Diff line number Diff line change
@@ -11,11 +11,13 @@ use axum::{
};
use sentry::integrations::tower::{NewSentryLayer, SentryHttpLayer};
use sentry::integrations::tracing as sentry_tracing;
use tokio::runtime::Runtime;
use tower::{BoxError, ServiceBuilder};
use tower_http::{services::ServeDir, trace::TraceLayer};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

use clap::Parser;
use color_eyre::eyre::Result;
use sourmash::index::revindex::RevIndex;
use sourmash::signature::{Signature, SigsTrait};
use sourmash::sketch::minhash::{max_hash_for_scaled, KmerMinHash};
@@ -54,8 +56,7 @@ struct Cli {
threshold_bp: usize,
}

#[tokio::main]
async fn main() {
fn main() -> Result<()> {
let _guard = sentry::init((
std::env::var("SENTRY_DSN").expect("$SENTRY_DSN must be set"),
sentry::ClientOptions {
@@ -117,13 +118,22 @@ async fn main() {
.into_inner(),
);

// Run our app with hyper
// Create the runtime
let rt = Runtime::new()?;

let addr = SocketAddr::from(([127, 0, 0, 1], opts.port));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();

// Spawn the root task
rt.block_on(async {
// Run our app with hyper
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
});

Ok(())
}

type SharedState = Arc<State>;

0 comments on commit b720205

Please sign in to comment.