From b00d961d8eda76da9d7c2f5920d70284bb5d0cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Guilherme=20Vanz?= Date: Thu, 14 Nov 2024 10:55:24 -0300 Subject: [PATCH] chore(deps): updates OpenTelemetry dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates policy-server to use the latest version of OpenTelemetry libraries. Signed-off-by: José Guilherme Vanz --- Cargo.lock | 24 +++++++++++---------- Cargo.toml | 8 +++---- src/metrics.rs | 23 ++++++++++---------- src/metrics/policy_evaluations_latency.rs | 2 +- src/metrics/policy_evaluations_total.rs | 2 +- src/tracing.rs | 26 ++++++++++++++--------- 6 files changed, 47 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca1f88b7..011d4eff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3110,7 +3110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -3704,9 +3704,9 @@ dependencies = [ [[package]] name = "opentelemetry" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570074cc999d1a58184080966e5bd3bf3a9a4af650c3b05047c2621e7405cd17" +checksum = "0f3cebff57f7dbd1255b44d8bddc2cebeb0ea677dbaa2e25a3070a91b318f660" dependencies = [ "futures-core", "futures-sink", @@ -3718,9 +3718,9 @@ dependencies = [ [[package]] name = "opentelemetry-otlp" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e1f9c8b032d4f635c730c0efcf731d5e2530ea13fa8bef7939ddc8420696bd" +checksum = "91cf61a1868dacc576bf2b2a1c3e9ab150af7272909e80085c3173384fe11f76" dependencies = [ "async-trait", "futures-core", @@ -3732,13 +3732,14 @@ dependencies = [ "thiserror 1.0.69", "tokio", "tonic", + "tracing", ] [[package]] name = "opentelemetry-proto" -version = "0.26.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9d3968ce3aefdcca5c27e3c4ea4391b37547726a70893aab52d3de95d5f8b34" +checksum = "a6e05acbfada5ec79023c85368af14abd0b307c015e9064d249b2a950ef459a6" dependencies = [ "opentelemetry", "opentelemetry_sdk", @@ -3748,9 +3749,9 @@ dependencies = [ [[package]] name = "opentelemetry_sdk" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c627d9f4c9cdc1f21a29ee4bfbd6028fcb8bcf2a857b43f3abdf72c9c862f3" +checksum = "27b742c1cae4693792cc564e58d75a2a0ba29421a34a85b50da92efa89ecb2bc" dependencies = [ "async-trait", "futures-channel", @@ -3765,6 +3766,7 @@ dependencies = [ "thiserror 1.0.69", "tokio", "tokio-stream", + "tracing", ] [[package]] @@ -6480,9 +6482,9 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc58af5d3f6c5811462cabb3289aec0093f7338e367e5a33d28c0433b3c7360b" +checksum = "97a971f6058498b5c0f1affa23e7ea202057a7301dbff68e968b2d578bcbd053" dependencies = [ "js-sys", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index dee6ea7c..5e00d206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,12 +22,12 @@ k8s-openapi = { version = "0.23.0", default-features = false, features = [ lazy_static = "1.4.0" mime = "0.3" num_cpus = "1.16.0" -opentelemetry-otlp = { version = "0.26.0", features = ["metrics", "tonic"] } -opentelemetry = { version = "0.26.0", default-features = false, features = [ +opentelemetry-otlp = { version = "0.27.0", features = ["metrics", "tonic"] } +opentelemetry = { version = "0.27.0", default-features = false, features = [ "metrics", "trace", ] } -opentelemetry_sdk = { version = "0.26.0", features = ["rt-tokio"] } +opentelemetry_sdk = { version = "0.27.0", features = ["rt-tokio"] } pprof = { version = "0.14", features = ["prost-codec"] } policy-evaluator = { git = "https://github.com/kubewarden/policy-evaluator", tag = "v0.19.3" } rustls = { version = "0.23", default-features = false, features = [ @@ -46,7 +46,7 @@ sha2 = "0.10" thiserror = "2.0" tokio = { version = "^1.41.0", features = ["full"] } tracing = "0.1" -tracing-opentelemetry = "0.27.0" +tracing-opentelemetry = "0.28.0" tracing-subscriber = { version = "0.3", features = ["ansi", "fmt", "json"] } semver = { version = "1.0.22", features = ["serde"] } mockall_double = "0.3" diff --git a/src/metrics.rs b/src/metrics.rs index c3a3e9c8..d771af5d 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -11,17 +11,18 @@ pub use policy_evaluations_latency::record_policy_latency; const METER_NAME: &str = "kubewarden"; pub fn setup_metrics() -> Result<()> { - let meter_provider = opentelemetry_otlp::new_pipeline() - .metrics(runtime::Tokio) - .with_exporter( - opentelemetry_otlp::new_exporter() - .tonic() - .with_export_config(ExportConfig::default()), - ) - .build()?; - - global::set_meter_provider(meter_provider.clone()); - + let meter_reader = opentelemetry_sdk::metrics::PeriodicReader::builder( + opentelemetry_otlp::MetricExporter::builder() + .with_tonic() + .with_export_config(ExportConfig::default()) + .build()?, + runtime::Tokio, + ) + .build(); + let meter_provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder() + .with_reader(meter_reader) + .build(); + global::set_meter_provider(meter_provider); Ok(()) } diff --git a/src/metrics/policy_evaluations_latency.rs b/src/metrics/policy_evaluations_latency.rs index 85e7e2a9..4ab0fcf9 100644 --- a/src/metrics/policy_evaluations_latency.rs +++ b/src/metrics/policy_evaluations_latency.rs @@ -9,7 +9,7 @@ lazy_static! { static ref POLICY_EVALUATION_LATENCY: Histogram = opentelemetry::global::meter(super::METER_NAME) .u64_histogram("kubewarden_policy_evaluation_latency_milliseconds") - .init(); + .build(); } pub fn record_policy_latency(latency: Duration, policy_evaluation: impl PolicyEvaluationMetric) { diff --git a/src/metrics/policy_evaluations_total.rs b/src/metrics/policy_evaluations_total.rs index 7203d8f7..0f55b7db 100644 --- a/src/metrics/policy_evaluations_total.rs +++ b/src/metrics/policy_evaluations_total.rs @@ -7,7 +7,7 @@ lazy_static! { static ref POLICY_EVALUATIONS_TOTAL: Counter = opentelemetry::global::meter(super::METER_NAME) .u64_counter("kubewarden_policy_evaluations_total") - .init(); + .build(); } pub fn add_policy_evaluation(policy_evaluation: impl PolicyEvaluationMetric) { diff --git a/src/tracing.rs b/src/tracing.rs index 2ba18aa4..779ced5b 100644 --- a/src/tracing.rs +++ b/src/tracing.rs @@ -39,16 +39,22 @@ pub fn setup_tracing(log_level: &str, log_fmt: &str, log_no_color: bool) -> Resu // OpenTelemetry collector using the OTLP format. // The collector must run on localhost (eg: use a sidecar inside of k8s) // using GRPC - let tracer_provider = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(opentelemetry_otlp::new_exporter().tonic()) - .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource( - opentelemetry_sdk::Resource::new(vec![opentelemetry::KeyValue::new( - "service.name", - config::SERVICE_NAME, - )]), - )) - .install_batch(opentelemetry_sdk::runtime::Tokio)?; + let otlp_exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .build()?; + + let tracer_config = opentelemetry_sdk::trace::Config::default().with_resource( + opentelemetry_sdk::Resource::new(vec![opentelemetry::KeyValue::new( + "service.name", + config::SERVICE_NAME, + )]), + ); + + let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder() + .with_config(tracer_config) + .with_batch_exporter(otlp_exporter, opentelemetry_sdk::runtime::Tokio) + .build(); + let tracer = tracer_provider.tracer(config::SERVICE_NAME); // Create a tracing layer with the configured tracer