Skip to content

Commit 25f7a13

Browse files
authored
[EXPORTER] Support handling retry-able errors for OTLP/HTTP (#3223)
1 parent 02cda51 commit 25f7a13

30 files changed

+1266
-104
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Increment the:
3333
* [SDK] Enable deriving from ResourceDetector to create a Resource
3434
[#3247](https://github.com/open-telemetry/opentelemetry-cpp/pull/3247)
3535

36+
* [EXPORTER] Support handling retry-able errors for OTLP/HTTP
37+
[#3223](https://github.com/open-telemetry/opentelemetry-cpp/pull/3223)
38+
3639
New features:
3740

3841
* [SDK] Better control of threads executed by opentelemetry-cpp

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ if(NOT WITH_STL STREQUAL "OFF")
212212
endif()
213213
endif()
214214

215+
option(WITH_OTLP_RETRY_PREVIEW
216+
"Whether to enable experimental retry functionality" OFF)
217+
215218
option(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW
216219
"Whether to enable mTLS support fro gRPC" OFF)
217220

api/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ target_compile_definitions(
116116
opentelemetry_api
117117
INTERFACE OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO})
118118

119+
if(WITH_OTLP_RETRY_PREVIEW)
120+
target_compile_definitions(opentelemetry_api
121+
INTERFACE ENABLE_OTLP_RETRY_PREVIEW)
122+
endif()
123+
119124
if(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW)
120125
target_compile_definitions(opentelemetry_api
121126
INTERFACE ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW)

ci/do_ci.sh

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
120120
-DOTELCPP_MAINTAINER_MODE=ON \
121121
-DWITH_NO_DEPRECATED_CODE=ON \
122122
-DWITH_OTLP_HTTP_COMPRESSION=ON \
123+
-DWITH_OTLP_RETRY_PREVIEW=ON \
123124
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
124125
"${SRC_DIR}"
125126
eval "$MAKE_COMMAND"
@@ -142,6 +143,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
142143
-DOTELCPP_MAINTAINER_MODE=ON \
143144
-DWITH_NO_DEPRECATED_CODE=ON \
144145
-DWITH_OTLP_HTTP_COMPRESSION=ON \
146+
-DWITH_OTLP_RETRY_PREVIEW=ON \
145147
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
146148
"${SRC_DIR}"
147149
eval "$MAKE_COMMAND"
@@ -165,6 +167,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
165167
-DOTELCPP_MAINTAINER_MODE=ON \
166168
-DWITH_NO_DEPRECATED_CODE=ON \
167169
-DWITH_OTLP_HTTP_COMPRESSION=ON \
170+
-DWITH_OTLP_RETRY_PREVIEW=ON \
168171
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
169172
"${SRC_DIR}"
170173
make -k -j $(nproc)
@@ -189,6 +192,7 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
189192
-DWITH_ABI_VERSION_1=OFF \
190193
-DWITH_ABI_VERSION_2=ON \
191194
-DWITH_OTLP_HTTP_COMPRESSION=ON \
195+
-DWITH_OTLP_RETRY_PREVIEW=ON \
192196
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
193197
"${SRC_DIR}"
194198
eval "$MAKE_COMMAND"

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h

+16
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ std::string GetOtlpDefaultTracesCompression();
152152
std::string GetOtlpDefaultMetricsCompression();
153153
std::string GetOtlpDefaultLogsCompression();
154154

155+
std::uint32_t GetOtlpDefaultTracesRetryMaxAttempts();
156+
std::uint32_t GetOtlpDefaultMetricsRetryMaxAttempts();
157+
std::uint32_t GetOtlpDefaultLogsRetryMaxAttempts();
158+
159+
std::chrono::duration<float> GetOtlpDefaultTracesRetryInitialBackoff();
160+
std::chrono::duration<float> GetOtlpDefaultMetricsRetryInitialBackoff();
161+
std::chrono::duration<float> GetOtlpDefaultLogsRetryInitialBackoff();
162+
163+
std::chrono::duration<float> GetOtlpDefaultTracesRetryMaxBackoff();
164+
std::chrono::duration<float> GetOtlpDefaultMetricsRetryMaxBackoff();
165+
std::chrono::duration<float> GetOtlpDefaultLogsRetryMaxBackoff();
166+
167+
float GetOtlpDefaultTracesRetryBackoffMultiplier();
168+
float GetOtlpDefaultMetricsRetryBackoffMultiplier();
169+
float GetOtlpDefaultLogsRetryBackoffMultiplier();
170+
155171
} // namespace otlp
156172
} // namespace exporter
157173
OPENTELEMETRY_END_NAMESPACE

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ struct OtlpHttpClientOptions
7575
// Additional HTTP headers
7676
OtlpHeaders http_headers;
7777

