From 1f5a7a87bab87e16ca94b40c323c75174d8f7dff Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 9 Apr 2024 14:14:44 -0700 Subject: [PATCH 01/12] Add disk retry enablement --- .../Implementation/ExperimentalOptions.cs | 35 ++++++++- .../OtlpExporterOptionsExtensions.cs | 73 ++++++++++++++++--- 2 files changed, 97 insertions(+), 11 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs index da9c185a516..3a02439372c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs @@ -17,6 +17,8 @@ internal sealed class ExperimentalOptions public const string OtlpRetryEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY"; + public const string OtlpDiskRetryStoragePathEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_STORAGE_PATH"; + public ExperimentalOptions() : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) { @@ -29,9 +31,28 @@ public ExperimentalOptions(IConfiguration configuration) this.EmitLogEventAttributes = emitLogEventAttributes; } - if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy) && retryPolicy != null && retryPolicy.Equals("in_memory", StringComparison.OrdinalIgnoreCase)) + if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy) && retryPolicy != null) { - this.EnableInMemoryRetry = true; + if (retryPolicy.Equals("in_memory", StringComparison.OrdinalIgnoreCase)) + { + this.EnableInMemoryRetry = true; + } + else if (retryPolicy.Equals("disk", StringComparison.OrdinalIgnoreCase)) + { + if (configuration.TryGetStringValue(OtlpDiskRetryStoragePathEnvVar, out var path) && path != null) + { + this.EnableDiskRetry = true; + this.DiskRetryStoragePath = path; + } + else + { + throw new ArgumentException($"{OtlpDiskRetryStoragePathEnvVar} is required when '{retryPolicy}' retry is used"); + } + } + else + { + throw new NotSupportedException($"Retry Policy '{retryPolicy}' is not supported."); + } } } @@ -48,4 +69,14 @@ public ExperimentalOptions(IConfiguration configuration) /// href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#retry"/>. /// public bool EnableInMemoryRetry { get; } + + /// + /// Gets a value indicating whether or not retry via disk should be enabled for transient errors. + /// + public bool EnableDiskRetry { get; } + + /// + /// Gets the path on disk where the telemetry will be stored for retries at a later point. + /// + public string? DiskRetryStoragePath { get; } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 34e5a09d597..56ef45d528d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -11,6 +11,7 @@ #if NETSTANDARD2_1 || NET6_0_OR_GREATER using Grpc.Net.Client; #endif +using Google.Protobuf; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission; using LogOtlpCollector = OpenTelemetry.Proto.Collector.Logs.V1; using MetricsOtlpCollector = OpenTelemetry.Proto.Collector.Metrics.V1; @@ -100,9 +101,27 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac ? httpTraceExportClient.HttpClient.Timeout.TotalMilliseconds : options.TimeoutMilliseconds; - return experimentalOptions.EnableInMemoryRetry - ? new OtlpExporterRetryTransmissionHandler(exportClient, timeoutMilliseconds) - : new OtlpExporterTransmissionHandler(exportClient, timeoutMilliseconds); + if (experimentalOptions.EnableInMemoryRetry) + { + return new OtlpExporterRetryTransmissionHandler(exportClient, timeoutMilliseconds); + } + else if (experimentalOptions.EnableDiskRetry) + { + return new OtlpExporterPersistentStorageTransmissionHandler( + exportClient, + timeoutMilliseconds, + (byte[] data) => + { + var request = new TraceOtlpCollector.ExportTraceServiceRequest(); + request.MergeFrom(data); + return request; + }, + Path.Combine(experimentalOptions.DiskRetryStoragePath, "traces")); + } + else + { + return new OtlpExporterTransmissionHandler(exportClient, timeoutMilliseconds); + } } public static OtlpExporterTransmissionHandler GetMetricsExportTransmissionHandler(this OtlpExporterOptions options, ExperimentalOptions experimentalOptions) @@ -116,9 +135,27 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac ? httpMetricsExportClient.HttpClient.Timeout.TotalMilliseconds : options.TimeoutMilliseconds; - return experimentalOptions.EnableInMemoryRetry - ? new OtlpExporterRetryTransmissionHandler(exportClient, timeoutMilliseconds) - : new OtlpExporterTransmissionHandler(exportClient, timeoutMilliseconds); + if (experimentalOptions.EnableInMemoryRetry) + { + return new OtlpExporterRetryTransmissionHandler(exportClient, timeoutMilliseconds); + } + else if (experimentalOptions.EnableDiskRetry) + { + return new OtlpExporterPersistentStorageTransmissionHandler( + exportClient, + timeoutMilliseconds, + (byte[] data) => + { + var request = new MetricsOtlpCollector.ExportMetricsServiceRequest(); + request.MergeFrom(data); + return request; + }, + Path.Combine(experimentalOptions.DiskRetryStoragePath, "metrics")); + } + else + { + return new OtlpExporterTransmissionHandler(exportClient, timeoutMilliseconds); + } } public static OtlpExporterTransmissionHandler GetLogsExportTransmissionHandler(this OtlpExporterOptions options, ExperimentalOptions experimentalOptions) @@ -128,9 +165,27 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac ? httpLogExportClient.HttpClient.Timeout.TotalMilliseconds : options.TimeoutMilliseconds; - return experimentalOptions.EnableInMemoryRetry - ? new OtlpExporterRetryTransmissionHandler(exportClient, timeoutMilliseconds) - : new OtlpExporterTransmissionHandler(exportClient, timeoutMilliseconds); + if (experimentalOptions.EnableInMemoryRetry) + { + return new OtlpExporterRetryTransmissionHandler(exportClient, timeoutMilliseconds); + } + else if (experimentalOptions.EnableDiskRetry) + { + return new OtlpExporterPersistentStorageTransmissionHandler( + exportClient, + timeoutMilliseconds, + (byte[] data) => + { + var request = new LogOtlpCollector.ExportLogsServiceRequest(); + request.MergeFrom(data); + return request; + }, + Path.Combine(experimentalOptions.DiskRetryStoragePath, "logs")); + } + else + { + return new OtlpExporterTransmissionHandler(exportClient, timeoutMilliseconds); + } } public static IExportClient GetTraceExportClient(this OtlpExporterOptions options) => From 82464dd99942af0cb73f0758e6ca32d31f0bca0e Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 10 Apr 2024 11:47:01 -0700 Subject: [PATCH 02/12] rename env var --- .../Implementation/ExperimentalOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs index 3a02439372c..bdbf6d288ba 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs @@ -17,7 +17,7 @@ internal sealed class ExperimentalOptions public const string OtlpRetryEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY"; - public const string OtlpDiskRetryStoragePathEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_STORAGE_PATH"; + public const string OtlpDiskRetryStoragePathEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH"; public ExperimentalOptions() : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) From 97eaacc9a4a93a5c3de28ef1b19d39de0725b0a8 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 3 May 2024 09:13:43 -0700 Subject: [PATCH 03/12] refactory --- .../Implementation/ExperimentalOptions.cs | 10 +++++----- .../OtlpExporterOptionsExtensions.cs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs index bdbf6d288ba..20599db083d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs @@ -17,7 +17,7 @@ internal sealed class ExperimentalOptions public const string OtlpRetryEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY"; - public const string OtlpDiskRetryStoragePathEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH"; + public const string OtlpDiskRetryDirectoryPathEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH"; public ExperimentalOptions() : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) @@ -39,14 +39,14 @@ public ExperimentalOptions(IConfiguration configuration) } else if (retryPolicy.Equals("disk", StringComparison.OrdinalIgnoreCase)) { - if (configuration.TryGetStringValue(OtlpDiskRetryStoragePathEnvVar, out var path) && path != null) + if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path) && path != null) { this.EnableDiskRetry = true; - this.DiskRetryStoragePath = path; + this.DiskRetryDirectoryPath = path; } else { - throw new ArgumentException($"{OtlpDiskRetryStoragePathEnvVar} is required when '{retryPolicy}' retry is used"); + throw new ArgumentException($"{OtlpDiskRetryDirectoryPathEnvVar} is required when '{retryPolicy}' retry is used"); } } else @@ -78,5 +78,5 @@ public ExperimentalOptions(IConfiguration configuration) /// /// Gets the path on disk where the telemetry will be stored for retries at a later point. /// - public string? DiskRetryStoragePath { get; } + public string? DiskRetryDirectoryPath { get; } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 56ef45d528d..8f282fd3030 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -116,7 +116,7 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac request.MergeFrom(data); return request; }, - Path.Combine(experimentalOptions.DiskRetryStoragePath, "traces")); + Path.Combine(experimentalOptions.DiskRetryDirectoryPath, "traces")); } else { @@ -150,7 +150,7 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac request.MergeFrom(data); return request; }, - Path.Combine(experimentalOptions.DiskRetryStoragePath, "metrics")); + Path.Combine(experimentalOptions.DiskRetryDirectoryPath, "metrics")); } else { @@ -180,7 +180,7 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac request.MergeFrom(data); return request; }, - Path.Combine(experimentalOptions.DiskRetryStoragePath, "logs")); + Path.Combine(experimentalOptions.DiskRetryDirectoryPath, "logs")); } else { From ee854f3bd583de5926956c975b46f117fb73ea4e Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 3 May 2024 09:24:12 -0700 Subject: [PATCH 04/12] changelog + readme --- .../CHANGELOG.md | 8 ++++++++ .../README.md | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index fa2eacc89fe..b71c618d5f7 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -13,6 +13,14 @@ `parent_is_remote` information. ([#5563](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5563)) +* Introduced experimental support for automatically retrying export to the otlp + endpoint by storing the telemetry offline during transient network errors. + Users can enable this feature by setting the + `OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY` environment variable to `disk` and + setting `OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` to the path + on disk for storing the telemetry. + ([#5527](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5527)) + ## 1.8.1 Released 2024-Apr-17 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index dd14461e6a5..b35482ddc3d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -632,6 +632,11 @@ want to solicit feedback from the community. Added in `1.8.0`. + When set to `disk` along with setting + `OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` to the path on + disk, it enables retries by storing telemetry on disk during transient + errors. TODO: Add package version. + * Logs * `OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES` From 3417006ba3a571dba26311734fd0a7c83043cd89 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 3 May 2024 09:40:08 -0700 Subject: [PATCH 05/12] update test --- .../OtlpExporterOptionsExtensionsTests.cs | 70 ++++++++++++++----- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs index b8bfb608288..a43aed34fe3 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs @@ -4,6 +4,7 @@ #if NETFRAMEWORK using System.Net.Http; #endif +using Microsoft.Extensions.Configuration; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission; @@ -130,16 +131,34 @@ public void AppendPathIfNotPresent_TracesPath_AppendsCorrectly(string inputUri, } [Theory] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000)] - public void GetTransmissionHandler_InitializesCorrectExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds) + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, null)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, null)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, null)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, "in_memory")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, "in_memory")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, "in_memory")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, "disk")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, "disk")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, "disk")] + public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds, string retryStrategy) { var exporterOptions = new OtlpExporterOptions() { Protocol = protocol }; if (customHttpClient) @@ -150,28 +169,45 @@ public void GetTransmissionHandler_InitializesCorrectExportClientAndTimeoutValue }; } + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.OtlpRetryEnvVar] = retryStrategy, [ExperimentalOptions.OtlpDiskRetryDirectoryPathEnvVar] = "/" }) + .Build(); + if (exportClientType == typeof(OtlpGrpcTraceExportClient) || exportClientType == typeof(OtlpHttpTraceExportClient)) { - var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions()); + var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } else if (exportClientType == typeof(OtlpGrpcMetricsExportClient) || exportClientType == typeof(OtlpHttpMetricsExportClient)) { - var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions()); + var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } else { - var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions()); + var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } } - private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds) + private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds, string retryStrategy) { + if (retryStrategy == "in_memory") + { + Assert.True(transmissionHandler is OtlpExporterRetryTransmissionHandler); + } + else if (retryStrategy == "disk") + { + Assert.True(transmissionHandler is OtlpExporterPersistentStorageTransmissionHandler); + } + else + { + Assert.True(transmissionHandler is OtlpExporterTransmissionHandler); + } + Assert.Equal(exportClientType, transmissionHandler.ExportClient.GetType()); Assert.Equal(expectedTimeoutMilliseconds, transmissionHandler.TimeoutMilliseconds); From edf649e6fadb102dc7a00ae24a233eb5777f97d3 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 3 May 2024 09:50:58 -0700 Subject: [PATCH 06/12] revert test --- .../OtlpExporterOptionsExtensionsTests.cs | 70 +++++-------------- 1 file changed, 17 insertions(+), 53 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs index a43aed34fe3..b8bfb608288 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs @@ -4,7 +4,6 @@ #if NETFRAMEWORK using System.Net.Http; #endif -using Microsoft.Extensions.Configuration; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission; @@ -131,34 +130,16 @@ public void AppendPathIfNotPresent_TracesPath_AppendsCorrectly(string inputUri, } [Theory] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, null)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, null)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, null)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, null)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, null)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, null)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, null)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, null)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, null)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, "in_memory")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, "in_memory")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, "in_memory")] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, "in_memory")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, "in_memory")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, "in_memory")] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, "in_memory")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, "in_memory")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, "in_memory")] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, "disk")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, "disk")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, "disk")] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, "disk")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, "disk")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, "disk")] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, "disk")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, "disk")] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, "disk")] - public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds, string retryStrategy) + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000)] + public void GetTransmissionHandler_InitializesCorrectExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds) { var exporterOptions = new OtlpExporterOptions() { Protocol = protocol }; if (customHttpClient) @@ -169,45 +150,28 @@ public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeo }; } - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.OtlpRetryEnvVar] = retryStrategy, [ExperimentalOptions.OtlpDiskRetryDirectoryPathEnvVar] = "/" }) - .Build(); - if (exportClientType == typeof(OtlpGrpcTraceExportClient) || exportClientType == typeof(OtlpHttpTraceExportClient)) { - var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions(configuration)); + var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions()); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); } else if (exportClientType == typeof(OtlpGrpcMetricsExportClient) || exportClientType == typeof(OtlpHttpMetricsExportClient)) { - var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions(configuration)); + var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions()); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); } else { - var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions(configuration)); + var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions()); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); } } - private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds, string retryStrategy) + private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds) { - if (retryStrategy == "in_memory") - { - Assert.True(transmissionHandler is OtlpExporterRetryTransmissionHandler); - } - else if (retryStrategy == "disk") - { - Assert.True(transmissionHandler is OtlpExporterPersistentStorageTransmissionHandler); - } - else - { - Assert.True(transmissionHandler is OtlpExporterTransmissionHandler); - } - Assert.Equal(exportClientType, transmissionHandler.ExportClient.GetType()); Assert.Equal(expectedTimeoutMilliseconds, transmissionHandler.TimeoutMilliseconds); From 1371484c05c7e6bd7cfb199233e631ce08e4926c Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 7 May 2024 11:39:41 -0700 Subject: [PATCH 07/12] review --- .../README.md | 10 +-- .../MockCollectorIntegrationTests.cs | 1 + .../OtlpExporterOptionsExtensionsTests.cs | 71 ++++++++++++++----- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index b35482ddc3d..adff6d6c7f2 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -627,15 +627,17 @@ want to solicit feedback from the community. * `OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY` - When set to `in_memory`, it enables in-memory retry for transient errors + * When set to `in_memory`, it enables in-memory retry for transient errors encountered while sending telemetry. - Added in `1.8.0`. + Added in `1.8.0`. - When set to `disk` along with setting + * When set to `disk` along with setting `OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` to the path on disk, it enables retries by storing telemetry on disk during transient - errors. TODO: Add package version. + errors. + + Added in **TBD** (Unreleased). * Logs diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs index a5ce7a0a279..3e972508158 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs @@ -188,6 +188,7 @@ public async Task GrpcRetryTests(bool useRetryTransmissionHandler, ExportResult using var source = new ActivitySource(activitySourceName); using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .ConfigureServices(sp => sp.AddSingleton(configuration)) .AddSource(activitySourceName) .Build(); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs index b8bfb608288..55daab7c638 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs @@ -4,6 +4,7 @@ #if NETFRAMEWORK using System.Net.Http; #endif +using Microsoft.Extensions.Configuration; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission; @@ -130,16 +131,34 @@ public void AppendPathIfNotPresent_TracesPath_AppendsCorrectly(string inputUri, } [Theory] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000)] - [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000)] - [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000)] - public void GetTransmissionHandler_InitializesCorrectExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds) + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, null)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, null)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, null)] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, null)] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, "in_memory")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, "in_memory")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, "in_memory")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, "in_memory")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcTraceExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpTraceExportClient), true, 8000, "disk")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcMetricsExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpMetricsExportClient), true, 8000, "disk")] + [InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcLogExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), false, 10000, "disk")] + [InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpLogExportClient), true, 8000, "disk")] + public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds, string retryStrategy) { var exporterOptions = new OtlpExporterOptions() { Protocol = protocol }; if (customHttpClient) @@ -150,28 +169,46 @@ public void GetTransmissionHandler_InitializesCorrectExportClientAndTimeoutValue }; } + var path = Path.GetTempPath(); + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.OtlpRetryEnvVar] = retryStrategy, [ExperimentalOptions.OtlpDiskRetryDirectoryPathEnvVar] = path }) + .Build(); + if (exportClientType == typeof(OtlpGrpcTraceExportClient) || exportClientType == typeof(OtlpHttpTraceExportClient)) { - var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions()); + var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } else if (exportClientType == typeof(OtlpGrpcMetricsExportClient) || exportClientType == typeof(OtlpHttpMetricsExportClient)) { - var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions()); + var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } else { - var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions()); + var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds); + AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } } - private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds) + private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds, string retryStrategy) { + if (retryStrategy == "in_memory") + { + Assert.True(transmissionHandler is OtlpExporterRetryTransmissionHandler); + } + else if (retryStrategy == "disk") + { + Assert.True(transmissionHandler is OtlpExporterPersistentStorageTransmissionHandler); + } + else + { + Assert.True(transmissionHandler is OtlpExporterTransmissionHandler); + } + Assert.Equal(exportClientType, transmissionHandler.ExportClient.GetType()); Assert.Equal(expectedTimeoutMilliseconds, transmissionHandler.TimeoutMilliseconds); From 634a2be9f7a6dd4a4423bdf1daf3b13335a15604 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 7 May 2024 11:49:49 -0700 Subject: [PATCH 08/12] review --- .../Implementation/ExperimentalOptions.cs | 5 +++-- .../OtlpExporterOptionsExtensionsTests.cs | 11 +++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs index 20599db083d..65d0bf57ee1 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs @@ -39,14 +39,15 @@ public ExperimentalOptions(IConfiguration configuration) } else if (retryPolicy.Equals("disk", StringComparison.OrdinalIgnoreCase)) { + this.EnableDiskRetry = true; if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path) && path != null) { - this.EnableDiskRetry = true; this.DiskRetryDirectoryPath = path; } else { - throw new ArgumentException($"{OtlpDiskRetryDirectoryPathEnvVar} is required when '{retryPolicy}' retry is used"); + // Fallback to temp location. + this.DiskRetryDirectoryPath = Path.GetTempPath(); } } else diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs index 55daab7c638..2b7810dfadf 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs @@ -169,32 +169,31 @@ public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeo }; } - var path = Path.GetTempPath(); var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.OtlpRetryEnvVar] = retryStrategy, [ExperimentalOptions.OtlpDiskRetryDirectoryPathEnvVar] = path }) + .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.OtlpRetryEnvVar] = retryStrategy }) .Build(); if (exportClientType == typeof(OtlpGrpcTraceExportClient) || exportClientType == typeof(OtlpHttpTraceExportClient)) { var transmissionHandler = exporterOptions.GetTraceExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); + AssertTransmissionHandler(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } else if (exportClientType == typeof(OtlpGrpcMetricsExportClient) || exportClientType == typeof(OtlpHttpMetricsExportClient)) { var transmissionHandler = exporterOptions.GetMetricsExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); + AssertTransmissionHandler(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } else { var transmissionHandler = exporterOptions.GetLogsExportTransmissionHandler(new ExperimentalOptions(configuration)); - AssertTransmissionHandlerProperties(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); + AssertTransmissionHandler(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy); } } - private static void AssertTransmissionHandlerProperties(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds, string retryStrategy) + private static void AssertTransmissionHandler(OtlpExporterTransmissionHandler transmissionHandler, Type exportClientType, int expectedTimeoutMilliseconds, string retryStrategy) { if (retryStrategy == "in_memory") { From d4eab4d4778325e8d3363afe6c601b3c35161c1b Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 7 May 2024 12:03:05 -0700 Subject: [PATCH 09/12] changelog --- .../CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index b71c618d5f7..d8200afd2b1 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -16,9 +16,12 @@ * Introduced experimental support for automatically retrying export to the otlp endpoint by storing the telemetry offline during transient network errors. Users can enable this feature by setting the - `OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY` environment variable to `disk` and - setting `OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` to the path - on disk for storing the telemetry. + `OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY` environment variable to `disk`. The + default path where the telemetry is stored is obtained by calling + [Path.GetTempPath()](https://learn.microsoft.com/dotnet/api/system.io.path.gettemppath) + or can be customized by setting + `OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` environment + variable. ([#5527](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5527)) ## 1.8.1 From 053d1bb3141ca60d726ad94ead4d36878f60eaa7 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 7 May 2024 12:05:28 -0700 Subject: [PATCH 10/12] clean up --- .../MockCollectorIntegrationTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs index 3e972508158..a5ce7a0a279 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs @@ -188,7 +188,6 @@ public async Task GrpcRetryTests(bool useRetryTransmissionHandler, ExportResult using var source = new ActivitySource(activitySourceName); using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .ConfigureServices(sp => sp.AddSingleton(configuration)) .AddSource(activitySourceName) .Build(); From a909b968e758626e38aee8cfa9c7072df3a49ed5 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 7 May 2024 13:00:56 -0700 Subject: [PATCH 11/12] address feedback --- .../OtlpExporterOptionsExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 8f282fd3030..4cf15b1b296 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -11,6 +11,7 @@ #if NETSTANDARD2_1 || NET6_0_OR_GREATER using Grpc.Net.Client; #endif +using System.Diagnostics; using Google.Protobuf; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission; using LogOtlpCollector = OpenTelemetry.Proto.Collector.Logs.V1; @@ -107,6 +108,8 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac } else if (experimentalOptions.EnableDiskRetry) { + Debug.Assert(!string.IsNullOrEmpty(experimentalOptions.DiskRetryDirectoryPath), $"{nameof(experimentalOptions.DiskRetryDirectoryPath)} is null or empty"); + return new OtlpExporterPersistentStorageTransmissionHandler( exportClient, timeoutMilliseconds, From 8922b5d2c88479dca784c581540fc983e2fd72af Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 7 May 2024 13:46:28 -0700 Subject: [PATCH 12/12] add debug.assert --- .../OtlpExporterOptionsExtensions.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 4cf15b1b296..ba68de13261 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -144,6 +144,8 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac } else if (experimentalOptions.EnableDiskRetry) { + Debug.Assert(!string.IsNullOrEmpty(experimentalOptions.DiskRetryDirectoryPath), $"{nameof(experimentalOptions.DiskRetryDirectoryPath)} is null or empty"); + return new OtlpExporterPersistentStorageTransmissionHandler( exportClient, timeoutMilliseconds, @@ -174,6 +176,8 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac } else if (experimentalOptions.EnableDiskRetry) { + Debug.Assert(!string.IsNullOrEmpty(experimentalOptions.DiskRetryDirectoryPath), $"{nameof(experimentalOptions.DiskRetryDirectoryPath)} is null or empty"); + return new OtlpExporterPersistentStorageTransmissionHandler( exportClient, timeoutMilliseconds,