Move tracing init into own function
This commit is contained in:
parent
27e7ae2e0c
commit
6bee29e6bc
21
src/main.rs
21
src/main.rs
|
@ -603,10 +603,10 @@ fn render(
|
|||
.body(min))
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> Result<(), anyhow::Error> {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
fn init_tracing(
|
||||
service_name: &'static str,
|
||||
opentelemetry_url: Option<&Url>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
opentelemetry::global::set_text_map_propagator(TraceContextPropagator::new());
|
||||
|
||||
LogTracer::init()?;
|
||||
|
@ -622,12 +622,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
.with(format_layer)
|
||||
.with(ErrorLayer::default());
|
||||
|
||||
if let Some(url) = &CONFIG.opentelemetry_url {
|
||||
if let Some(url) = opentelemetry_url {
|
||||
let tracer =
|
||||
opentelemetry_otlp::new_pipeline()
|
||||
.tracing()
|
||||
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
|
||||
Resource::new(vec![KeyValue::new("service.name", "pict-rs-proxy")]),
|
||||
Resource::new(vec![KeyValue::new("service.name", service_name)]),
|
||||
))
|
||||
.with_exporter(
|
||||
opentelemetry_otlp::new_exporter()
|
||||
|
@ -645,6 +645,15 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> Result<(), anyhow::Error> {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
init_tracing("pict-rs-proxy", CONFIG.opentelemetry_url.as_ref())?;
|
||||
|
||||
HttpServer::new(move || {
|
||||
let client = Client::builder()
|
||||
.header("User-Agent", "pict-rs-frontend, v0.1.0")
|
||||
|
|
Loading…
Reference in a new issue