From ce5385d7979f1c8a4a503fa4b0622146110f23d6 Mon Sep 17 00:00:00 2001 From: dev0 Date: Tue, 19 Nov 2024 23:11:27 +1100 Subject: [PATCH] up --- Cargo.lock | 46 ++++++++++++-------------- clash_lib/src/app/logging.rs | 62 +++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b2759cdf..db1c5ee9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -392,9 +392,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axum" -version = "0.7.9" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +checksum = "504e3947307ac8326a5437504c517c4b56716c9d98fac0028c2acc7ca47d70ae" dependencies = [ "async-trait", "axum-core", @@ -615,9 +615,9 @@ dependencies = [ [[package]] name = "bollard" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2b63bbe2a4db01f82f388bee3b1bed3ea9c4cc5f1f4f1fa7a4a171f1ddb2cf1" +checksum = "97ccca1260af6a459d75994ad5acc1651bcabcbdbc41467cc9786519ab854c30" dependencies = [ "base64 0.22.1", "bollard-stubs", @@ -648,9 +648,9 @@ dependencies = [ [[package]] name = "bollard-stubs" -version = "1.46.0-rc.27.3.1" +version = "1.47.1-rc.27.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a79775fcd9a02681f9508cd6e44f2164db81c29506063b5904757dd82879d96" +checksum = "3f179cfbddb6e77a5472703d4b30436bff32929c0aa8a9008ecf23d1d3cdd0da" dependencies = [ "serde", "serde_repr", @@ -3198,9 +3198,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.164" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libloading" @@ -4291,9 +4291,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quinn" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" dependencies = [ "bytes", "futures-io", @@ -4303,29 +4303,26 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "socket2 0.5.7", - "thiserror 2.0.3", + "thiserror 1.0.69", "tokio", "tracing", ] [[package]] name = "quinn-proto" -version = "0.11.9" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", - "getrandom", "rand", "ring 0.17.8", "rustc-hash 2.0.0", "rustls", - "rustls-pki-types", "slab", - "thiserror 2.0.3", + "thiserror 1.0.69", "tinyvec", "tracing", - "web-time", ] [[package]] @@ -4674,9 +4671,6 @@ name = "rustls-pki-types" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" -dependencies = [ - "web-time", -] [[package]] name = "rustls-webpki" @@ -4809,9 +4803,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.215" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] @@ -4828,9 +4822,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", @@ -4848,9 +4842,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.133" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", diff --git a/clash_lib/src/app/logging.rs b/clash_lib/src/app/logging.rs index 8a729129d..5dd73215a 100644 --- a/clash_lib/src/app/logging.rs +++ b/clash_lib/src/app/logging.rs @@ -3,10 +3,14 @@ use std::io::IsTerminal; use crate::def::LogLevel; use opentelemetry::{ global::{self}, - trace::TracerProvider, + trace::TracerProvider as _, KeyValue, }; -use opentelemetry_sdk::{trace, Resource}; +use opentelemetry_otlp::{LogExporter, SpanExporter, WithExportConfig}; +use opentelemetry_sdk::{ + trace::{self, Config, TracerProvider}, + Resource, +}; use opentelemetry_semantic_conventions::{ resource::{DEPLOYMENT_ENVIRONMENT_NAME, SERVICE_NAME, SERVICE_VERSION}, SCHEMA_URL, @@ -17,7 +21,11 @@ use tokio::sync::broadcast::Sender; use tracing::{debug, error}; use tracing_appender::non_blocking::WorkerGuard; use tracing_oslog::OsLogger; -use tracing_subscriber::{filter, filter::Directive, prelude::*, EnvFilter, Layer}; +use tracing_subscriber::{ + filter::{self, filter_fn, Directive}, + prelude::*, + EnvFilter, Layer, +}; impl From for filter::LevelFilter { fn from(level: LogLevel) -> Self { @@ -92,28 +100,23 @@ pub fn setup_logging( global::set_text_map_propagator( opentelemetry_jaeger_propagator::Propagator::new(), ); - global::set_error_handler(|e| { - error!("OpenTelemetry error: {:?}", e); - }) - .unwrap(); - - let provider = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(opentelemetry_otlp::new_exporter().tonic()) - .with_trace_config(trace::Config::default().with_resource( - Resource::from_schema_url( - [ - KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")), - KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION")), - KeyValue::new( - DEPLOYMENT_ENVIRONMENT_NAME, - std::env::var("PROFILE").unwrap_or_default(), - ), - ], - SCHEMA_URL, - ), - )) - .install_batch(opentelemetry_sdk::runtime::Tokio)?; + + let exporter = SpanExporter::builder().with_tonic().build()?; + + let provider = TracerProvider::builder() + .with_config(Config::default().with_resource(Resource::from_schema_url( + [ + KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")), + KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION")), + KeyValue::new( + DEPLOYMENT_ENVIRONMENT_NAME, + std::env::var("PROFILE").unwrap_or_default(), + ), + ], + SCHEMA_URL, + ))) + .with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio) + .build(); global::set_tracer_provider(provider.clone()); @@ -142,6 +145,12 @@ pub fn setup_logging( None }; + let opentelemetry_layer = tracing_subscriber::fmt::Layer::new() + .with_writer(std::io::stderr) + .with_filter(filter_fn(|metadata| { + metadata.target().starts_with("opentelemetry") + })); + let subscriber = tracing_subscriber::registry() .with(jaeger) .with(filter) @@ -167,7 +176,8 @@ pub fn setup_logging( .with_thread_ids(true) .with_writer(std::io::stdout), ) - .with(ios_os_log); + .with(ios_os_log) + .with(opentelemetry_layer); tracing::subscriber::set_global_default(subscriber) .map_err(|x| anyhow!("setup logging error: {}", x))?;