From c53c5f1fcb8dec6e9f0659cd706e793b7e97402e Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 8 Jul 2024 12:52:04 -0700 Subject: [PATCH 1/5] Add code comment about default Log attribute size (#1914) --- opentelemetry-sdk/src/logs/log_emitter.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opentelemetry-sdk/src/logs/log_emitter.rs b/opentelemetry-sdk/src/logs/log_emitter.rs index c26b4f3af7..9914c7b408 100644 --- a/opentelemetry-sdk/src/logs/log_emitter.rs +++ b/opentelemetry-sdk/src/logs/log_emitter.rs @@ -40,6 +40,9 @@ pub struct LoggerProvider { /// Default logger name if empty string is provided. const DEFAULT_COMPONENT_NAME: &str = "rust.opentelemetry.io/sdk/logger"; +// According to a Go-specific study mentioned on https://go.dev/blog/slog, +// up to 5 attributes is the most common case. We have chosen 8 as the default +// capacity for attributes to avoid reallocation in common scenarios. const PREALLOCATED_ATTRIBUTE_CAPACITY: usize = 8; impl opentelemetry::logs::LoggerProvider for LoggerProvider { From 224289e9e079fa8c5e41b34d337233d1b0956f43 Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Wed, 10 Jul 2024 18:45:19 +0200 Subject: [PATCH 2/5] Remove `isahc` support (#1924) --- .cspell.json | 1 - Cargo.toml | 3 +-- opentelemetry-http/CHANGELOG.md | 1 + opentelemetry-http/Cargo.toml | 1 - opentelemetry-http/src/lib.rs | 26 -------------------------- scripts/patch_dependencies.sh | 2 ++ 6 files changed, 4 insertions(+), 30 deletions(-) diff --git a/.cspell.json b/.cspell.json index 47fc5d18e8..23ecd03c8b 100644 --- a/.cspell.json +++ b/.cspell.json @@ -37,7 +37,6 @@ "Dirkjan", "EPYC", "hasher", - "isahc", "Isobel", "jaegertracing", "Kühle", diff --git a/Cargo.toml b/Cargo.toml index f5d93d6b8a..28a0dea98d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ futures-executor = "0.3" futures-util = { version = "0.3", default-features = false } hyper = { version = "0.14", default-features = false } http = { version = "0.2", default-features = false } -isahc = { version = "1.4", default-features = false } log = "0.4.21" once_cell = "1.13" ordered-float = "4.0" @@ -46,4 +45,4 @@ tokio-stream = "0.1.1" tracing = { version = "0.1", default-features = false } tracing-core = { version = "0.1", default-features = false } tracing-subscriber = { version = "0.3", default-features = false } -url = { version = "=2.5.0", default-features = false } #pinning the version supporting rustc 1.65 +url = { version = "2.5", default-features = false } diff --git a/opentelemetry-http/CHANGELOG.md b/opentelemetry-http/CHANGELOG.md index c19fd56dea..51880f3c31 100644 --- a/opentelemetry-http/CHANGELOG.md +++ b/opentelemetry-http/CHANGELOG.md @@ -3,6 +3,7 @@ ## vNext - **Breaking** Correct the misspelling of "webkpi" to "webpki" in features [#1842](https://github.com/open-telemetry/opentelemetry-rust/pull/1842) +- **Breaking** Remove support for the `isahc` HTTP client [#1924](https://github.com/open-telemetry/opentelemetry-rust/pull/1924) ## v0.12.0 diff --git a/opentelemetry-http/Cargo.toml b/opentelemetry-http/Cargo.toml index a3fda11719..f7472054df 100644 --- a/opentelemetry-http/Cargo.toml +++ b/opentelemetry-http/Cargo.toml @@ -18,7 +18,6 @@ async-trait = { workspace = true } bytes = { workspace = true } http = { workspace = true } hyper = { workspace = true, features = ["http2", "client", "tcp"], optional = true } -isahc = { workspace = true, optional = true } opentelemetry = { version = "0.23", path = "../opentelemetry", features = ["trace"] } reqwest = { workspace = true, features = ["blocking"], optional = true } tokio = { workspace = true, features = ["time"], optional = true } diff --git a/opentelemetry-http/src/lib.rs b/opentelemetry-http/src/lib.rs index cee858b647..b921a41d9c 100644 --- a/opentelemetry-http/src/lib.rs +++ b/opentelemetry-http/src/lib.rs @@ -99,32 +99,6 @@ mod reqwest { } } -#[cfg(feature = "isahc")] -mod isahc { - use crate::ResponseExt; - - use super::{async_trait, Bytes, HttpClient, HttpError, Request, Response}; - use isahc::AsyncReadResponseExt; - use std::convert::TryInto as _; - - #[async_trait] - impl HttpClient for isahc::HttpClient { - async fn send(&self, request: Request>) -> Result, HttpError> { - let mut response = self.send_async(request).await?; - let mut bytes = Vec::with_capacity(response.body().len().unwrap_or(0).try_into()?); - response.copy_to(&mut bytes).await?; - - let headers = std::mem::take(response.headers_mut()); - let mut http_response = Response::builder() - .status(response.status().as_u16()) - .body(bytes.into())?; - *http_response.headers_mut() = headers; - - Ok(http_response.error_for_status()?) - } - } -} - #[cfg(feature = "hyper")] pub mod hyper { use crate::ResponseExt; diff --git a/scripts/patch_dependencies.sh b/scripts/patch_dependencies.sh index ff7ffc7070..d52547db67 100755 --- a/scripts/patch_dependencies.sh +++ b/scripts/patch_dependencies.sh @@ -6,3 +6,5 @@ function patch_version() { cargo update -p $1:$latest_version --precise $2 } +patch_version cc 1.0.105 +patch_version url 2.5.0 From 3882b2288dd7e056c98d992d1fe7b6f4f49171d9 Mon Sep 17 00:00:00 2001 From: Ramji Date: Wed, 10 Jul 2024 13:06:02 -0400 Subject: [PATCH 3/5] Update http example with json protocol (#1912) Co-authored-by: Cijo Thomas Co-authored-by: Lalit Kumar Bhasin --- opentelemetry-otlp/Cargo.toml | 1 - .../examples/basic-otlp-http/Cargo.toml | 2 +- .../examples/basic-otlp-http/README.md | 4 ++-- .../examples/basic-otlp-http/src/main.rs | 22 ++++++++++++++----- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/opentelemetry-otlp/Cargo.toml b/opentelemetry-otlp/Cargo.toml index f031791aa6..2a04fa9956 100644 --- a/opentelemetry-otlp/Cargo.toml +++ b/opentelemetry-otlp/Cargo.toml @@ -71,7 +71,6 @@ tls-webpki-roots = ["tls", "tonic/tls-webpki-roots"] # http binary http-proto = ["prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "http", "trace", "metrics"] -# http json This does not work today due to known issue. See https://github.com/open-telemetry/opentelemetry-rust/issues/1763. http-json = ["serde_json", "prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "opentelemetry-proto/with-serde", "http", "trace", "metrics"] reqwest-blocking-client = ["reqwest/blocking", "opentelemetry-http/reqwest"] reqwest-client = ["reqwest", "opentelemetry-http/reqwest"] diff --git a/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml b/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml index 5357988ad5..149a734304 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml +++ b/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml @@ -16,7 +16,7 @@ once_cell = { workspace = true } opentelemetry = { path = "../../../opentelemetry" } opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "metrics", "logs"] } opentelemetry-http = { path = "../../../opentelemetry-http", optional = true } -opentelemetry-otlp = { path = "../..", features = ["http-proto", "reqwest-client", "logs"] } +opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "reqwest-client", "logs"] } opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false} opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-conventions" } diff --git a/opentelemetry-otlp/examples/basic-otlp-http/README.md b/opentelemetry-otlp/examples/basic-otlp-http/README.md index 91394b1560..d70a5534a0 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/README.md +++ b/opentelemetry-otlp/examples/basic-otlp-http/README.md @@ -1,9 +1,9 @@ # Basic OTLP exporter Example This example shows how to setup OpenTelemetry OTLP exporter for logs, metrics -and traces to exports them to the [OpenTelemetry +and traces to export them to the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP -over HTTP/protobuf. The Collector then sends the data to the appropriate +over selected protocol such as HTTP/protobuf or HTTP/json. The Collector then sends the data to the appropriate backend, in this case, the logging Exporter, which displays data to console. ## Usage diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index 3e7c41b48d..610268294e 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -6,18 +6,18 @@ use opentelemetry::{ Key, KeyValue, }; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; +use opentelemetry_otlp::Protocol; use opentelemetry_otlp::{HttpExporterBuilder, WithExportConfig}; use opentelemetry_sdk::trace::{self as sdktrace, Config}; use opentelemetry_sdk::{ logs::{self as sdklogs}, Resource, }; +use std::error::Error; use tracing::info; use tracing_subscriber::prelude::*; use tracing_subscriber::EnvFilter; -use std::error::Error; - #[cfg(feature = "hyper")] mod hyper; @@ -39,14 +39,22 @@ fn init_logs() -> Result opentelemetry_otlp::new_pipeline() .logging() .with_resource(RESOURCE.clone()) - .with_exporter(http_exporter().with_endpoint("http://localhost:4318/v1/logs")) + .with_exporter( + http_exporter() + .with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format + .with_endpoint("http://localhost:4318/v1/logs"), + ) .install_batch(opentelemetry_sdk::runtime::Tokio) } fn init_tracer_provider() -> Result { opentelemetry_otlp::new_pipeline() .tracing() - .with_exporter(http_exporter().with_endpoint("http://localhost:4318/v1/traces")) + .with_exporter( + http_exporter() + .with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format + .with_endpoint("http://localhost:4318/v1/traces"), + ) .with_trace_config(Config::default().with_resource(RESOURCE.clone())) .install_batch(opentelemetry_sdk::runtime::Tokio) } @@ -54,7 +62,11 @@ fn init_tracer_provider() -> Result { fn init_metrics() -> Result { opentelemetry_otlp::new_pipeline() .metrics(opentelemetry_sdk::runtime::Tokio) - .with_exporter(http_exporter().with_endpoint("http://localhost:4318/v1/metrics")) + .with_exporter( + http_exporter() + .with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format + .with_endpoint("http://localhost:4318/v1/metrics"), + ) .with_resource(RESOURCE.clone()) .build() } From df815bdc7fa19b16a28c15d8c8d47def5aea0321 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 10 Jul 2024 18:03:05 -0700 Subject: [PATCH 4/5] Simplify OTLP example (#1926) --- opentelemetry-otlp/examples/basic-otlp/src/main.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index 0a98be997d..f18de642f9 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -40,7 +40,7 @@ fn init_metrics() -> Result Result Ok(provider), - Err(err) => Err(err), - } + .build() } fn init_logs() -> Result { From 166a12734c873bf4984eddb14274da6fbd36bd3c Mon Sep 17 00:00:00 2001 From: Shawn <18649508+NOBLES5E@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:38:49 -0400 Subject: [PATCH 5/5] Update CHANGELOG.md (#1927) --- opentelemetry-sdk/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 61d99a629b..88e303a9ac 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -17,13 +17,13 @@ `RwLock` instead of `Mutex` to reduce contention - **Breaking** [1726](https://github.com/open-telemetry/opentelemetry-rust/pull/1726) - Update `LogProcessor::emit() method to take mutable reference to LogData. This is breaking + Update `LogProcessor::emit()` method to take mutable reference to LogData. This is breaking change for LogProcessor developers. If the processor needs to invoke the exporter asynchronously, it should clone the data to ensure it can be safely processed without lifetime issues. Any changes made to the log data before cloning in this method will be reflected in the next log processor in the chain, as well as to the exporter. - **Breaking** [1726](https://github.com/open-telemetry/opentelemetry-rust/pull/1726) - Update `LogExporter::export() method to accept a batch of log data, which can be either a + Update `LogExporter::export()` method to accept a batch of log data, which can be either a reference or owned`LogData`. If the exporter needs to process the log data asynchronously, it should clone the log data to ensure it can be safely processed without lifetime issues.