Skip to content

Commit

Permalink
Merge pull request #87 from Overmuse/SR/sentry
Browse files Browse the repository at this point in the history
feat: Add sentry integration
  • Loading branch information
SebRollen authored Dec 8, 2021
2 parents 6224d51 + c914641 commit 7045864
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 8 deletions.
207 changes: 207 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ refinery = { version = "0.6", features = ["tokio-postgres"] }
reqwest = "0.11.4"
risk-manager = {git = "ssh://git@github.com/Overmuse/risk-manager.git", tag = "v0.4.1" }
rust_decimal = { version = "1.17", features = ["tokio-pg"] }
sentry = "0.23.0"
sentry-tracing = "0.23.0"
serde = "1.0"
serde_json = "1.0"
serde_plain = "0.3"
Expand Down
20 changes: 13 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use anyhow::Result;
use order_manager::run;
use order_manager::Settings;
use tracing::subscriber::set_global_default;
use tracing_subscriber::EnvFilter;
use sentry::{ClientOptions, IntoDsn};
use tracing_subscriber::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
dotenv::dotenv().ok();
let subscriber = tracing_subscriber::fmt()
.json()
.with_env_filter(EnvFilter::from_default_env())
.finish();
set_global_default(subscriber)?;
let settings = Settings::new()?;
let _guard = sentry::init(ClientOptions {
dsn: settings.sentry.dsn.clone().into_dsn().unwrap(),
environment: Some(settings.sentry.environment.clone().into()),
release: sentry::release_name!(),
..ClientOptions::default()
});

tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().json())
.with(sentry_tracing::layer())
.init();
run(settings).await
}
7 changes: 7 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub struct Database {
pub name: String,
}

#[derive(Debug, Deserialize)]
pub struct SentrySettings {
pub environment: String,
pub dsn: String,
}

#[derive(Debug, Deserialize)]
pub struct DatastoreSettings {
pub base_url: String,
Expand All @@ -29,6 +35,7 @@ pub struct Settings {
pub database: Database,
pub kafka: KafkaSettings,
pub datastore: DatastoreSettings,
pub sentry: SentrySettings,
pub webserver: WebServerSettings,
}

Expand Down
5 changes: 4 additions & 1 deletion tests/integration/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ pub async fn setup() -> (
std::env::set_var("KAFKA__SECURITY_PROTOCOL", "PLAINTEXT");
std::env::set_var("KAFKA__ACKS", "0");
std::env::set_var("KAFKA__RETRIES", "0");
std::env::set_var("WEBSERVER__PORT", "0");
std::env::set_var("KAFKA__RETRIES", "0");
std::env::set_var("SENTRY__DSN", "");
std::env::set_var("SENTRY__ENVIRONMENT", "test");
std::env::set_var("WEBSERVER__PORT", "8127");
let settings = Settings::new();
tracing::debug!("{:?}", settings);
let res = run(settings.unwrap()).await;
Expand Down

0 comments on commit 7045864

Please sign in to comment.