Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal logging to HTTP libraries #2452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion opentelemetry-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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}
9 changes: 7 additions & 2 deletions opentelemetry-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@

#[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<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
otel_debug!(name: "ReqwestClient.Send");

Check warning on line 76 in opentelemetry-http/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-http/src/lib.rs#L76

Added line #L76 was not covered by tests
let request = request.try_into()?;
let mut response = self.execute(request).await?.error_for_status()?;
let headers = std::mem::take(response.headers_mut());
Expand All @@ -87,6 +90,7 @@
#[async_trait]
impl HttpClient for reqwest::blocking::Client {
async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
otel_debug!(name: "ReqwestBlockingClient.Send");

Check warning on line 93 in opentelemetry-http/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-http/src/lib.rs#L93

Added line #L93 was not covered by tests
let request = request.try_into()?;
let mut response = self.execute(request)?.error_for_status()?;
let headers = std::mem::take(response.headers_mut());
Expand All @@ -102,16 +106,16 @@

#[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};
use hyper_util::client::legacy::{
connect::{Connect, HttpConnector},
Client,
};
use opentelemetry::otel_debug;
use std::fmt::Debug;
use std::pin::Pin;
use std::task::{self, Poll};
Expand Down Expand Up @@ -156,6 +160,7 @@
#[async_trait]
impl HttpClient for HyperClient {
async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
otel_debug!(name: "HyperClient.Send");

Check warning on line 163 in opentelemetry-http/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-http/src/lib.rs#L163

Added line #L163 was not covered by tests
let (parts, body) = request.into_parts();
let mut request = Request::from_parts(parts, Body(Full::from(body)));
if let Some(ref authorization) = self.authorization {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/src/exporter/http/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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};

Expand Down Expand Up @@ -32,7 +33,8 @@
}

let request_uri = request.uri().to_string();
otel_debug!(name: "HttpLogsClient.CallingExport");
let response = client.send(request).await?;

Check warning on line 37 in opentelemetry-otlp/src/exporter/http/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/exporter/http/logs.rs#L36-L37

Added lines #L36 - L37 were not covered by tests

if !response.status().is_success() {
let error = format!(
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/src/exporter/http/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-otlp/src/exporter/http/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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;
Expand Down Expand Up @@ -47,6 +47,7 @@

Box::pin(async move {
let request_uri = request.uri().to_string();
otel_debug!(name: "HttpTracesClient.CallingExport");

Check warning on line 50 in opentelemetry-otlp/src/exporter/http/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/exporter/http/trace.rs#L50

Added line #L50 was not covered by tests
let response = client.send(request).await?;

if !response.status().is_success() {
Expand Down
Loading