Skip to content

Commit 693765b

Browse files
committed
chore: modify tonic exporters so we don't _need_ the async runtime if we don't want retry
1 parent 4ae557e commit 693765b

File tree

7 files changed

+152
-63
lines changed

7 files changed

+152
-63
lines changed

opentelemetry-otlp/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ serialize = ["serde", "serde_json"]
7070
default = ["http-proto", "reqwest-blocking-client", "trace", "metrics", "logs", "internal-logs"]
7171

7272
# grpc using tonic
73-
grpc-tonic = ["tonic", "tonic-types", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic", "opentelemetry_sdk/rt-tokio", "opentelemetry_sdk/experimental_async_runtime"]
73+
grpc-tonic = ["tonic", "tonic-types", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic"]
7474
gzip-tonic = ["tonic/gzip"]
7575
zstd-tonic = ["tonic/zstd"]
7676

77+
# grpc with retry support
78+
experimental-grpc-retry = ["grpc-tonic", "opentelemetry_sdk/experimental_async_runtime", "opentelemetry_sdk/rt-tokio"]
79+
7780
# http compression
7881
gzip-http = ["flate2"]
7982
zstd-http = ["zstd"]
@@ -85,8 +88,7 @@ tls-webpki-roots = ["tls", "tonic/tls-webpki-roots"]
8588
http-proto = ["prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "http", "trace", "metrics"]
8689

8790
# http with retry support.
88-
# What should we do with this? We need the async_runtime. gRPC exporters already need it.
89-
http-retry = ["opentelemetry_sdk/experimental_async_runtime", "opentelemetry_sdk/rt-tokio", "tokio"]
91+
experimental-http-retry = ["opentelemetry_sdk/experimental_async_runtime", "opentelemetry_sdk/rt-tokio", "tokio"]
9092

9193
http-json = ["serde_json", "prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "opentelemetry-proto/with-serde", "http", "trace", "metrics"]
9294
reqwest-blocking-client = ["reqwest/blocking", "opentelemetry-http/reqwest-blocking"]

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ use std::str::FromStr;
2222
use std::sync::{Arc, Mutex};
2323
use std::time::Duration;
2424

25-
#[cfg(feature = "http-retry")]
25+
#[cfg(feature = "experimental-http-retry")]
2626
use crate::retry_classification::http::classify_http_error;
27-
#[cfg(feature = "http-retry")]
27+
#[cfg(feature = "experimental-http-retry")]
2828
use opentelemetry_sdk::retry::{RetryErrorType, RetryPolicy};
2929

3030
// Shared HTTP retry functionality
3131
/// HTTP-specific error wrapper for retry classification
3232
#[derive(Debug)]
3333
pub(crate) struct HttpExportError {
34-
#[cfg(feature = "http-retry")]
34+
#[cfg(feature = "experimental-http-retry")]
3535
pub status_code: u16,
36-
#[cfg(feature = "http-retry")]
36+
#[cfg(feature = "experimental-http-retry")]
3737
pub retry_after: Option<String>,
3838
pub message: String,
3939
}
@@ -42,9 +42,9 @@ impl HttpExportError {
4242
/// Create a new HttpExportError without retry-after header
4343
pub(crate) fn new(_status_code: u16, message: String) -> Self {
4444
Self {
45-
#[cfg(feature = "http-retry")]
45+
#[cfg(feature = "experimental-http-retry")]
4646
status_code: _status_code,
47-
#[cfg(feature = "http-retry")]
47+
#[cfg(feature = "experimental-http-retry")]
4848
retry_after: None,
4949
message,
5050
}
@@ -57,16 +57,16 @@ impl HttpExportError {
5757
message: String,
5858
) -> Self {
5959
Self {
60-
#[cfg(feature = "http-retry")]
60+
#[cfg(feature = "experimental-http-retry")]
6161
status_code: _status_code,
62-
#[cfg(feature = "http-retry")]
62+
#[cfg(feature = "experimental-http-retry")]
6363
retry_after: Some(_retry_after),
6464
message,
6565
}
6666
}
6767
}
6868

69-
#[cfg(feature = "http-retry")]
69+
#[cfg(feature = "experimental-http-retry")]
7070
/// Classify HTTP export errors for retry decisions
7171
pub(crate) fn classify_http_export_error(error: &HttpExportError) -> RetryErrorType {
7272
classify_http_error(error.status_code, error.retry_after.as_deref())
@@ -113,7 +113,7 @@ pub struct HttpConfig {
113113
compression: Option<crate::Compression>,
114114

115115
/// The retry policy to use for HTTP requests.
116-
#[cfg(feature = "http-retry")]
116+
#[cfg(feature = "experimental-http-retry")]
117117
retry_policy: Option<RetryPolicy>,
118118
}
119119

@@ -286,7 +286,7 @@ impl HttpExporterBuilder {
286286
self.exporter_config.protocol,
287287
timeout,
288288
compression,
289-
#[cfg(feature = "http-retry")]
289+
#[cfg(feature = "experimental-http-retry")]
290290
self.http_config.retry_policy.take(),
291291
))
292292
}
@@ -367,7 +367,7 @@ pub(crate) struct OtlpHttpClient {
367367
protocol: Protocol,
368368
_timeout: Duration,
369369
compression: Option<crate::Compression>,
370-
#[cfg(feature = "http-retry")]
370+
#[cfg(feature = "experimental-http-retry")]
371371
retry_policy: RetryPolicy,
372372
#[allow(dead_code)]
373373
// <allow dead> would be removed once we support set_resource for metrics and traces.
@@ -385,7 +385,7 @@ impl OtlpHttpClient {
385385
where
386386
F: Fn(&Self, T) -> Result<(Vec<u8>, &'static str, Option<&'static str>), String>,
387387
{
388-
#[cfg(feature = "http-retry")]
388+
#[cfg(feature = "experimental-http-retry")]
389389
{
390390
use opentelemetry_sdk::retry::retry_with_backoff;
391391
use opentelemetry_sdk::runtime::Tokio;
@@ -419,7 +419,7 @@ impl OtlpHttpClient {
419419
.map_err(|e| opentelemetry_sdk::error::OTelSdkError::InternalFailure(e.message))
420420
}
421421

422-
#[cfg(not(feature = "http-retry"))]
422+
#[cfg(not(feature = "experimental-http-retry"))]
423423
{
424424
let (body, content_type, content_encoding) = build_body_fn(self, data)
425425
.map_err(opentelemetry_sdk::error::OTelSdkError::InternalFailure)?;
@@ -545,7 +545,7 @@ impl OtlpHttpClient {
545545
protocol: Protocol,
546546
timeout: Duration,
547547
compression: Option<crate::Compression>,
548-
#[cfg(feature = "http-retry")] retry_policy: Option<RetryPolicy>,
548+
#[cfg(feature = "experimental-http-retry")] retry_policy: Option<RetryPolicy>,
549549
) -> Self {
550550
OtlpHttpClient {
551551
client: Mutex::new(Some(client)),
@@ -554,7 +554,7 @@ impl OtlpHttpClient {
554554
protocol,
555555
_timeout: timeout,
556556
compression,
557-
#[cfg(feature = "http-retry")]
557+
#[cfg(feature = "experimental-http-retry")]
558558
retry_policy: retry_policy.unwrap_or(RetryPolicy {
559559
max_retries: 3,
560560
initial_delay_ms: 100,
@@ -733,7 +733,7 @@ pub trait WithHttpConfig {
733733
fn with_compression(self, compression: crate::Compression) -> Self;
734734

735735
/// Set the retry policy for HTTP requests.
736-
#[cfg(feature = "http-retry")]
736+
#[cfg(feature = "experimental-http-retry")]
737737
fn with_retry_policy(self, policy: RetryPolicy) -> Self;
738738
}
739739

@@ -760,7 +760,7 @@ impl<B: HasHttpConfig> WithHttpConfig for B {
760760
self
761761
}
762762

763-
#[cfg(feature = "http-retry")]
763+
#[cfg(feature = "experimental-http-retry")]
764764
fn with_retry_policy(mut self, policy: RetryPolicy) -> Self {
765765
self.http_client_config().retry_policy = Some(policy);
766766
self
@@ -1010,7 +1010,7 @@ mod tests {
10101010
client: None,
10111011
headers: Some(initial_headers),
10121012
compression: None,
1013-
#[cfg(feature = "http-retry")]
1013+
#[cfg(feature = "experimental-http-retry")]
10141014
retry_policy: None,
10151015
},
10161016
exporter_config: crate::ExportConfig::default(),
@@ -1078,7 +1078,7 @@ mod tests {
10781078
crate::Protocol::HttpBinary,
10791079
std::time::Duration::from_secs(10),
10801080
Some(crate::Compression::Gzip),
1081-
#[cfg(feature = "http-retry")]
1081+
#[cfg(feature = "experimental-http-retry")]
10821082
None,
10831083
);
10841084

@@ -1111,7 +1111,7 @@ mod tests {
11111111
crate::Protocol::HttpBinary,
11121112
std::time::Duration::from_secs(10),
11131113
Some(crate::Compression::Zstd),
1114-
#[cfg(feature = "http-retry")]
1114+
#[cfg(feature = "experimental-http-retry")]
11151115
None,
11161116
);
11171117

@@ -1141,7 +1141,7 @@ mod tests {
11411141
crate::Protocol::HttpBinary,
11421142
std::time::Duration::from_secs(10),
11431143
None, // No compression
1144-
#[cfg(feature = "http-retry")]
1144+
#[cfg(feature = "experimental-http-retry")]
11451145
None,
11461146
);
11471147

@@ -1164,7 +1164,7 @@ mod tests {
11641164
crate::Protocol::HttpBinary,
11651165
std::time::Duration::from_secs(10),
11661166
Some(crate::Compression::Gzip),
1167-
#[cfg(feature = "http-retry")]
1167+
#[cfg(feature = "experimental-http-retry")]
11681168
None,
11691169
);
11701170

@@ -1188,7 +1188,7 @@ mod tests {
11881188
crate::Protocol::HttpBinary,
11891189
std::time::Duration::from_secs(10),
11901190
Some(crate::Compression::Zstd),
1191-
#[cfg(feature = "http-retry")]
1191+
#[cfg(feature = "experimental-http-retry")]
11921192
None,
11931193
);
11941194

@@ -1252,7 +1252,7 @@ mod tests {
12521252
protocol,
12531253
std::time::Duration::from_secs(10),
12541254
compression,
1255-
#[cfg(feature = "http-retry")]
1255+
#[cfg(feature = "experimental-http-retry")]
12561256
None,
12571257
)
12581258
}
@@ -1487,7 +1487,7 @@ mod tests {
14871487
));
14881488
}
14891489

1490-
#[cfg(feature = "http-retry")]
1490+
#[cfg(feature = "experimental-http-retry")]
14911491
#[test]
14921492
fn test_with_retry_policy() {
14931493
use super::super::HttpExporterBuilder;
@@ -1511,23 +1511,23 @@ mod tests {
15111511
assert_eq!(retry_policy.jitter_ms, 50);
15121512
}
15131513

1514-
#[cfg(feature = "http-retry")]
1514+
#[cfg(feature = "experimental-http-retry")]
15151515
#[test]
15161516
fn test_default_retry_policy_when_none_configured() {
15171517
let client = create_test_client(crate::Protocol::HttpBinary, None);
1518-
1518+
15191519
// Verify default values are used
15201520
assert_eq!(client.retry_policy.max_retries, 3);
15211521
assert_eq!(client.retry_policy.initial_delay_ms, 100);
15221522
assert_eq!(client.retry_policy.max_delay_ms, 1600);
15231523
assert_eq!(client.retry_policy.jitter_ms, 100);
15241524
}
15251525

1526-
#[cfg(feature = "http-retry")]
1526+
#[cfg(feature = "experimental-http-retry")]
15271527
#[test]
15281528
fn test_custom_retry_policy_used() {
15291529
use opentelemetry_sdk::retry::RetryPolicy;
1530-
1530+
15311531
let custom_policy = RetryPolicy {
15321532
max_retries: 7,
15331533
initial_delay_ms: 500,
@@ -1544,7 +1544,7 @@ mod tests {
15441544
None,
15451545
Some(custom_policy),
15461546
);
1547-
1547+
15481548
// Verify custom values are used
15491549
assert_eq!(client.retry_policy.max_retries, 7);
15501550
assert_eq!(client.retry_policy.initial_delay_ms, 500);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use opentelemetry_proto::transform::logs::tonic::group_logs_by_resource_and_scop
1414

1515
use super::BoxInterceptor;
1616

17-
use crate::retry_classification::grpc::classify_tonic_status;
18-
use opentelemetry_sdk::retry::{retry_with_backoff, RetryPolicy};
17+
use opentelemetry_sdk::retry::RetryPolicy;
18+
#[cfg(feature = "experimental-grpc-retry")]
1919
use opentelemetry_sdk::runtime::Tokio;
2020

2121
pub(crate) struct TonicLogsClient {
@@ -73,10 +73,13 @@ impl LogExporter for TonicLogsClient {
7373
async fn export(&self, batch: LogBatch<'_>) -> OTelSdkResult {
7474
let batch = Arc::new(batch);
7575

76-
match retry_with_backoff(
76+
match super::tonic_retry_with_backoff(
77+
#[cfg(feature = "experimental-grpc-retry")]
7778
Tokio,
79+
#[cfg(not(feature = "experimental-grpc-retry"))]
80+
(),
7881
self.retry_policy.clone(),
79-
classify_tonic_status,
82+
crate::retry_classification::grpc::classify_tonic_status,
8083
"TonicLogsClient.Export",
8184
|| async {
8285
let batch_clone = Arc::clone(&batch);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Chann
1212
use super::BoxInterceptor;
1313
use crate::metric::MetricsClient;
1414

15-
use crate::retry_classification::grpc::classify_tonic_status;
16-
use opentelemetry_sdk::retry::{retry_with_backoff, RetryPolicy};
15+
use opentelemetry_sdk::retry::RetryPolicy;
16+
#[cfg(feature = "experimental-grpc-retry")]
1717
use opentelemetry_sdk::runtime::Tokio;
1818

1919
pub(crate) struct TonicMetricsClient {
@@ -65,10 +65,13 @@ impl TonicMetricsClient {
6565

6666
impl MetricsClient for TonicMetricsClient {
6767
async fn export(&self, metrics: &ResourceMetrics) -> OTelSdkResult {
68-
match retry_with_backoff(
68+
match super::tonic_retry_with_backoff(
69+
#[cfg(feature = "experimental-grpc-retry")]
6970
Tokio,
71+
#[cfg(not(feature = "experimental-grpc-retry"))]
72+
(),
7073
self.retry_policy.clone(),
71-
classify_tonic_status,
74+
crate::retry_classification::grpc::classify_tonic_status,
7275
"TonicMetricsClient.Export",
7376
|| async {
7477
// Execute the export operation

0 commit comments

Comments
 (0)