|
3 | 3 |
|
4 | 4 | using System.Net;
|
5 | 5 | using System.Net.Http.Headers;
|
| 6 | +#if NET |
| 7 | +using System.Security.Cryptography; |
| 8 | +#endif |
6 | 9 | using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient.Grpc;
|
7 | 10 |
|
8 | 11 | namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
|
@@ -40,13 +43,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie
|
40 | 43 | /// </summary>
|
41 | 44 | internal static class OtlpRetry
|
42 | 45 | {
|
43 |
| - public const string GrpcStatusDetailsHeader = "grpc-status-details-bin"; |
44 | 46 | public const int InitialBackoffMilliseconds = 1000;
|
45 | 47 | private const int MaxBackoffMilliseconds = 5000;
|
46 | 48 | private const double BackoffMultiplier = 1.5;
|
47 | 49 |
|
48 | 50 | #if !NET
|
49 |
| - private static readonly Random Random = new Random(); |
| 51 | + private static readonly Random Random = new(); |
50 | 52 | #endif
|
51 | 53 |
|
52 | 54 | public static bool TryGetHttpRetryResult(ExportClientHttpResponse response, int retryDelayInMilliSeconds, out RetryResult retryResult)
|
@@ -156,9 +158,7 @@ private static bool TryGetRetryResult<TStatusCode, TCarrier>(TStatusCode statusC
|
156 | 158 | return false;
|
157 | 159 | }
|
158 | 160 |
|
159 |
| - var delayDuration = throttleDelay.HasValue |
160 |
| - ? throttleDelay.Value |
161 |
| - : TimeSpan.FromMilliseconds(GetRandomNumber(0, nextRetryDelayMilliseconds)); |
| 161 | + var delayDuration = throttleDelay ?? TimeSpan.FromMilliseconds(GetRandomNumber(0, nextRetryDelayMilliseconds)); |
162 | 162 |
|
163 | 163 | if (deadline.HasValue && IsDeadlineExceeded(deadline + delayDuration))
|
164 | 164 | {
|
@@ -246,13 +246,15 @@ private static bool IsHttpStatusCodeRetryable(HttpStatusCode statusCode, bool ha
|
246 | 246 | private static int GetRandomNumber(int min, int max)
|
247 | 247 | {
|
248 | 248 | #if NET
|
249 |
| - return Random.Shared.Next(min, max); |
| 249 | + return RandomNumberGenerator.GetInt32(min, max); |
250 | 250 | #else
|
251 | 251 | // TODO: Implement this better to minimize lock contention.
|
252 | 252 | // Consider pulling in Random.Shared implementation.
|
253 | 253 | lock (Random)
|
254 | 254 | {
|
| 255 | +#pragma warning disable CA5394 // Do not use insecure randomness |
255 | 256 | return Random.Next(min, max);
|
| 257 | +#pragma warning restore CA5394 // Do not use insecure randomness |
256 | 258 | }
|
257 | 259 | #endif
|
258 | 260 | }
|
|
0 commit comments