Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Nov 19, 2024
1 parent 78f7e9b commit ce5385d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 52 deletions.
46 changes: 20 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 36 additions & 26 deletions clash_lib/src/app/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-musleabihf

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-unknown-linux-gnu-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-unknown-linux-gnu

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-musl

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-gnu

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-linux-android

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-gnu

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-gnu-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-linux-androideabi

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-linux-android

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabi

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabi-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-gnu-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-musl

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-pc-windows-msvc-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabihf

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin-static-crt

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-linux-android

unused imports: `LogExporter` and `WithExportConfig`

Check failure on line 9 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-pc-windows-msvc

unused imports: `LogExporter` and `WithExportConfig`
use opentelemetry_sdk::{
trace::{self, Config, TracerProvider},

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-musleabihf

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-unknown-linux-gnu-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-unknown-linux-gnu

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-musl

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-gnu

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-linux-android

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-gnu

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-gnu-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-linux-androideabi

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-linux-android

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabi

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabi-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-gnu-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-musl

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-pc-windows-msvc-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabihf

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin-static-crt

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-linux-android

unused import: `self`

Check failure on line 11 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-pc-windows-msvc

unused import: `self`
Resource,
};
use opentelemetry_semantic_conventions::{
resource::{DEPLOYMENT_ENVIRONMENT_NAME, SERVICE_NAME, SERVICE_VERSION},
SCHEMA_URL,
Expand All @@ -17,7 +21,11 @@ use tokio::sync::broadcast::Sender;
use tracing::{debug, error};

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-musleabihf

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-unknown-linux-gnu-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-unknown-linux-gnu

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-musl

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-gnu

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-linux-android

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-gnu

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-gnu-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-linux-androideabi

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / i686-linux-android

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabi

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabi-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-unknown-linux-gnu-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-unknown-linux-musl

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-pc-windows-msvc-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / armv7-unknown-linux-gnueabihf

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin-static-crt

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-linux-android

unused import: `error`

Check failure on line 21 in clash_lib/src/app/logging.rs

View workflow job for this annotation

GitHub Actions / aarch64-pc-windows-msvc

unused import: `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<LogLevel> for filter::LevelFilter {
fn from(level: LogLevel) -> Self {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)
Expand All @@ -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))?;
Expand Down

0 comments on commit ce5385d

Please sign in to comment.