From 0e0fe4181503371c1510dea1bf456530dc82f0b3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:37:58 +0000 Subject: [PATCH 1/2] fix(deps): update opentelemetry --- Cargo.lock | 38 ++++++++++++++++++++------------------ Cargo.toml | 16 ++++++++-------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbe5e4b..86a16e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1144,9 +1144,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", @@ -1158,9 +1158,9 @@ dependencies = [ [[package]] name = "opentelemetry-http" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6351496aeaa49d7c267fb480678d85d1cd30c5edb20b497c48c56f62a8c14b99" +checksum = "10a8a7f5f6ba7c1b286c2fbca0454eaba116f63bbe69ed250b642d36fbb04d80" dependencies = [ "async-trait", "bytes", @@ -1175,9 +1175,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", @@ -1190,13 +1190,14 @@ dependencies = [ "thiserror", "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", @@ -1206,15 +1207,15 @@ dependencies = [ [[package]] name = "opentelemetry-semantic-conventions" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db945c1eaea8ac6a9677185357480d215bb6999faa9f691d0c4d4d641eab7a09" +checksum = "bc1b6902ff63b32ef6c489e8048c5e253e2e4a803ea3ea7e783914536eb15c52" [[package]] name = "opentelemetry-zipkin" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd5f25a628014191d3e98bb4794e37771b580e9c3de341cf1c813019aa721278" +checksum = "4c630342febc883d74af134b87f75f0bded45bd56d1a7673685df23d400a9d26" dependencies = [ "async-trait", "futures-core", @@ -1249,9 +1250,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", @@ -1266,6 +1267,7 @@ dependencies = [ "thiserror", "tokio", "tokio-stream", + "tracing", ] [[package]] @@ -2094,9 +2096,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", @@ -2112,9 +2114,9 @@ dependencies = [ [[package]] name = "tracing-opentelemetry-instrumentation-sdk" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e23ebe790a95c3105f5a7ec8e7c33884ecc8462f751f7f719d2356a3cfa122b" +checksum = "ece512a961221014e69a59c75561a2889835325c7520551ca721145809f9e40c" dependencies = [ "http 1.1.0", "opentelemetry", diff --git a/Cargo.toml b/Cargo.toml index d197f01..24554d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,18 +7,18 @@ description = "Open Telemetry fox Axum and Tracing" [dependencies] http = "1.1.0" -opentelemetry = { version = "0.26", default-features = false, features = [ +opentelemetry = { version = "0.27", default-features = false, features = [ "trace", ] } -tracing-opentelemetry = "0.27" -opentelemetry-http = { version = "0.26", features = ["hyper"] } -opentelemetry-otlp = { version = "0.26", features = ["http-proto"] } -opentelemetry-zipkin = { version = "0.26", features = [], optional = true } -opentelemetry_sdk = { version = "0.26", default-features = false, features = [ +tracing-opentelemetry = "0.28" +opentelemetry-http = { version = "0.27", features = ["hyper"] } +opentelemetry-otlp = { version = "0.27", features = ["http-proto"] } +opentelemetry-zipkin = { version = "0.27", features = [], optional = true } +opentelemetry_sdk = { version = "0.27", default-features = false, features = [ "rt-tokio", ] } -opentelemetry-semantic-conventions = { version = "0.26", features = ["semconv_experimental"] } -tracing-opentelemetry-instrumentation-sdk = { version = "0.23", features = ["http"] } +opentelemetry-semantic-conventions = { version = "0.27", features = ["semconv_experimental"] } +tracing-opentelemetry-instrumentation-sdk = { version = "0.24", features = ["http"] } tracing = { version = "0.1.40", default-features = false } tracing-subscriber = { version = "0.3.18", default-features = false, features = [ "env-filter", From f20df80bf0882f21f0022bcfbb92563a3499ab1a Mon Sep 17 00:00:00 2001 From: Leonid Beschastny Date: Mon, 18 Nov 2024 18:52:07 +0100 Subject: [PATCH 2/2] Fix all breaking changes --- Cargo.lock | 1 - Cargo.toml | 1 - src/otlp.rs | 84 ++++++++++++++++++++++------------------------------- 3 files changed, 34 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86a16e2..105cbb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1788,7 +1788,6 @@ dependencies = [ "http 1.1.0", "http-body-util", "hyper", - "hyper-util", "lambda_runtime", "opentelemetry", "opentelemetry-http", diff --git a/Cargo.toml b/Cargo.toml index 24554d8..8e3c3c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ http-body-util = { version = "0.1.1", optional = true } aws-types = { version = "1", optional = true } lambda_runtime = { version = "0", optional = true } paste = { version = "1.0.14", optional = true } -hyper-util = "0.1.9" [dev-dependencies] assert2 = "0.3" diff --git a/src/otlp.rs b/src/otlp.rs index 2cd8148..141afbf 100644 --- a/src/otlp.rs +++ b/src/otlp.rs @@ -4,12 +4,14 @@ use std::{collections::HashMap, str::FromStr}; -use hyper_util::{client::legacy::Client, rt::TokioExecutor}; use opentelemetry::trace::TraceError; use opentelemetry_http::hyper::HyperClient; -use opentelemetry_otlp::{ExportConfig, Protocol, SpanExporterBuilder}; +use opentelemetry_otlp::{ + ExportConfig, Protocol, SpanExporter, WithExportConfig, WithHttpConfig, +}; use opentelemetry_sdk::{ - trace::{Sampler, TracerProvider}, + runtime, + trace::{Config as TraceConfig, Sampler, TracerProvider}, Resource, }; use std::time::Duration; @@ -19,8 +21,8 @@ use crate::util; #[must_use] pub fn identity( - v: opentelemetry_otlp::OtlpTracePipeline, -) -> opentelemetry_otlp::OtlpTracePipeline { + v: opentelemetry_sdk::trace::Builder, +) -> opentelemetry_sdk::trace::Builder { v } @@ -30,12 +32,8 @@ pub fn init_tracer( transform: F, ) -> Result where - F: FnOnce( - opentelemetry_otlp::OtlpTracePipeline, - ) -> opentelemetry_otlp::OtlpTracePipeline, + F: FnOnce(opentelemetry_sdk::trace::Builder) -> opentelemetry_sdk::trace::Builder, { - use opentelemetry_otlp::WithExportConfig; - let (maybe_protocol, maybe_endpoint, maybe_timeout) = read_export_config_from_env(); let export_config = infer_export_config( maybe_protocol.as_deref(), @@ -43,33 +41,32 @@ where maybe_timeout.as_deref(), )?; tracing::debug!(target: "otel::setup", export_config = format!("{export_config:?}")); - let exporter: SpanExporterBuilder = match export_config.protocol { - Protocol::HttpBinary => opentelemetry_otlp::new_exporter() - .http() - .with_http_client(HyperClient::new_with_timeout( - Client::builder(TokioExecutor::new()).build_http(), + let exporter: SpanExporter = match export_config.protocol { + Protocol::HttpBinary => SpanExporter::builder() + .with_http() + .with_http_client(HyperClient::with_default_connector( export_config.timeout, + None, )) .with_headers(read_headers_from_env()) .with_export_config(export_config) - .into(), - Protocol::Grpc => opentelemetry_otlp::new_exporter() - .tonic() + .build()?, + Protocol::Grpc => SpanExporter::builder() + .with_tonic() .with_export_config(export_config) - .into(), + .build()?, Protocol::HttpJson => unreachable!("HttpJson protocol is not supported"), }; - let mut pipeline = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(exporter) - .with_trace_config( - opentelemetry_sdk::trace::Config::default() + let tracer_provider_builder = TracerProvider::builder() + .with_batch_exporter(exporter, runtime::Tokio) + .with_config( + TraceConfig::default() .with_resource(resource) .with_sampler(read_sampler_from_env()), ); - pipeline = transform(pipeline); - pipeline.install_batch(opentelemetry_sdk::runtime::Tokio) + + Ok(transform(tracer_provider_builder).build()) } /// turn a string of "k1=v1,k2=v2,..." into an iterator of (key, value) tuples @@ -157,12 +154,6 @@ fn infer_export_config( }, }; - let endpoint = match protocol { - Protocol::HttpBinary => maybe_endpoint.unwrap_or("http://localhost:4318"), - Protocol::Grpc => maybe_endpoint.unwrap_or("http://localhost:4317"), - Protocol::HttpJson => unreachable!("HttpJson protocol is not supported"), - }; - let timeout = match maybe_timeout { Some(millis) => Duration::from_millis(millis.parse::().map_err(|err| { TraceError::from(format!("invalid timeout {millis:?} form env: {err}")) @@ -173,7 +164,7 @@ fn infer_export_config( }; Ok(ExportConfig { - endpoint: endpoint.to_owned(), + endpoint: maybe_endpoint.map(ToOwned::to_owned), protocol, timeout, }) @@ -191,23 +182,16 @@ mod tests { Duration::from_secs(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT); #[rstest] - #[case(None, None, None, HttpBinary, "http://localhost:4318", TIMEOUT)] - #[case( - Some("http/protobuf"), - None, - None, - HttpBinary, - "http://localhost:4318", - TIMEOUT - )] - #[case(Some("http"), None, None, HttpBinary, "http://localhost:4318", TIMEOUT)] - #[case(Some("grpc"), None, None, Grpc, "http://localhost:4317", TIMEOUT)] + #[case(None, None, None, HttpBinary, None, TIMEOUT)] + #[case(Some("http/protobuf"), None, None, HttpBinary, None, TIMEOUT)] + #[case(Some("http"), None, None, HttpBinary, None, TIMEOUT)] + #[case(Some("grpc"), None, None, Grpc, None, TIMEOUT)] #[case( None, Some("http://localhost:4317"), None, Grpc, - "http://localhost:4317", + Some("http://localhost:4317"), TIMEOUT )] #[case( @@ -215,7 +199,7 @@ mod tests { Some("http://localhost:4318"), None, HttpBinary, - "http://localhost:4318", + Some("http://localhost:4318"), TIMEOUT )] #[case( @@ -223,7 +207,7 @@ mod tests { Some("https://examples.com:4318"), None, HttpBinary, - "https://examples.com:4318", + Some("https://examples.com:4318"), TIMEOUT )] #[case( @@ -231,7 +215,7 @@ mod tests { Some("https://examples.com:4317"), Some("12345"), HttpBinary, - "https://examples.com:4317", + Some("https://examples.com:4317"), Duration::from_millis(12345) )] fn test_infer_export_config( @@ -239,7 +223,7 @@ mod tests { #[case] traces_endpoint: Option<&str>, #[case] traces_timeout: Option<&str>, #[case] expected_protocol: Protocol, - #[case] expected_endpoint: &str, + #[case] expected_endpoint: Option<&str>, #[case] expected_timeout: Duration, ) { let ExportConfig { @@ -250,7 +234,7 @@ mod tests { .unwrap(); assert!(protocol == expected_protocol); - assert!(endpoint == expected_endpoint); + assert!(endpoint.as_deref() == expected_endpoint); assert!(timeout == expected_timeout); } }