signal-kit 0.3.0

Helpers for initializing OpenTelemetry-based observability (tracing, metrics, logs) in async Rust services.
Documentation
use opentelemetry_sdk::logs::SdkLoggerProvider;

/// Initialize the logging provider for the given service.
///
/// # Arguments
///
/// * `resource` - The resource shared by every signal of this process.
/// * `otel_runtime` - The runtime driving the batch log processor.
#[cfg_attr(
    not(all(
        feature = "logs-otlp",
        any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json")
    )),
    allow(unused_mut, unused_variables)
)]
pub(crate) fn init_logging_provider(
    resource: &opentelemetry_sdk::Resource,
    otel_runtime: &crate::otel_runtime::SignalKitOtelRuntime,
) -> SdkLoggerProvider {
    let mut builder = SdkLoggerProvider::builder().with_resource(resource.clone());

    // Check if OTLP endpoint is configured for logs
    #[cfg(all(
        feature = "logs-otlp",
        any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json")
    ))]
    if crate::get_otlp_endpoint("logs").is_some() {
        let exporter = crate::transport::log_exporter::build(crate::resolve_otlp_transport("logs"));
        let batch_processor =
            opentelemetry_sdk::logs::log_processor_with_async_runtime::BatchLogProcessor::builder(
                exporter,
                otel_runtime.clone(),
            )
            .build();
        builder = builder.with_log_processor(batch_processor);
    }

    builder.build()
}