refactor(app): wire all 5 binary apps to lib/obs for tracing init
zhenyi committed
Modified app/apihost/src/main.rs app/apihost/src/main.rs +4 −13 View app/apihost/src/main.rs
@@ -5,21 +5,12 @@
55use config::ConfigLoader;
66use tokio::net::TcpListener;
77use tracing::info;
8use tracing_subscriber::EnvFilter;
98use webapi::{AppServices, router};
109
1110const DEFAULT_BIND: &str = "0.0.0.0";
1211const DEFAULT_PORT: u16 = 8080;
12const DEFAULT_LOG_FILTER: &str = "info,webapi=debug,apihost=debug";
1313
14fn init_tracing() {
15 let filter = EnvFilter::try_from_default_env()
16 .unwrap_or_else(|_| EnvFilter::new("info,webapi=debug,apihost=debug"));
17 tracing_subscriber::fmt()
18 .with_env_filter(filter)
19 .with_target(true)
20 .init();
21}
22
2314#[tokio::main]
2415async fn main() {
2516 if let Err(e) = run().await {
@@ -29,8 +20,6 @@
2920}
3021
3122async fn run() -> Result<(), Box<dyn std::error::Error>> {
32 init_tracing();
33
3423 let mut loader = ConfigLoader::new();
3524 let mut bind = IpAddr::from_str(DEFAULT_BIND)?;
3625 let mut port = DEFAULT_PORT;
@@ -62,7 +51,9 @@
6251 }
6352 }
6453
65 let app = loader.load()?;
54 let mut app = loader.load()?;
55 app.obs = app.obs.with_app_defaults("apihost", DEFAULT_LOG_FILTER);
56 let _obs = obs::init(&app.obs)?;
6657 let addr = SocketAddr::new(bind, port);
6758
6859 let services = AppServices::build(&app).await?;
Modified app/apihost/Cargo.toml app/apihost/Cargo.toml +2 −2 View app/apihost/Cargo.toml
@@ -11,7 +11,7 @@
1111[dependencies]
1212webapi.workspace = true
1313config.workspace = true
14obs.workspace = true
1415axum.workspace = true
1516tokio.workspace = true
16tracing.workspace = true
17tracing-subscriber.workspace = true
No newline at end of file
17tracing.workspace = true
No newline at end of file
Modified app/githook/src/main.rs app/githook/src/main.rs +14 −14 View app/githook/src/main.rs
@@ -3,18 +3,11 @@
33use cache::{CacheBuilder, RedisCache};
44use config::ConfigLoader;
55use db::conn::Db;
6use gitsync::{NoopWebhookTx, SyncWorker};
6use gitsync::{SyncWorker, WebhookTx};
77use tracing::{info, warn};
8use webhook::WebhookDispatcher;
89
9fn init_tracing() {
10 let filter = tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
11 tracing_subscriber::EnvFilter::new("info,githook=debug,gitsync=debug")
12 });
13 tracing_subscriber::fmt()
14 .with_env_filter(filter)
15 .with_target(true)
16 .init();
17}
10const DEFAULT_LOG_FILTER: &str = "info,githook=debug,gitsync=debug";
1811
1912#[tokio::main]
2013async fn main() {
@@ -25,8 +18,6 @@
2518}
2619
2720async fn run() -> Result<(), Box<dyn std::error::Error>> {
28 init_tracing();
29
3021 let mut loader = ConfigLoader::new();
3122 let mut args = std::env::args().skip(1);
3223 while let Some(arg) = args.next() {
@@ -43,7 +34,9 @@
4334 }
4435 }
4536
46 let app = loader.load()?;
37 let mut app = loader.load()?;
38 app.obs = app.obs.with_app_defaults("githook", DEFAULT_LOG_FILTER);
39 let _obs = obs::init(&app.obs)?;
4740
4841 let db = Db::from_config(&app.db).await?;
4942 let cache = CacheBuilder::from_config(app.app_cache.clone())
@@ -61,6 +54,12 @@
6154 .map(Arc::new);
6255 let storage = storage::repo::from_config(&app.storage)?;
6356
57 // --- webhook dispatcher: async + retry, wired in as the WebhookTx ---
58 let dispatcher = WebhookDispatcher::from_config(&app.webhook, db.clone())
59 .map_err(|e| format!("webhook dispatcher: {e}"))?;
60 let webhook_tx: Arc<dyn WebhookTx> = Arc::new(dispatcher.clone());
61
62 // --- gitsync: consume post-receive events and sync repo state ---
6463 let worker = SyncWorker::new(
6564 db,
6665 Arc::new(app.repo.clone()),
@@ -68,13 +67,14 @@
6867 Arc::new(cache),
6968 storage,
7069 queue,
71 Arc::new(NoopWebhookTx),
70 webhook_tx,
7271 app.git_sync.clone(),
7372 );
7473 let running = worker.run().await?;
7574
7675 wait_for_shutdown().await;
7776 running.shutdown().await?;
77 dispatcher.drain().await;
7878 info!("githook shut down cleanly");
7979 Ok(())
8080}
Modified app/githook/Cargo.toml app/githook/Cargo.toml +2 −1 View app/githook/Cargo.toml
@@ -13,8 +13,9 @@
1313config.workspace = true
1414db.workspace = true
1515gitsync.workspace = true
16obs.workspace = true
1617queue.workspace = true
1718storage.workspace = true
1819tokio.workspace = true
1920tracing.workspace = true
20tracing-subscriber.workspace = true
No newline at end of file
21webhook.workspace = true
No newline at end of file
Modified app/gitpro/src/main.rs app/gitpro/src/main.rs +4 −12 View app/gitpro/src/main.rs
@@ -8,15 +8,7 @@
88use tokio::net::TcpListener;
99use tracing::{info, warn};
1010
11fn init_tracing() {
12 let filter = tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
13 tracing_subscriber::EnvFilter::new("info,gitpro=debug,gitsmart=debug,gitssh=debug")
14 });
15 tracing_subscriber::fmt()
16 .with_env_filter(filter)
17 .with_target(true)
18 .init();
19}
11const DEFAULT_LOG_FILTER: &str = "info,gitpro=debug,gitsmart=debug,gitssh=debug";
2012
2113#[tokio::main]
2214async fn main() {
@@ -27,8 +19,6 @@
2719}
2820
2921async fn run() -> Result<(), Box<dyn std::error::Error>> {
30 init_tracing();
31
3222 let mut loader = ConfigLoader::new();
3323 let mut args = std::env::args().skip(1);
3424 while let Some(arg) = args.next() {
@@ -45,7 +35,9 @@
4535 }
4636 }
4737
48 let app = loader.load()?;
38 let mut app = loader.load()?;
39 app.obs = app.obs.with_app_defaults("gitpro", DEFAULT_LOG_FILTER);
40 let _obs = obs::init(&app.obs)?;
4941
5042 let db = Db::from_config(&app.db).await?;
5143 let kv = if app.cache.urls.is_empty() {
Modified app/gitpro/Cargo.toml app/gitpro/Cargo.toml +2 −2 View app/gitpro/Cargo.toml
@@ -17,8 +17,8 @@
1717gitsmart.workspace = true
1818gitssh.workspace = true
1919jwt.workspace = true
20obs.workspace = true
2021queue.workspace = true
2122storage.workspace = true
2223tokio.workspace = true
23tracing.workspace = true
24tracing-subscriber.workspace = true
No newline at end of file
24tracing.workspace = true
No newline at end of file
Modified app/livechat/src/main.rs app/livechat/src/main.rs +4 −14 View app/livechat/src/main.rs
@@ -19,10 +19,10 @@
1919use tokio::net::TcpListener;
2020use tokio::sync::RwLock;
2121use tracing::info;
22use tracing_subscriber::EnvFilter;
2322
2423const DEFAULT_BIND: &str = "0.0.0.0";
2524const DEFAULT_PORT: u16 = 8080;
25const DEFAULT_LOG_FILTER: &str = "info,chatlayer=debug,glayer=debug,live=debug,livechat=debug";
2626
2727#[derive(Serialize)]
2828struct HealthStatus {
@@ -44,16 +44,6 @@
4444 })
4545}
4646
47fn init_tracing() {
48 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
49 EnvFilter::new("info,chatlayer=debug,glayer=debug,live=debug,livechat=debug")
50 });
51 tracing_subscriber::fmt()
52 .with_env_filter(filter)
53 .with_target(true)
54 .init();
55}
56
5747#[tokio::main]
5848async fn main() {
5949 if let Err(e) = run().await {
@@ -63,8 +53,6 @@
6353}
6454
6555async fn run() -> Result<(), Box<dyn std::error::Error>> {
66 init_tracing();
67
6856 let mut loader = ConfigLoader::new();
6957 let mut bind = IpAddr::from_str(DEFAULT_BIND)?;
7058 let mut port = DEFAULT_PORT;
@@ -96,7 +84,9 @@
9684 }
9785 }
9886
99 let app = loader.load()?;
87 let mut app = loader.load()?;
88 app.obs = app.obs.with_app_defaults("livechat", DEFAULT_LOG_FILTER);
89 let _obs = obs::init(&app.obs)?;
10090 let addr = SocketAddr::new(bind, port);
10191
10292 let db = Arc::new(Db::from_config(&app.db).await?);
Modified app/livechat/Cargo.toml app/livechat/Cargo.toml +1 −1 View app/livechat/Cargo.toml
@@ -24,4 +24,4 @@
2424tokio.workspace = true
2525serde.workspace = true
2626tracing.workspace = true
27tracing-subscriber.workspace = true
No newline at end of file
27obs.workspace = true
No newline at end of file
Modified app/mails/src/main.rs app/mails/src/main.rs +4 −12 View app/mails/src/main.rs
@@ -3,16 +3,8 @@
33use config::ConfigLoader;
44use email::{WorkerOptions, run_until_shutdown};
55use tracing::info;
6use tracing_subscriber::EnvFilter;
76
8fn init_tracing() {
9 let filter = EnvFilter::try_from_default_env()
10 .unwrap_or_else(|_| EnvFilter::new("info,email=debug,mails=debug"));
11 tracing_subscriber::fmt()
12 .with_env_filter(filter)
13 .with_target(true)
14 .init();
15}
7const DEFAULT_LOG_FILTER: &str = "info,email=debug,mails=debug";
168
179#[tokio::main]
1810async fn main() {
@@ -23,8 +15,6 @@
2315}
2416
2517async fn run() -> Result<(), Box<dyn std::error::Error>> {
26 init_tracing();
27
2818 let mut loader = ConfigLoader::new();
2919 let mut args = std::env::args().skip(1);
3020 while let Some(arg) = args.next() {
@@ -41,7 +31,9 @@
4131 }
4232 }
4333
44 let app = loader.load()?;
34 let mut app = loader.load()?;
35 app.obs = app.obs.with_app_defaults("mails", DEFAULT_LOG_FILTER);
36 let _obs = obs::init(&app.obs)?;
4537 info!(
4638 enabled = %app.email.enabled,
4739 smtp = %format!("{}:{}", app.email.smtp_host, app.email.smtp_port),
Modified app/mails/Cargo.toml app/mails/Cargo.toml +2 −2 View app/mails/Cargo.toml
@@ -11,6 +11,6 @@
1111[dependencies]
1212config.workspace = true
1313email.workspace = true
14obs.workspace = true
1415tokio.workspace = true
15tracing.workspace = true
16tracing-subscriber.workspace = true
No newline at end of file
16tracing.workspace = true
No newline at end of file