Skip to content

Commit 3066b94

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

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

server/src/tracing_setup.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,25 @@ 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());
33-
34-
match http.get(loki_base_url.parse().unwrap()).await {
35-
Ok(_) => {
36-
let (layer, task) = build_loki_layer(&loki_base_url);
37-
38-
registry.with(layer).init();
39-
tokio::spawn(task);
40-
41-
tracing::info!("Loki initialized");
42-
}
43-
Err(_) => {
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+
});
37+
38+
if !is_url_provided {
39+
if http.get(loki_base_url.parse().unwrap()).await.is_err() {
4440
registry.init();
4541

4642
tracing::warn!("Couldn't connect to Loki. Continuing without it.");
43+
return;
4744
}
48-
};
45+
}
46+
47+
let (layer, task) = build_loki_layer(&loki_base_url);
48+
49+
registry.with(layer).init();
50+
tokio::spawn(task);
51+
52+
tracing::info!("Loki initialized");
4953
}

0 commit comments

Comments
 (0)