LCOV - differential code coverage report
Current view: top level - proxy/src - logging.rs (source / functions) Coverage Total Hit UBC CBC
Current: f6946e90941b557c917ac98cd5a7e9506d180f3e.info Lines: 96.2 % 26 25 1 25
Current Date: 2023-10-19 02:04:12 Functions: 100.0 % 4 4 4
Baseline: c8637f37369098875162f194f92736355783b050.info
Baseline Date: 2023-10-18 20:25:20

           TLA  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 CBC          17 : pub async fn init() -> anyhow::Result<LoggingGuard> {
      16              17 :     let env_filter = EnvFilter::builder()
      17              17 :         .with_default_directive(LevelFilter::INFO.into())
      18              17 :         .from_env_lossy();
      19              17 : 
      20              17 :     let fmt_layer = tracing_subscriber::fmt::layer()
      21              17 :         .with_ansi(false)
      22              17 :         .with_writer(std::io::stderr)
      23              17 :         .with_target(false);
      24                 : 
      25              17 :     let otlp_layer = tracing_utils::init_tracing("proxy")
      26 UBC           0 :         .await
      27 CBC          17 :         .map(OpenTelemetryLayer::new);
      28              17 : 
      29              17 :     tracing_subscriber::registry()
      30              17 :         .with(env_filter)
      31              17 :         .with(otlp_layer)
      32              17 :         .with(fmt_layer)
      33              17 :         .try_init()?;
      34                 : 
      35              17 :     Ok(LoggingGuard)
      36              17 : }
      37                 : 
      38                 : pub struct LoggingGuard;
      39                 : 
      40                 : impl Drop for LoggingGuard {
      41              17 :     fn drop(&mut self) {
      42              17 :         // Shutdown trace pipeline gracefully, so that it has a chance to send any
      43              17 :         // pending traces before we exit.
      44              17 :         tracing::info!("shutting down the tracing machinery");
      45              17 :         tracing_utils::shutdown_tracing();
      46              17 :     }
      47                 : }
        

Generated by: LCOV version 2.1-beta