78+
// Retry policy for select failure codes
79+
ext::http::client::RetryPolicy retry_policy;
80+
7881
// Concurrent requests
7982
std::size_t max_concurrent_requests = 64;
8083

@@ -107,6 +110,10 @@ struct OtlpHttpClientOptions
107110
bool input_console_debug,
108111
std::chrono::system_clock::duration input_timeout,
109112
const OtlpHeaders &input_http_headers,
113+
std::uint32_t input_retry_policy_max_attempts,
114+
std::chrono::duration<float> input_retry_policy_initial_backoff,
115+
std::chrono::duration<float> input_retry_policy_max_backoff,
116+
float input_retry_policy_backoff_multiplier,
110117
const std::shared_ptr<sdk::common::ThreadInstrumentation> &input_thread_instrumentation,
111118
std::size_t input_concurrent_sessions = 64,
112119
std::size_t input_max_requests_per_connection = 8,
@@ -131,6 +138,8 @@ struct OtlpHttpClientOptions
131138
console_debug(input_console_debug),
132139
timeout(input_timeout),
133140
http_headers(input_http_headers),
141+
retry_policy{input_retry_policy_max_attempts, input_retry_policy_initial_backoff,
142+
input_retry_policy_max_backoff, input_retry_policy_backoff_multiplier},
134143
max_concurrent_requests(input_concurrent_sessions),
135144
max_requests_per_connection(input_max_requests_per_connection),
136145
user_agent(input_user_agent),

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <cstdint>
78
#include <string>
89

910
#include "opentelemetry/exporters/otlp/otlp_environment.h"
@@ -101,6 +102,18 @@ struct OPENTELEMETRY_EXPORT OtlpHttpExporterOptions
101102

102103
/** Compression type. */
103104
std::string compression;
105+
106+
/** The maximum number of call attempts, including the original attempt. */
107+
std::uint32_t retry_policy_max_attempts{};
108+
109+
/** The initial backoff delay between retry attempts, random between (0, initial_backoff). */
110+
std::chrono::duration<float> retry_policy_initial_backoff{};
111+
112+
/** The maximum backoff places an upper limit on exponential backoff growth. */
113+
std::chrono::duration<float> retry_policy_max_backoff{};
114+
115+
/** The backoff will be multiplied by this value after each retry attempt. */
116+
float retry_policy_backoff_multiplier{};
104117
};
105118

106119
} // namespace otlp

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <cstdint>
78
#include <string>
89

910
#include "opentelemetry/exporters/otlp/otlp_environment.h"
@@ -101,6 +102,18 @@ struct OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterOptions
101102

102103
/** Compression type. */
103104
std::string compression;
105+
106+
/** The maximum number of call attempts, including the original attempt. */
107+
std::uint32_t retry_policy_max_attempts{};
108+
109+
/** The initial backoff delay between retry attempts, random between (0, initial_backoff). */
110+
std::chrono::duration<float> retry_policy_initial_backoff{};
111+
112+
/** The maximum backoff places an upper limit on exponential backoff growth. */
113+
std::chrono::duration<float> retry_policy_max_backoff{};
114+
115+
/** The backoff will be multiplied by this value after each retry attempt. */
116+
float retry_policy_backoff_multiplier{};
104117
};
105118

106119
} // namespace otlp

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <cstdint>
78
#include <string>
89

910
#include "opentelemetry/exporters/otlp/otlp_environment.h"
@@ -104,6 +105,18 @@ struct OPENTELEMETRY_EXPORT OtlpHttpMetricExporterOptions
104105

105106
/** Compression type. */
106107
std::string compression;
108+
109+
/** The maximum number of call attempts, including the original attempt. */
110+
std::uint32_t retry_policy_max_attempts{};
111+
112+
/** The initial backoff delay between retry attempts, random between (0, initial_backoff). */
113+
std::chrono::duration<float> retry_policy_initial_backoff{};
114+
115+
/** The maximum backoff places an upper limit on exponential backoff growth. */
116+
std::chrono::duration<float> retry_policy_max_backoff{};
117+
118+
/** The backoff will be multiplied by this value after each retry attempt. */
119+
float retry_policy_backoff_multiplier{};
107120
};
108121

109122
} // namespace otlp

0 commit comments

Comments
 (0)