Skip to content

Commit dba1820

Browse files
feat: Cleanup OTLP Exporter public API (#3384)
Co-authored-by: Scott Gerring <scottgerring@users.noreply.github.com>
1 parent 09b85b5 commit dba1820

8 files changed

Lines changed: 27 additions & 50 deletions

File tree

opentelemetry-otlp/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## vNext
44

5+
- **Breaking** Removed `ExportConfig`, `HasExportConfig`, and `with_export_config()` from public API.
6+
Use the `WithExportConfig` trait
7+
methods (`.with_endpoint()`, `.with_protocol()`, `.with_timeout()`) instead, which remain public.
58
- Add support for `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` environment variable
69
to configure metrics temporality. Accepted values: `cumulative` (default), `delta`,
710
`lowmemory` (case-insensitive). Programmatic `.with_temporality()` overrides the env var.

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use super::{
22
default_headers, parse_header_string, resolve_timeout, ExporterBuildError,
33
OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT,
44
};
5-
use crate::{ExportConfig, Protocol, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS};
5+
use crate::{
6+
exporter::ExportConfig, Protocol, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS,
7+
};
68
use http::{HeaderName, HeaderValue, Uri};
79
use opentelemetry::otel_debug;
810
use opentelemetry_http::{Bytes, HttpClient};
@@ -1042,7 +1044,7 @@ mod tests {
10421044
#[cfg(feature = "experimental-http-retry")]
10431045
retry_policy: None,
10441046
},
1045-
exporter_config: crate::ExportConfig::default(),
1047+
exporter_config: crate::exporter::ExportConfig::default(),
10461048
};
10471049

10481050
// Act

opentelemetry-otlp/src/exporter/mod.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) mod tonic;
5353

