//! Tracing init for the Rust workers.
//!
//! Both bin targets (`worker`, `hrrr_point_worker`) call `init(svc)` at
//! startup to install a JSON-to-stdout `tracing` subscriber so kubectl
//! logs keep working.
//!
//! OTLP span export was removed in 2026-04 — the opentelemetry stack
//! pulled ~80 transitive crates and added ~3-5 min to cold builds on
//! the forgejo runner, and the cluster's trace consumption was
//! negligible compared to structured logs + /metrics. Re-add via
//! `tracing-opentelemetry` only if Tempo becomes load-bearing.

use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

/// Opaque handle the caller holds until shutdown. No-op today; kept
/// so re-adding OTLP later doesn't require churn at every call site.
pub struct TelemetryGuard;

impl TelemetryGuard {
    /// Flush/drop hook. Currently a no-op; the fmt layer flushes each
    /// line as it's written.
    pub fn shutdown(self) {}
}

/// Initialize tracing for a binary. `service_name` is accepted for API
/// compatibility with the previous OTLP-capable init and is currently
/// unused in the fmt-only path.
pub fn init(_service_name: &'static str) -> TelemetryGuard {
    let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
    let fmt_layer = tracing_subscriber::fmt::layer().json();

    tracing_subscriber::registry()
        .with(env_filter)
        .with(fmt_layer)
        .init();

    TelemetryGuard
}
