openapp_sdk_core/telemetry.rs
1//! Tracing / telemetry configuration.
2//!
3//! The SDK emits structured [`tracing`] events for every request. OpenTelemetry export
4//! is available via the (optional) `otel` Cargo feature — kept behind a feature flag so
5//! default builds stay lean and language SDKs can opt in as needed.
6
7use tracing_subscriber::EnvFilter;
8
9/// Initialize a minimal `tracing` subscriber with `RUST_LOG` / `OPENAPP_SDK_LOG`
10/// filter support. Safe to call multiple times (no-op after the first call).
11///
12/// Language SDKs are expected to call this at most once; for `PyO3` bindings this is
13/// invoked from the bridge's `Client.connect` implementation.
14pub fn init_fallback() {
15 let filter = EnvFilter::try_from_env("OPENAPP_SDK_LOG")
16 .or_else(|_| EnvFilter::try_from_default_env())
17 .unwrap_or_else(|_| EnvFilter::new("openapp_sdk_core=info,warn"));
18
19 let _ = tracing_subscriber::fmt()
20 .with_env_filter(filter)
21 .with_target(true)
22 .try_init();
23}