Skip to content

Commit

Permalink
honor OTLP env vars (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug authored May 31, 2024
1 parent 133157d commit 292c261
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 72 deletions.
42 changes: 0 additions & 42 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ opentelemetry = "0.23"
opentelemetry_sdk = { version = "0.23", features = ["rt-tokio"] }
tracing-opentelemetry = "0.24"
opentelemetry-jaeger-propagator = "0.2.0"
opentelemetry-jaeger = { version = "0.22", features = ["collector_client", "hyper_collector_client", "rt-tokio"] }
opentelemetry-jaeger = { version = "0.22", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.16.0", features = ["grpc-tonic"] }

crc32fast = "1.4.2"
Expand Down
40 changes: 19 additions & 21 deletions clash_lib/src/app/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use std::io::IsTerminal;
use crate::def::LogLevel;
use opentelemetry::global;
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::trace;
use opentelemetry_sdk::trace::Sampler;
use opentelemetry_sdk::Resource;
use serde::Serialize;
use tokio::sync::broadcast::Sender;

use tracing::debug;
use tracing::error;
use tracing_appender::non_blocking::NonBlocking;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_oslog::OsLogger;
Expand Down Expand Up @@ -103,28 +102,27 @@ pub fn setup_logging(
.with_default_directive(format!("clash={}", level).parse::<Directive>().unwrap())
.from_env_lossy();

let jaeger = if let Ok(jager_endpoint) = std::env::var("JAGER_ENDPOINT") {
let jaeger = if std::env::var("JAEGER_DISABLED").is_ok() {
None
} else {
global::set_text_map_propagator(opentelemetry_jaeger_propagator::Propagator::new());

let otlp_exporter = opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(jager_endpoint);
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(otlp_exporter)
.with_trace_config(
trace::config()
.with_sampler(Sampler::AlwaysOn)
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"clash-rs",
)])),
)
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
global::set_error_handler(|e| {
error!("OpenTelemetry error: {:?}", e);
})
.unwrap();

let otlp_exporter = opentelemetry_otlp::new_exporter().tonic();

let tracer =
opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(otlp_exporter)
.with_trace_config(trace::config().with_resource(Resource::new(vec![
KeyValue::new("service.name", "clash-rs"),
])))
.install_batch(opentelemetry_sdk::runtime::Tokio)?;

Some(tracing_opentelemetry::layer().with_tracer(tracer))
} else {
None
};

let ios_os_log = if cfg!(target_os = "ios") {
Expand Down
9 changes: 1 addition & 8 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
- type: bind
source: ./v2ray/key.pem
target: /etc/v2ray/v2ray.key
restart: unless-stopped

nginx:
image: nginx
Expand All @@ -37,12 +38,4 @@ services:
- type: bind
source: ./v2ray/key.pem
target: /etc/v2ray/v2ray.key

wireguard:
image: linuxserver/wireguard:latest
network_mode: "host"
cap_add:
- NET_ADMIN
volumes:
- ./wg/config:/config
restart: unless-stopped

0 comments on commit 292c261

Please sign in to comment.