|
12 | 12 | #include <atomic>
|
13 | 13 | #include <chrono>
|
14 | 14 | #include <condition_variable>
|
| 15 | +#include <cstdio> |
15 | 16 | #include <fstream>
|
16 | 17 | #include <iterator>
|
17 | 18 | #include <memory>
|
|
23 | 24 | #include "opentelemetry/common/timestamp.h"
|
24 | 25 | #include "opentelemetry/ext/http/common/url_parser.h"
|
25 | 26 | #include "opentelemetry/nostd/function_ref.h"
|
| 27 | +#include "opentelemetry/nostd/string_view.h" |
26 | 28 | #include "opentelemetry/sdk/common/global_log_handler.h"
|
27 | 29 |
|
28 | 30 | OPENTELEMETRY_BEGIN_NAMESPACE
|
@@ -347,6 +349,49 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
|
347 | 349 | grpc_arguments.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP);
|
348 | 350 | }
|
349 | 351 |
|
| 352 | +#ifdef ENABLE_OTLP_RETRY_PREVIEW |
| 353 | + if (options.retry_policy_max_attempts > 0U && |
| 354 | + options.retry_policy_initial_backoff > std::chrono::duration<float>::zero() && |
| 355 | + options.retry_policy_max_backoff > std::chrono::duration<float>::zero() && |
| 356 | + options.retry_policy_backoff_multiplier > 0.0f) |
| 357 | + { |
| 358 | + static const auto kServiceConfigJson = opentelemetry::nostd::string_view{R"( |
| 359 | + { |
| 360 | + "methodConfig": [ |
| 361 | + { |
| 362 | + "name": [{}], |
| 363 | + "retryPolicy": { |
| 364 | + "maxAttempts": %0000000000u, |
| 365 | + "initialBackoff": "%0000000000.1fs", |
| 366 | + "maxBackoff": "%0000000000.1fs", |
| 367 | + "backoffMultiplier": %0000000000.1f, |
| 368 | + "retryableStatusCodes": [ |
| 369 | + "CANCELLED", |
| 370 | + "DEADLINE_EXCEEDED", |
| 371 | + "ABORTED", |
| 372 | + "OUT_OF_RANGE", |
| 373 | + "DATA_LOSS", |
| 374 | + "UNAVAILABLE" |
| 375 | + ] |
| 376 | + } |
| 377 | + } |
| 378 | + ] |
| 379 | + })"}; |
| 380 | + |
| 381 | + // Allocate string with buffer large enough to hold the formatted json config |
| 382 | + auto service_config = std::string(kServiceConfigJson.size(), '\0'); |
| 383 | + // Prior to C++17, need to explicitly cast away constness from `data()` buffer |
| 384 | + std::snprintf( |
| 385 | + const_cast<decltype(service_config)::value_type *>(service_config.data()), |
| 386 | + service_config.size(), kServiceConfigJson.data(), options.retry_policy_max_attempts, |
| 387 | + std::min(std::max(options.retry_policy_initial_backoff.count(), 0.f), 999999999.f), |
| 388 | + std::min(std::max(options.retry_policy_max_backoff.count(), 0.f), 999999999.f), |
| 389 | + std::min(std::max(options.retry_policy_backoff_multiplier, 0.f), 999999999.f)); |
| 390 | + |
| 391 | + grpc_arguments.SetServiceConfigJSON(service_config); |
| 392 | + } |
| 393 | +#endif // ENABLE_OTLP_RETRY_PREVIEW |
| 394 | + |
350 | 395 | if (options.use_ssl_credentials)
|
351 | 396 | {
|
352 | 397 | grpc::SslCredentialsOptions ssl_opts;
|
|
0 commit comments