Skip to content

Commit 8d9d8f2

Browse files
committed
chore: move retry from sdk down to otlp for now
1 parent ca1bf18 commit 8d9d8f2

File tree

9 files changed

+35
-29
lines changed

9 files changed

+35
-29
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::time::Duration;
2525
#[cfg(feature = "experimental-http-retry")]
2626
use crate::retry_classification::http::classify_http_error;
2727
#[cfg(feature = "experimental-http-retry")]
28-
use opentelemetry_sdk::retry::{RetryErrorType, RetryPolicy};
28+
use crate::retry::{RetryErrorType, RetryPolicy};
2929

3030
// Shared HTTP retry functionality
3131
/// HTTP-specific error wrapper for retry classification
@@ -387,7 +387,7 @@ impl OtlpHttpClient {
387387
{
388388
#[cfg(feature = "experimental-http-retry")]
389389
{
390-
use opentelemetry_sdk::retry::retry_with_backoff;
390+
use crate::retry::retry_with_backoff;
391391
use opentelemetry_sdk::runtime::Tokio;
392392

393393
// Build request body once before retry loop
@@ -1493,7 +1493,7 @@ mod tests {
14931493
fn test_with_retry_policy() {
14941494
use super::super::HttpExporterBuilder;
14951495
use crate::WithHttpConfig;
1496-
use opentelemetry_sdk::retry::RetryPolicy;
1496+
use crate::retry::RetryPolicy;
14971497

14981498
let custom_policy = RetryPolicy {
14991499
max_retries: 5,
@@ -1527,7 +1527,7 @@ mod tests {
15271527
#[cfg(feature = "experimental-http-retry")]
15281528
#[test]
15291529
fn test_custom_retry_policy_used() {
1530-
use opentelemetry_sdk::retry::RetryPolicy;
1530+
use crate::retry::RetryPolicy;
15311531

15321532
let custom_policy = RetryPolicy {
15331533
max_retries: 7,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use opentelemetry_proto::transform::logs::tonic::group_logs_by_resource_and_scop
1414

1515
use super::BoxInterceptor;
1616

17-
use opentelemetry_sdk::retry::RetryPolicy;
17+
use crate::retry::RetryPolicy;
1818
#[cfg(feature = "experimental-grpc-retry")]
1919
use opentelemetry_sdk::runtime::Tokio;
2020

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

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

15-
use opentelemetry_sdk::retry::RetryPolicy;
15+
use crate::retry::RetryPolicy;
1616
#[cfg(feature = "experimental-grpc-retry")]
1717
use opentelemetry_sdk::runtime::Tokio;
1818

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use crate::{ExportConfig, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADER
2020
feature = "experimental-grpc-retry",
2121
any(feature = "trace", feature = "metrics", feature = "logs")
2222
))]
23-
use opentelemetry_sdk::retry::retry_with_backoff;
23+
use crate::retry::retry_with_backoff;
2424
#[cfg(feature = "grpc-tonic")]
25-
use opentelemetry_sdk::retry::RetryPolicy;
25+
use crate::retry::RetryPolicy;
2626
#[cfg(all(
2727
feature = "experimental-grpc-retry",
2828
any(feature = "trace", feature = "metrics", feature = "logs")
@@ -366,7 +366,7 @@ impl TonicExporterBuilder {
366366
async fn tonic_retry_with_backoff<R, F, Fut, T>(
367367
runtime: R,
368368
policy: RetryPolicy,
369-
classify_fn: fn(&tonic::Status) -> opentelemetry_sdk::retry::RetryErrorType,
369+
classify_fn: fn(&tonic::Status) -> crate::retry::RetryErrorType,
370370
operation_name: &'static str,
371371
operation: F,
372372
) -> Result<T, tonic::Status>
@@ -387,7 +387,7 @@ where
387387
async fn tonic_retry_with_backoff<F, Fut, T>(
388388
_runtime: (),
389389
_policy: RetryPolicy,
390-
_classify_fn: fn(&tonic::Status) -> opentelemetry_sdk::retry::RetryErrorType,
390+
_classify_fn: fn(&tonic::Status) -> crate::retry::RetryErrorType,
391391
_operation_name: &'static str,
392392
operation: F,
393393
) -> Result<T, tonic::Status>
@@ -857,7 +857,7 @@ mod tests {
857857
#[test]
858858
fn test_with_retry_policy() {
859859
use crate::WithTonicConfig;
860-
use opentelemetry_sdk::retry::RetryPolicy;
860+
use crate::retry::RetryPolicy;
861861

862862
let custom_policy = RetryPolicy {
863863
max_retries: 5,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Chann
1616

1717
use super::BoxInterceptor;
1818

19-
use opentelemetry_sdk::retry::RetryPolicy;
19+
use crate::retry::RetryPolicy;
2020
#[cfg(feature = "experimental-grpc-retry")]
2121
use opentelemetry_sdk::runtime::Tokio;
2222

opentelemetry-otlp/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ mod span;
369369
#[cfg(any(feature = "grpc-tonic", feature = "experimental-http-retry"))]
370370
pub mod retry_classification;
371371

372+
/// Retry logic for exporting telemetry data.
373+
#[cfg(any(feature = "grpc-tonic", feature = "experimental-http-retry"))]
374+
pub mod retry;
375+
372376
pub use crate::exporter::Compression;
373377
pub use crate::exporter::ExportConfig;
374378
pub use crate::exporter::ExporterBuildError;
@@ -410,7 +414,7 @@ pub use crate::exporter::{
410414
};
411415

412416
#[cfg(feature = "experimental-http-retry")]
413-
pub use opentelemetry_sdk::retry::RetryPolicy;
417+
pub use retry::RetryPolicy;
414418

415419
/// Type to indicate the builder does not have a client set.
416420
#[derive(Debug, Default, Clone)]

opentelemetry-sdk/src/retry.rs renamed to opentelemetry-otlp/src/retry.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
//! retries. The function uses error classification to determine retry behavior and can honor
99
//! server-provided throttling hints.
1010
11-
#[cfg(feature = "experimental_async_runtime")]
11+
#[cfg(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry"))]
1212
use opentelemetry::otel_warn;
13-
#[cfg(feature = "experimental_async_runtime")]
13+
#[cfg(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry"))]
1414
use std::future::Future;
15+
use std::hash::DefaultHasher;
1516
use std::time::Duration;
16-
#[cfg(feature = "experimental_async_runtime")]
17+
#[cfg(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry"))]
1718
use std::time::SystemTime;
1819

19-
#[cfg(feature = "experimental_async_runtime")]
20-
use crate::runtime::Runtime;
20+
#[cfg(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry"))]
21+
use opentelemetry_sdk::runtime::Runtime;
2122

2223
/// Classification of errors for retry purposes.
2324
#[derive(Debug, Clone, PartialEq)]
@@ -46,11 +47,11 @@ pub struct RetryPolicy {
4647

4748
/// A runtime stub for when experimental_async_runtime is not enabled.
4849
/// This allows retry policy to be configured but no actual retries occur.
49-
#[cfg(not(feature = "experimental_async_runtime"))]
50+
#[cfg(not(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry")))]
5051
#[derive(Debug, Clone, Default)]
5152
pub struct NoOpRuntime;
5253

53-
#[cfg(not(feature = "experimental_async_runtime"))]
54+
#[cfg(not(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry")))]
5455
impl NoOpRuntime {
5556
/// Creates a new no-op runtime.
5657
pub fn new() -> Self {
@@ -59,13 +60,16 @@ impl NoOpRuntime {
5960
}
6061

6162
// Generates a random jitter value up to max_jitter
62-
#[cfg(feature = "experimental_async_runtime")]
63+
#[cfg(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry"))]
6364
fn generate_jitter(max_jitter: u64) -> u64 {
6465
let now = SystemTime::now();
6566
let nanos = now
6667
.duration_since(SystemTime::UNIX_EPOCH)
6768
.unwrap()
6869
.subsec_nanos();
70+
71+
let hasher = DefaultHasher::default();
72+
6973
nanos as u64 % (max_jitter + 1)
7074
}
7175

@@ -86,7 +90,7 @@ fn generate_jitter(max_jitter: u64) -> u64 {
8690
///
8791
/// A `Result` containing the operation's result or an error if max retries are reached
8892
/// or a non-retryable error occurs.
89-
#[cfg(feature = "experimental_async_runtime")]
93+
#[cfg(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry"))]
9094
pub async fn retry_with_backoff<R, F, Fut, T, E, C>(
9195
runtime: R,
9296
policy: RetryPolicy,
@@ -147,7 +151,7 @@ where
147151

148152
/// No-op retry function for when experimental_async_runtime is not enabled.
149153
/// This function will execute the operation exactly once without any retries.
150-
#[cfg(not(feature = "experimental_async_runtime"))]
154+
#[cfg(not(any(feature = "experimental-grpc-retry", feature = "experimental-http-retry")))]
151155
pub async fn retry_with_backoff<R, F, Fut, T, E, C>(
152156
_runtime: R,
153157
_policy: RetryPolicy,
@@ -163,10 +167,10 @@ where
163167
operation().await
164168
}
165169

166-
#[cfg(all(test, feature = "experimental_async_runtime", feature = "rt-tokio"))]
170+
#[cfg(all(test, feature = "experimental-grpc-retry"))]
167171
mod tests {
168172
use super::*;
169-
use crate::runtime::Tokio;
173+
use opentelemetry_sdk::runtime::Tokio;
170174
use std::sync::atomic::{AtomicUsize, Ordering};
171175
use std::time::Duration;
172176
use tokio::time::timeout;

opentelemetry-otlp/src/retry_classification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! supporting server-provided throttling hints like HTTP Retry-After headers and
55
//! gRPC RetryInfo metadata.
66
7-
use opentelemetry_sdk::retry::RetryErrorType;
7+
use crate::retry::RetryErrorType;
88
use std::time::Duration;
99

1010
#[cfg(feature = "grpc-tonic")]
@@ -222,7 +222,7 @@ mod tests {
222222
#[cfg(feature = "grpc-tonic")]
223223
mod grpc_tests {
224224
use crate::retry_classification::grpc::classify_tonic_status;
225-
use opentelemetry_sdk::retry::RetryErrorType;
225+
use crate::retry::RetryErrorType;
226226
use tonic_types::{ErrorDetails, StatusExt};
227227

228228
#[test]

opentelemetry-sdk/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,3 @@ impl<T> From<std::sync::PoisonError<T>> for InMemoryExporterError {
168168
}
169169
}
170170

171-
/// Retry logic for exporting telemetry data.
172-
pub mod retry;

0 commit comments

Comments
 (0)