some observability

This commit is contained in:
Ondrej Vlach 2023-11-28 18:48:58 +01:00
parent 8366a1d82e
commit 5115265592
3 changed files with 14 additions and 5 deletions

View File

@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};
use async_trait::async_trait;
use async_mutex::Mutex;
use headless_chrome::{Browser, LaunchOptions};
use tracing::{error, info, debug, trace, warn, trace_span};
use tracing::{error, info, debug, trace, warn, trace_span, info_span};
use rocket::{fairing::{Fairing, self}, Rocket, Build, Request, request::{FromRequest, Outcome}, futures::pin_mut, http::Status};
use tokio::time::sleep;
@ -107,11 +107,14 @@ impl ChromiumCoordinator {
}
pub async fn get_browser(&self) -> std::result::Result<BrowserHolder, ()> {
let span = info_span!("get_browser");
let _enter = span.enter();
loop {
info!("trying to get a browser instance");
match self.try_get_browser().await {
Ok(browser) => return Ok(browser),
Err(_) => {
trace!("all instances of browser are dead... waiting for ");
warn!("all instances of browser are dead... waiting for new instance");
// all instances may be dead ... we must wait for new instance
}
}

View File

@ -1,7 +1,13 @@
use nanobyte_opentelemetry::{default_filter_layer, LogLevel};
use ovlach_pdf::rocket_builder;
use tracing::Level;
#[rocket::main]
async fn main() {
let _opentelemetry = nanobyte_opentelemetry::init_telemetry(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
let _opentelemetry = nanobyte_opentelemetry::init_telemetry(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
Some(default_filter_layer(LogLevel::Normal))
);
let _ = rocket_builder().launch().await;
}

View File

@ -42,7 +42,7 @@ fn generate_pdf(browser: Browser) {
}
#[get("/cv/<username>/pdf")]
pub async fn render_pdf_cv(username: &str, browser: BrowserHolder, tracing: TracingSpan) -> NamedFile {
pub async fn render_pdf_cv(username: &str, browser: BrowserHolder, tracing: TracingSpan) -> Option<NamedFile> {
let entered_span = tracing.0.enter();
let span = info_span!("render_pdf", username = username);
info!("generate PDF");
@ -51,5 +51,5 @@ pub async fn render_pdf_cv(username: &str, browser: BrowserHolder, tracing: Trac
});
info!("done generating");
drop(entered_span);
NamedFile::open("/tmp/foo.pdf").await.expect("failed to open foo.pdf")
Some(NamedFile::open("/tmp/foo.pdf").await.expect("failed to open foo.pdf"))
}