Skip to content

Commit

Permalink
Util -> Upgrade OpenTelemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfm committed Nov 25, 2024
1 parent 8966265 commit 54f442b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 51 deletions.
48 changes: 15 additions & 33 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ nix = "0.29.0"
oauth2 = { version = "4.4.2", default-features = false }
openidconnect = { version = "3.5.0", default-features = false }
openssl-sys = { version = "0.9.102", features = ["vendored"] }
opentelemetry = "0.22.0"
opentelemetry-appender-tracing = "0.3.0"
opentelemetry-otlp = "0.15.0"
opentelemetry_sdk = "0.22.0"
opentelemetry-semantic-conventions = "0.14.0"
opentelemetry = "0.23.0"
opentelemetry-appender-tracing = "0.4.0"
opentelemetry-otlp = "0.16.0"
opentelemetry_sdk = "0.23.0"
opentelemetry-semantic-conventions = "0.15.0"
pem = {version = "3.0.3", features = ["serde"]}
phf = { version = "0.11", features = ["macros"] }
ping-rs = { version = "0.1.2" }
Expand Down Expand Up @@ -147,7 +147,7 @@ tonic-async-interceptor = { version = "0.11.0" }
tower = "0.4.13"
tower-http = { version = "0.4.4", features = ["cors", "fs"] }
tracing = { version = "0.1.40" }
tracing-opentelemetry = "0.23.0"
tracing-opentelemetry = "0.24.0"
tracing-subscriber = { version = "0.3.18", default-features = false }
tracing-web = { version = "0.1.3" }
url = "2.5.0"
Expand Down
8 changes: 7 additions & 1 deletion opendut-util/src/telemetry/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ impl LoggingConfig {
}
}

pub fn init_logger(telemetry_interceptor: ConfClientArcMutex<Option<ConfidentialClientRef>>, endpoint: &Endpoint, service_name: impl Into<String>, service_instance_id: impl Into<String>) -> Result<opentelemetry_sdk::logs::Logger, LogError> {
pub fn init_logger_provider(
telemetry_interceptor: ConfClientArcMutex<Option<ConfidentialClientRef>>,
endpoint: &Endpoint,
service_name: impl Into<String>,
service_instance_id: impl Into<String>
) -> Result<opentelemetry_sdk::logs::LoggerProvider, LogError> {

opentelemetry_otlp::new_pipeline()
.logging()
.with_log_config(
Expand Down
16 changes: 5 additions & 11 deletions opendut-util/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use std::str::FromStr;
use std::sync::Arc;

use opentelemetry::global;
use opentelemetry::global::{GlobalLoggerProvider, logger_provider};
use opentelemetry::trace::TraceError;
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
use opentelemetry_sdk::logs::Logger;
use opentelemetry_sdk::propagation::TraceContextPropagator;
use tokio::sync::Mutex;
use tracing::error;
Expand Down Expand Up @@ -86,7 +84,7 @@ pub async fn initialize_with_config(
None
};

let (tracer, logger, logger_layer, meter_providers) =
let (tracer, logger_layer, meter_providers) =
if let Opentelemetry::Enabled {
collector_endpoint,
service_name,
Expand All @@ -99,9 +97,7 @@ pub async fn initialize_with_config(

let tracer = traces::init_tracer(confidential_client.clone(), &collector_endpoint, service_name.clone(), service_instance_id.clone()).expect("Failed to initialize tracer.");

let logger = logging::init_logger(confidential_client.clone(), &collector_endpoint, service_name.clone(), service_instance_id.clone()).expect("Failed to initialize logs.");

let logger_provider: GlobalLoggerProvider = logger_provider();
let logger_provider = logging::init_logger_provider(confidential_client.clone(), &collector_endpoint, service_name.clone(), service_instance_id.clone()).expect("Failed to initialize logs.");
let logger_layer = OpenTelemetryTracingBridge::new(&logger_provider);

let default_meter_provider = NamedMeterProvider {
Expand Down Expand Up @@ -129,9 +125,9 @@ pub async fn initialize_with_config(
global::set_meter_provider(default_meter_provider.meter_provider.clone());
let meter_providers: NamedMeterProviders = (default_meter_provider, cpu_meter_provider);

(Some(tracer), Some(logger), Some(logger_layer), Some(meter_providers))
(Some(tracer), Some(logger_layer), Some(meter_providers))
} else {
(None, None, None, None)
(None, None, None)
};

tracing_subscriber::registry()
Expand All @@ -142,13 +138,12 @@ pub async fn initialize_with_config(
.with(logger_layer)
.try_init()?;

Ok(ShutdownHandle { _logger: logger, meter_providers })
Ok(ShutdownHandle { meter_providers })
}


#[must_use]
pub struct ShutdownHandle {
pub(crate) _logger: Option<Logger>,
pub meter_providers: Option<(
NamedMeterProvider<NamedMeterProviderKindDefault>,
NamedMeterProvider<NamedMeterProviderKindCpu>
Expand All @@ -157,7 +152,6 @@ pub struct ShutdownHandle {
impl ShutdownHandle {
pub fn shutdown(&mut self) {
global::shutdown_tracer_provider();
global::shutdown_logger_provider();
//global::shutdown_meter_provider(); //TODO re-include when this appears in a release: https://github.com/open-telemetry/opentelemetry-rust/pull/1623
}
}
Expand Down

0 comments on commit 54f442b

Please sign in to comment.