5454
/// Configuration for the OTLP exporter.
5555
#[derive(Debug)]
56-
pub struct ExportConfig {
56+
pub(crate) struct ExportConfig {
5757
/// The address of the OTLP collector.
5858
/// Default address will be used based on the protocol.
5959
///
@@ -228,7 +228,7 @@ fn default_headers() -> std::collections::HashMap<String, String> {
228228
}
229229

230230
/// Provide access to the [ExportConfig] field within the exporter builders.
231-
pub trait HasExportConfig {
231+
pub(crate) trait HasExportConfig {
232232
/// Return a mutable reference to the [ExportConfig] within the exporter builders.
233233
fn export_config(&mut self) -> &mut ExportConfig;
234234
}
@@ -249,9 +249,7 @@ impl HasExportConfig for HttpExporterBuilder {
249249
}
250250
}
251251

252-
/// Expose methods to override [ExportConfig].
253-
///
254-
/// This trait will be implemented for every struct that implemented [`HasExportConfig`] trait.
252+
/// Expose methods to set export configuration on exporter builders.
255253
///
256254
/// ## Examples
257255
/// ```
@@ -280,10 +278,6 @@ pub trait WithExportConfig {
280278
///
281279
/// Note: Programmatically setting this will override any value set via the environment variable.
282280
fn with_timeout(self, timeout: Duration) -> Self;
283-
/// Set export config. This will override all previous configurations.
284-
///
285-
/// Note: Programmatically setting this will override any value set via environment variables.
286-
fn with_export_config(self, export_config: ExportConfig) -> Self;
287281
}
288282

289283
impl<B: HasExportConfig> WithExportConfig for B {
@@ -301,13 +295,6 @@ impl<B: HasExportConfig> WithExportConfig for B {
301295
self.export_config().timeout = Some(timeout);
302296
self
303297
}
304-
305-
fn with_export_config(mut self, exporter_config: ExportConfig) -> Self {
306-
self.export_config().endpoint = exporter_config.endpoint;
307-
self.export_config().protocol = exporter_config.protocol;
308-
self.export_config().timeout = exporter_config.timeout;
309-
self
310-
}
311298
}
312299

313300
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
@@ -413,19 +400,12 @@ mod tests {
413400
#[cfg(any(feature = "http-proto", feature = "http-json"))]
414401
#[test]
415402
fn export_builder_error_invalid_http_endpoint() {
416-
use std::time::Duration;
417-
418-
use crate::{ExportConfig, LogExporter, Protocol, WithExportConfig};
419-
420-
let ex_config = ExportConfig {
421-
endpoint: Some("invalid_uri/something".to_string()),
422-
protocol: Protocol::HttpBinary,
423-
timeout: Some(Duration::from_secs(10)),
424-
};
403+
use crate::{LogExporter, WithExportConfig};
425404

426405
let exporter_result = LogExporter::builder()
427406
.with_http()
428-
.with_export_config(ex_config)
407+
.with_endpoint("invalid_uri/something")
408+
.with_timeout(std::time::Duration::from_secs(10))
429409
.build();
430410

431411
assert!(
@@ -440,19 +420,12 @@ mod tests {
440420
#[cfg(feature = "grpc-tonic")]
441421
#[tokio::test]
442422
async fn export_builder_error_invalid_grpc_endpoint() {
443-
use std::time::Duration;
444-
445-
use crate::{ExportConfig, LogExporter, Protocol, WithExportConfig};
446-
447-
let ex_config = ExportConfig {
448-
endpoint: Some("invalid_uri/something".to_string()),
449-
protocol: Protocol::Grpc,
450-
timeout: Some(Duration::from_secs(10)),
451-
};
423+
use crate::{LogExporter, WithExportConfig};
452424

453425
let exporter_result = LogExporter::builder()
454426
.with_tonic()
455-
.with_export_config(ex_config)
427+
.with_endpoint("invalid_uri/something")
428+
.with_timeout(std::time::Duration::from_secs(10))
456429
.build();
457430

458431
assert!(matches!(

opentelemetry-otlp/src/exporter/tonic/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tonic::transport::ClientTlsConfig;
1414
use super::{default_headers, parse_header_string, OTEL_EXPORTER_OTLP_GRPC_ENDPOINT_DEFAULT};
1515
use super::{resolve_timeout, ExporterBuildError};
1616
use crate::exporter::Compression;
17-
use crate::{ExportConfig, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS};
17+
use crate::{exporter::ExportConfig, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS};
1818

1919
#[cfg(all(
2020
feature = "experimental-grpc-retry",
@@ -502,7 +502,7 @@ pub trait WithTonicConfig {
502502
/// this will override tls config and should only be used
503503
/// when working with non-HTTP transports.
504504
///
505-
/// Users MUST make sure the [`ExportConfig::timeout`] is
505+
/// Users MUST make sure the timeout is
506506
/// the same as the channel's timeout.
507507
fn with_channel(self, channel: tonic::transport::Channel) -> Self;
508508

opentelemetry-otlp/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ pub mod retry_classification;
424424
pub mod retry;
425425

426426
pub use crate::exporter::Compression;
427-
pub use crate::exporter::ExportConfig;
428427
pub use crate::exporter::ExporterBuildError;
429428
#[cfg(feature = "trace")]
430429
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
@@ -457,7 +456,7 @@ pub use crate::exporter::http::{HasHttpConfig, WithHttpConfig};
457456
pub use crate::exporter::tonic::{HasTonicConfig, WithTonicConfig};
458457

459458
pub use crate::exporter::{
460-
HasExportConfig, WithExportConfig, OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_ENDPOINT,
459+
WithExportConfig, OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_ENDPOINT,
461460
OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_PROTOCOL,
462461
OTEL_EXPORTER_OTLP_PROTOCOL_GRPC, OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_JSON,
463462
OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF, OTEL_EXPORTER_OTLP_TIMEOUT,

opentelemetry-otlp/src/logs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use opentelemetry_sdk::{error::OTelSdkResult, logs::LogBatch};
88
use std::fmt::Debug;
99
use std::time;
1010

11-
use crate::{ExporterBuildError, HasExportConfig, NoExporterBuilderSet};
11+
use crate::{exporter::HasExportConfig, ExporterBuildError, NoExporterBuilderSet};
1212

1313
#[cfg(feature = "grpc-tonic")]
1414
use crate::{HasTonicConfig, TonicExporterBuilder, TonicExporterBuilderSet};
@@ -83,14 +83,14 @@ impl LogExporterBuilder<HttpExporterBuilderSet> {
8383

8484
#[cfg(feature = "grpc-tonic")]
8585
impl HasExportConfig for LogExporterBuilder<TonicExporterBuilderSet> {
86-
fn export_config(&mut self) -> &mut crate::ExportConfig {
86+
fn export_config(&mut self) -> &mut crate::exporter::ExportConfig {
8787
&mut self.client.0.exporter_config
8888
}
8989
}
9090

9191
#[cfg(any(feature = "http-proto", feature = "http-json"))]
9292
impl HasExportConfig for LogExporterBuilder<HttpExporterBuilderSet> {
93-
fn export_config(&mut self) -> &mut crate::ExportConfig {
93+
fn export_config(&mut self) -> &mut crate::exporter::ExportConfig {
9494
&mut self.client.0.exporter_config
9595
}
9696
}

opentelemetry-otlp/src/metric.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
66
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
7-
use crate::HasExportConfig;
7+
use crate::exporter::HasExportConfig;
88

99
#[cfg(any(feature = "http-proto", feature = "http-json"))]
1010
use crate::{exporter::http::HttpExporterBuilder, HasHttpConfig, HttpExporterBuilderSet};
@@ -127,14 +127,14 @@ impl MetricExporterBuilder<HttpExporterBuilderSet> {
127127

128128
#[cfg(feature = "grpc-tonic")]
129129
impl HasExportConfig for MetricExporterBuilder<TonicExporterBuilderSet> {
130-
fn export_config(&mut self) -> &mut crate::ExportConfig {
130+
fn export_config(&mut self) -> &mut crate::exporter::ExportConfig {
131131
&mut self.client.0.exporter_config
132132
}
133133
}
134134

135135
#[cfg(any(feature = "http-proto", feature = "http-json"))]
136136
impl HasExportConfig for MetricExporterBuilder<HttpExporterBuilderSet> {
137-
fn export_config(&mut self) -> &mut crate::ExportConfig {
137+
fn export_config(&mut self) -> &mut crate::exporter::ExportConfig {
138138
&mut self.client.0.exporter_config
139139
}
140140
}

opentelemetry-otlp/src/span.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ impl SpanExporterBuilder<HttpExporterBuilderSet> {
8686

8787
#[cfg(feature = "grpc-tonic")]
8888
impl HasExportConfig for SpanExporterBuilder<TonicExporterBuilderSet> {
89-
fn export_config(&mut self) -> &mut crate::ExportConfig {
89+
fn export_config(&mut self) -> &mut crate::exporter::ExportConfig {
9090
&mut self.client.0.exporter_config
9191
}
9292
}
9393

9494
#[cfg(any(feature = "http-proto", feature = "http-json"))]
9595
impl HasExportConfig for SpanExporterBuilder<HttpExporterBuilderSet> {
96-
fn export_config(&mut self) -> &mut crate::ExportConfig {
96+
fn export_config(&mut self) -> &mut crate::exporter::ExportConfig {
9797
&mut self.client.0.exporter_config
9898
}
9999
}

0 commit comments

Comments
 (0)