Skip to content
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: 2 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## vNext

- Add HTTP compression support with `gzip-http` and `zstd-http` feature flags

## 0.30.0

Released 2025-May-23
Expand Down
9 changes: 9 additions & 0 deletions opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ serde = { workspace = true, features = ["derive"], optional = true }
thiserror = { workspace = true }
serde_json = { workspace = true, optional = true }

# compression dependencies
flate2 = { version = "1.1.2", optional = true }
zstd = { version = "0.13", optional = true }

[dev-dependencies]
tokio-stream = { workspace = true, features = ["net"] }
opentelemetry_sdk = { features = ["trace", "testing"], path = "../opentelemetry-sdk" }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
futures-util = { workspace = true }
temp-env = { workspace = true }
tonic = { workspace = true, features = ["router", "server"] }
async-trait = { workspace = true }

[features]
# telemetry pillars and functions
Expand All @@ -67,6 +72,10 @@ default = ["http-proto", "reqwest-blocking-client", "trace", "metrics", "logs",
grpc-tonic = ["tonic", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic"]
gzip-tonic = ["tonic/gzip"]
zstd-tonic = ["tonic/zstd"]

# http compression
gzip-http = ["flate2"]
zstd-http = ["zstd"]
tls = ["tonic/tls-ring"]
tls-roots = ["tls", "tonic/tls-native-roots"]
tls-webpki-roots = ["tls", "tonic/tls-webpki-roots"]
Expand Down
13 changes: 10 additions & 3 deletions opentelemetry-otlp/src/exporter/http/logs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::OtlpHttpClient;
use http::header::CONTENT_ENCODING;
use http::{header::CONTENT_TYPE, Method};
use opentelemetry::otel_debug;
use opentelemetry_sdk::error::{OTelSdkError, OTelSdkResult};
Expand All @@ -14,14 +15,20 @@ impl LogExporter for OtlpHttpClient {
.clone()
.ok_or(OTelSdkError::AlreadyShutdown)?;

let (body, content_type) = self
let (body, content_type, content_encoding) = self
.build_logs_export_body(batch)
.map_err(OTelSdkError::InternalFailure)?;

let mut request = http::Request::builder()
let mut request_builder = http::Request::builder()
.method(Method::POST)
.uri(&self.collector_endpoint)
.header(CONTENT_TYPE, content_type)
.header(CONTENT_TYPE, content_type);

if let Some(encoding) = content_encoding {
request_builder = request_builder.header(CONTENT_ENCODING, encoding);
}

let mut request = request_builder
.body(body.into())
.map_err(|e| OTelSdkError::InternalFailure(e.to_string()))?;

Expand Down
18 changes: 13 additions & 5 deletions opentelemetry-otlp/src/exporter/http/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ impl MetricsClient for OtlpHttpClient {
_ => Err(OTelSdkError::AlreadyShutdown),
})?;

let (body, content_type) = self.build_metrics_export_body(metrics).ok_or_else(|| {
OTelSdkError::InternalFailure("Failed to serialize metrics".to_string())
})?;
let mut request = http::Request::builder()
let (body, content_type, content_encoding) =
self.build_metrics_export_body(metrics).ok_or_else(|| {
OTelSdkError::InternalFailure("Failed to serialize metrics".to_string())
})?;

let mut request_builder = http::Request::builder()
.method(Method::POST)
.uri(&self.collector_endpoint)
.header(CONTENT_TYPE, content_type)
.header(CONTENT_TYPE, content_type);

if let Some(encoding) = content_encoding {
request_builder = request_builder.header("Content-Encoding", encoding);
}

let mut request = request_builder
.body(body.into())
.map_err(|e| OTelSdkError::InternalFailure(format!("{e:?}")))?;

Expand Down
Loading
Loading