LCOV - code coverage report
Current view: top level - proxy/src - logging.rs (source / functions) Coverage Total Hit
Test: 32f4a56327bc9da697706839ed4836b2a00a408f.info Lines: 96.2 % 26 25
Test Date: 2024-02-07 07:37:29 Functions: 100.0 % 4 4

            Line data    Source code
       1              : use tracing_opentelemetry::OpenTelemetryLayer;
       2              : use tracing_subscriber::{
       3              :     filter::{EnvFilter, LevelFilter},
       4              :     prelude::*,
       5              : };
       6              : 
       7              : /// Initialize logging and OpenTelemetry tracing and exporter.
       8              : ///
       9              : /// Logging can be configured using `RUST_LOG` environment variable.
      10              : ///
      11              : /// OpenTelemetry is configured with OTLP/HTTP exporter. It picks up
      12              : /// configuration from environment variables. For example, to change the
      13              : /// destination, set `OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318`.
      14              : /// See <https://opentelemetry.io/docs/reference/specification/sdk-environment-variables>
      15           24 : pub async fn init() -> anyhow::Result<LoggingGuard> {
      16           24 :     let env_filter = EnvFilter::builder()
      17           24 :         .with_default_directive(LevelFilter::INFO.into())
      18           24 :         .from_env_lossy();
      19           24 : 
      20           24 :     let fmt_layer = tracing_subscriber::fmt::layer()
      21           24 :         .with_ansi(false)
      22           24 :         .with_writer(std::io::stderr)
      23           24 :         .with_target(false);
      24              : 
      25           24 :     let otlp_layer = tracing_utils::init_tracing("proxy")
      26            0 :         .await
      27           24 :         .map(OpenTelemetryLayer::new);
      28           24 : 
      29           24 :     tracing_subscriber::registry()
      30           24 :         .with(env_filter)
      31           24 :         .with(otlp_layer)
      32           24 :         .with(fmt_layer)
      33           24 :         .try_init()?;
      34              : 
      35           24 :     Ok(LoggingGuard)
      36           24 : }
      37              : 
      38              : pub struct LoggingGuard;
      39              : 
      40              : impl Drop for LoggingGuard {
      41           24 :     fn drop(&mut self) {
      42           24 :         // Shutdown trace pipeline gracefully, so that it has a chance to send any
      43           24 :         // pending traces before we exit.
      44           24 :         tracing::info!("shutting down the tracing machinery");
      45           24 :         tracing_utils::shutdown_tracing();
      46           24 :     }
      47              : }
        

Generated by: LCOV version 2.1-beta