|
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,46 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO |
347 | 349 | grpc_arguments.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP); |
348 | 350 | } |
349 | 351 |
|
| 352 | + if (options.retry_policy_max_attempts > 0U && |
| 353 | + options.retry_policy_initial_backoff > SecondsDecimal::zero() && |
| 354 | + options.retry_policy_max_backoff > SecondsDecimal::zero() && |
| 355 | + options.retry_policy_backoff_multiplier > 0.f) |
| 356 | + { |
| 357 | + static const auto kServiceConfigJson = opentelemetry::nostd::string_view{R"( |
| 358 | + { |
| 359 | + "methodConfig": [ |
| 360 | + { |
| 361 | + "name": [{}], |
| 362 | + "retryPolicy": { |
| 363 | + "maxAttempts": %0000000000u, |
| 364 | + "initialBackoff": "%.1fs", |
| 365 | + "maxBackoff": "%.1fs", |
| 366 | + "backoffMultiplier": %.1f, |
| 367 | + "retryableStatusCodes": [ |
| 368 | + "CANCELLED", |
| 369 | + "DEADLINE_EXCEEDED", |
| 370 | + "ABORTED", |
| 371 | + "OUT_OF_RANGE", |
| 372 | + "DATA_LOSS", |
| 373 | + "UNAVAILABLE" |
| 374 | + ] |
| 375 | + } |
| 376 | + } |
| 377 | + ] |
| 378 | + })"}; |
| 379 | + |
| 380 | + // Allocate string with buffer large enough to hold the formatted json config |
| 381 | + auto service_config = std::string(kServiceConfigJson.size(), '\0'); |
| 382 | + // Prior to C++17, need to explicitly cast away constness from `data()` buffer |
| 383 | + std::snprintf(const_cast<decltype(service_config)::value_type *>(service_config.data()), |
| 384 | + service_config.size(), kServiceConfigJson.data(), |
| 385 | + options.retry_policy_max_attempts, options.retry_policy_initial_backoff.count(), |
| 386 | + options.retry_policy_max_backoff.count(), |
| 387 | + options.retry_policy_backoff_multiplier); |
| 388 | + |
| 389 | + grpc_arguments.SetServiceConfigJSON(service_config); |
| 390 | + } |
| 391 | + |
350 | 392 | if (options.use_ssl_credentials) |
351 | 393 | { |
352 | 394 | grpc::SslCredentialsOptions ssl_opts; |
|
0 commit comments