From 0a7ad690fc9c15d3de6bb4c3c5caa510daff5ec4 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 18 Dec 2024 18:21:06 -0800 Subject: [PATCH] Add internal logging to HTTP libraries (#2452) --- .github/workflows/integration_tests.yml | 2 +- opentelemetry-http/CHANGELOG.md | 2 +- opentelemetry-http/Cargo.toml | 3 +++ opentelemetry-http/src/lib.rs | 9 +++++++-- opentelemetry-otlp/Cargo.toml | 2 +- opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml | 2 +- opentelemetry-otlp/src/exporter/http/logs.rs | 2 ++ opentelemetry-otlp/src/exporter/http/metrics.rs | 2 ++ opentelemetry-otlp/src/exporter/http/trace.rs | 3 ++- 9 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 2f21b5f3db..badc78fb10 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -24,5 +24,5 @@ jobs: with: components: rustfmt - uses: arduino/setup-protoc@v3 - - name: Run integration tests using docker compose + - name: Run integration tests run: ./scripts/integration_tests.sh diff --git a/opentelemetry-http/CHANGELOG.md b/opentelemetry-http/CHANGELOG.md index 30f10c2b87..18f06ca63d 100644 --- a/opentelemetry-http/CHANGELOG.md +++ b/opentelemetry-http/CHANGELOG.md @@ -3,7 +3,7 @@ ## vNext - Bump msrv to 1.75.0. - +- Add "internal-logs" feature flag (enabled by default), and emit internal logs. ## 0.27.0 diff --git a/opentelemetry-http/Cargo.toml b/opentelemetry-http/Cargo.toml index 77da400bd2..fcc8492641 100644 --- a/opentelemetry-http/Cargo.toml +++ b/opentelemetry-http/Cargo.toml @@ -10,9 +10,11 @@ edition = "2021" rust-version = "1.75.0" [features] +default = ["internal-logs"] hyper = ["dep:http-body-util", "dep:hyper", "dep:hyper-util", "dep:tokio"] reqwest-rustls = ["reqwest", "reqwest/rustls-tls-native-roots"] reqwest-rustls-webpki-roots = ["reqwest", "reqwest/rustls-tls-webpki-roots"] +internal-logs = ["tracing", "opentelemetry/internal-logs"] [dependencies] async-trait = { workspace = true } @@ -24,3 +26,4 @@ hyper-util = { workspace = true, features = ["client-legacy", "http1", "http2"], opentelemetry = { version = "0.27", path = "../opentelemetry", features = ["trace"] } reqwest = { workspace = true, features = ["blocking"], optional = true } tokio = { workspace = true, features = ["time"], optional = true } +tracing = {workspace = true, optional = true} \ No newline at end of file diff --git a/opentelemetry-http/src/lib.rs b/opentelemetry-http/src/lib.rs index 778f8aee98..f272d8d4c5 100644 --- a/opentelemetry-http/src/lib.rs +++ b/opentelemetry-http/src/lib.rs @@ -66,11 +66,14 @@ pub trait HttpClient: Debug + Send + Sync { #[cfg(feature = "reqwest")] mod reqwest { + use opentelemetry::otel_debug; + use super::{async_trait, Bytes, HttpClient, HttpError, Request, Response}; #[async_trait] impl HttpClient for reqwest::Client { async fn send(&self, request: Request>) -> Result, HttpError> { + otel_debug!(name: "ReqwestClient.Send"); let request = request.try_into()?; let mut response = self.execute(request).await?.error_for_status()?; let headers = std::mem::take(response.headers_mut()); @@ -87,6 +90,7 @@ mod reqwest { #[async_trait] impl HttpClient for reqwest::blocking::Client { async fn send(&self, request: Request>) -> Result, HttpError> { + otel_debug!(name: "ReqwestBlockingClient.Send"); let request = request.try_into()?; let mut response = self.execute(request)?.error_for_status()?; let headers = std::mem::take(response.headers_mut()); @@ -102,9 +106,8 @@ mod reqwest { #[cfg(feature = "hyper")] pub mod hyper { - use crate::ResponseExt; - use super::{async_trait, Bytes, HttpClient, HttpError, Request, Response}; + use crate::ResponseExt; use http::HeaderValue; use http_body_util::{BodyExt, Full}; use hyper::body::{Body as HttpBody, Frame}; @@ -112,6 +115,7 @@ pub mod hyper { connect::{Connect, HttpConnector}, Client, }; + use opentelemetry::otel_debug; use std::fmt::Debug; use std::pin::Pin; use std::task::{self, Poll}; @@ -156,6 +160,7 @@ pub mod hyper { #[async_trait] impl HttpClient for HyperClient { async fn send(&self, request: Request>) -> Result, HttpError> { + otel_debug!(name: "HyperClient.Send"); let (parts, body) = request.into_parts(); let mut request = Request::from_parts(parts, Body(Full::from(body))); if let Some(ref authorization) = self.authorization { diff --git a/opentelemetry-otlp/Cargo.toml b/opentelemetry-otlp/Cargo.toml index 9526b63589..0f4599fc03 100644 --- a/opentelemetry-otlp/Cargo.toml +++ b/opentelemetry-otlp/Cargo.toml @@ -58,7 +58,7 @@ trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "opentelemetry-proto/ metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics", "opentelemetry-proto/metrics"] logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "opentelemetry-proto/logs"] populate-logs-event-name = ["opentelemetry-proto/populate-logs-event-name"] -internal-logs = ["tracing"] +internal-logs = ["tracing", "opentelemetry/internal-logs"] # add ons serialize = ["serde", "serde_json"] diff --git a/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml b/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml index 0c0c099024..c56c5502c3 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml +++ b/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml @@ -16,7 +16,7 @@ experimental_metrics_periodicreader_with_async_runtime = ["opentelemetry_sdk/exp once_cell = { workspace = true } opentelemetry = { path = "../../../opentelemetry" } opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "experimental_metrics_periodicreader_with_async_runtime"]} -opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs"] , default-features = false} +opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs", "internal-logs"] , default-features = false} opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false} tokio = { workspace = true, features = ["full"] } diff --git a/opentelemetry-otlp/src/exporter/http/logs.rs b/opentelemetry-otlp/src/exporter/http/logs.rs index 24bb667129..905fb638d0 100644 --- a/opentelemetry-otlp/src/exporter/http/logs.rs +++ b/opentelemetry-otlp/src/exporter/http/logs.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use async_trait::async_trait; use http::{header::CONTENT_TYPE, Method}; +use opentelemetry::otel_debug; use opentelemetry_sdk::export::logs::{LogBatch, LogExporter}; use opentelemetry_sdk::logs::{LogError, LogResult}; @@ -32,6 +33,7 @@ impl LogExporter for OtlpHttpClient { } let request_uri = request.uri().to_string(); + otel_debug!(name: "HttpLogsClient.CallingExport"); let response = client.send(request).await?; if !response.status().is_success() { diff --git a/opentelemetry-otlp/src/exporter/http/metrics.rs b/opentelemetry-otlp/src/exporter/http/metrics.rs index 5ba84b30e6..7b96a7c5ce 100644 --- a/opentelemetry-otlp/src/exporter/http/metrics.rs +++ b/opentelemetry-otlp/src/exporter/http/metrics.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use async_trait::async_trait; use http::{header::CONTENT_TYPE, Method}; +use opentelemetry::otel_debug; use opentelemetry_sdk::metrics::data::ResourceMetrics; use opentelemetry_sdk::metrics::{MetricError, MetricResult}; @@ -33,6 +34,7 @@ impl MetricsClient for OtlpHttpClient { request.headers_mut().insert(k.clone(), v.clone()); } + otel_debug!(name: "HttpMetricsClient.CallingExport"); client .send(request) .await diff --git a/opentelemetry-otlp/src/exporter/http/trace.rs b/opentelemetry-otlp/src/exporter/http/trace.rs index cc7894c266..d188dc8911 100644 --- a/opentelemetry-otlp/src/exporter/http/trace.rs +++ b/opentelemetry-otlp/src/exporter/http/trace.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use futures_core::future::BoxFuture; use http::{header::CONTENT_TYPE, Method}; -use opentelemetry::trace::TraceError; +use opentelemetry::{otel_debug, trace::TraceError}; use opentelemetry_sdk::export::trace::{ExportResult, SpanData, SpanExporter}; use super::OtlpHttpClient; @@ -47,6 +47,7 @@ impl SpanExporter for OtlpHttpClient { Box::pin(async move { let request_uri = request.uri().to_string(); + otel_debug!(name: "HttpTracesClient.CallingExport"); let response = client.send(request).await?; if !response.status().is_success() {