Skip to content

Commit d79a877

Browse files
author
David Gomes
committed
feat: wait for loki connection
1 parent 095397f commit d79a877

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

server/src/tracing_setup.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,23 @@ pub async fn setup_loki() {
2929
.with(fmt::layer().with_writer(io::stdout));
3030

3131
let http = Client::new();
32-
let loki_base_url = env::var("LOKI_BASE_URL").unwrap_or("http://127.0.0.1:3100".into());
32+
let mut is_url_provided = true;
33+
let loki_base_url = env::var("LOKI_BASE_URL").unwrap_or_else(|_| {
34+
is_url_provided = false;
35+
"http://127.0.0.1:3100".into()
36+
});
3337

34-
match http.get(loki_base_url.parse().unwrap()).await {
35-
Ok(_) => {
36-
let (layer, task) = build_loki_layer(&loki_base_url);
38+
if !is_url_provided && http.get(loki_base_url.parse().unwrap()).await.is_err() {
39+
registry.init();
3740

38-
registry.with(layer).init();
39-
tokio::spawn(task);
41+
tracing::warn!("Couldn't connect to Loki. Continuing without it.");
42+
return;
43+
}
4044

41-
tracing::info!("Loki initialized");
42-
}
43-
Err(_) => {
44-
registry.init();
45+
let (layer, task) = build_loki_layer(&loki_base_url);
4546

46-
tracing::warn!("Couldn't connect to Loki. Continuing without it.");
47-
}
48-
};
47+
registry.with(layer).init();
48+
tokio::spawn(task);
49+
50+
tracing::info!("Loki initialized");
4951
}

0 commit comments

Comments
 (0)