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

fix(server): init sentry before the tokio runtime #12

Merged
merged 1 commit into from
Jan 20, 2024
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
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
Expand Up @@ -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
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
clap.workspace = true
color-eyre.workspace = true
sourmash.workspace = true
serde_json.workspace = true
axum.workspace = true
Expand Down
24 changes: 17 additions & 7 deletions crates/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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>;
Expand Down