From 3a15b779c998c35ad5bae020f9cd203412a0332a Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 30 Jan 2023 16:48:04 -0800 Subject: [PATCH 01/49] Add options for persistent storage to OTLP Exporter --- build/Common.nonprod.props | 1 + build/Common.props | 1 + ...OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj | 1 + .../OtlpExporterOptions.cs | 10 ++++++++++ 4 files changed, 13 insertions(+) diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index 12049e6e3c0..6e3dc69d1ca 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -42,6 +42,7 @@ [6.0.0,) [17.4.1] [4.18.3,5.0) + 1.0.0-beta.1 [6.4.0,7.0) [1.0.0,2.0) [6.4.0] diff --git a/build/Common.props b/build/Common.props index d47bf985f5e..565fb184dd3 100644 --- a/build/Common.props +++ b/build/Common.props @@ -45,6 +45,7 @@ [1.1.1,2.0) [0.12.1,0.13) 1.3.2 + 1.0.0-beta.1 [2.8.0,3.0) [1.2.0-beta.435,2.0) 1.4.0 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj index 4c152e42d23..fc3289cab61 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj @@ -30,6 +30,7 @@ + diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index 289c0fec8b3..df1243ed70e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -183,6 +183,16 @@ public Uri Endpoint /// public Func HttpClientFactory { get; set; } + /// + /// Gets or sets the directory for offline storage. + /// + public string StorageDirectory { get; set; } + + /// + /// Gets or sets a value indicating whether offline storage should be used. + /// + public bool EnableOfflineStorage { get; set; } + /// /// Gets a value indicating whether was modified via its setter. /// From eb70d8958cc6dcbf98c879dd7d14e5b20abd746f Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 30 Jan 2023 17:10:59 -0800 Subject: [PATCH 02/49] Add publicApi --- .../.publicApi/net462/PublicAPI.Unshipped.txt | 4 ++++ .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 4 ++++ .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 4 ++++ .../.publicApi/netstandard2.1/PublicAPI.Unshipped.txt | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt index d54151c394a..94356eb50aa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,3 +1,7 @@ +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt index d54151c394a..94356eb50aa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -1,3 +1,7 @@ +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index d54151c394a..94356eb50aa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,3 +1,7 @@ +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index d54151c394a..94356eb50aa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,3 +1,7 @@ +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string +OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool +OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder From e0b301309dd1bfdaeeb97b7ce675dd221c1a15ac Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 31 Jan 2023 13:09:28 -0800 Subject: [PATCH 03/49] Update OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj --- .../OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj index fc3289cab61..a30fb3529db 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj @@ -30,7 +30,7 @@ - + From 2593a5cdddead8158f675da8d9e30c4a6576930c Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 31 Jan 2023 15:44:59 -0800 Subject: [PATCH 04/49] Switch to service DI --- examples/Console/Examples.Console.csproj | 1 + examples/Console/TestOtlpExporter.cs | 4 ++++ .../OtlpExporterOptions.cs | 10 ---------- .../OtlpMetricExporterExtensions.cs | 10 ++++++++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj index 59cff3d55ad..c7d7507ba8d 100644 --- a/examples/Console/Examples.Console.csproj +++ b/examples/Console/Examples.Console.csproj @@ -21,6 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 53e6b1a7243..b2a6afbf6a1 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -14,8 +14,11 @@ // limitations under the License. // +using Microsoft.Extensions.DependencyInjection; using OpenTelemetry; using OpenTelemetry.Exporter; +using OpenTelemetry.Extensions.PersistentStorage; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -71,6 +74,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) + .ConfigureServices(services => services.AddSingleton(sp => new FileBlobProvider("/tmp/otel"))) .AddOtlpExporter(opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index df1243ed70e..289c0fec8b3 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -183,16 +183,6 @@ public Uri Endpoint /// public Func HttpClientFactory { get; set; } - /// - /// Gets or sets the directory for offline storage. - /// - public string StorageDirectory { get; set; } - - /// - /// Gets or sets a value indicating whether offline storage should be used. - /// - public bool EnableOfflineStorage { get; set; } - /// /// Gets a value indicating whether was modified via its setter. /// diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index b965fff68c0..e3b18fbccdb 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -14,9 +14,12 @@ // limitations under the License. // +using System.Reflection; +using System.Runtime.Intrinsics.X86; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Internal; namespace OpenTelemetry.Metrics @@ -156,6 +159,13 @@ internal static MeterProviderBuilder AddOtlpExporter( metricExporter = configureExporterInstance(metricExporter); } + var persistentStorage = serviceProvider.GetService(typeof(PersistentBlobProvider)); + + if (persistentStorage != null) + { + // TODO + } + var metricReader = PeriodicExportingMetricReaderHelper.CreatePeriodicExportingMetricReader( metricExporter, metricReaderOptions); From b5e870ab0508221fc5913f399d72922414aa2894 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 31 Jan 2023 15:56:43 -0800 Subject: [PATCH 05/49] remove no longer needed public api additions --- .../.publicApi/net462/PublicAPI.Unshipped.txt | 4 ---- .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 4 ---- .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 4 ---- .../.publicApi/netstandard2.1/PublicAPI.Unshipped.txt | 4 ---- 4 files changed, 16 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt index 94356eb50aa..d54151c394a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,7 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt index 94356eb50aa..d54151c394a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -1,7 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 94356eb50aa..d54151c394a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,7 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index 94356eb50aa..d54151c394a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,7 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.get -> string -OpenTelemetry.Exporter.OtlpExporterOptions.StorageDirectory.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.get -> bool -OpenTelemetry.Exporter.OtlpExporterOptions.EnableOfflineStorage.set -> void static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder *REMOVED*static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder From 5253e11b5803947d377056ad8a106db7062b08c2 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 2 Feb 2023 10:45:54 -0800 Subject: [PATCH 06/49] move to trace exporter --- .../OtlpMetricExporterExtensions.cs | 10 ---------- .../OtlpTraceExporterHelperExtensions.cs | 8 ++++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index b50454be03d..80979dd38f9 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -14,12 +14,9 @@ // limitations under the License. // -using System.Reflection; -using System.Runtime.Intrinsics.X86; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Internal; namespace OpenTelemetry.Metrics @@ -157,13 +154,6 @@ internal static MetricReader BuildOtlpExporterMetricReader( metricExporter = configureExporterInstance(metricExporter); } - var persistentStorage = serviceProvider.GetService(typeof(PersistentBlobProvider)); - - if (persistentStorage != null) - { - // TODO - } - return PeriodicExportingMetricReaderHelper.CreatePeriodicExportingMetricReader( metricExporter, metricReaderOptions); diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 728ce1f503a..e03e55782c9 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -19,6 +19,7 @@ using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Internal; namespace OpenTelemetry.Trace @@ -113,6 +114,13 @@ internal static BaseProcessor BuildOtlpExporterProcessor( otlpExporter = configureExporterInstance(otlpExporter); } + var persistentStorage = serviceProvider.GetService(typeof(PersistentBlobProvider)); + + if (persistentStorage != null) + { + // TODO + } + if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple) { return new SimpleActivityExportProcessor(otlpExporter); From 86acbb209d90d887c7d0ca06152ea53b5cdb433e Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Fri, 3 Feb 2023 17:30:46 -0800 Subject: [PATCH 07/49] Update TestOtlpExporter.cs --- examples/Console/TestOtlpExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index b2a6afbf6a1..e174b69a1fb 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -74,7 +74,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) - .ConfigureServices(services => services.AddSingleton(sp => new FileBlobProvider("/tmp/otel"))) + .ConfigureServices(services => services.AddSingleton(sp => new FileBlobProvider("C:\\tmp"))) .AddOtlpExporter(opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. From a8aacfa48d055e38fef03766514074c1cbf52fb5 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Sat, 4 Feb 2023 01:19:52 -0800 Subject: [PATCH 08/49] otlp grpc trace export client has access to persistentblobprovider now --- .../ExportClient/BaseOtlpGrpcExportClient.cs | 6 +++++- .../ExportClient/OtlpGrpcTraceExportClient.cs | 11 +++++++++-- .../OtlpExporterOptionsExtensions.cs | 5 +++-- .../OtlpTraceExporter.cs | 7 +++++-- .../OtlpTraceExporterHelperExtensions.cs | 10 ++-------- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs index bc833bea2d0..e777811486e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs @@ -15,6 +15,7 @@ // using Grpc.Core; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Internal; #if NETSTANDARD2_1 || NET6_0_OR_GREATER using Grpc.Net.Client; @@ -26,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie /// Type of export request. internal abstract class BaseOtlpGrpcExportClient : IExportClient { - protected BaseOtlpGrpcExportClient(OtlpExporterOptions options) + protected BaseOtlpGrpcExportClient(OtlpExporterOptions options, PersistentBlobProvider persistentBlobProvider = null) { Guard.ThrowIfNull(options); Guard.ThrowIfInvalidTimeout(options.TimeoutMilliseconds); @@ -36,6 +37,7 @@ protected BaseOtlpGrpcExportClient(OtlpExporterOptions options) this.Endpoint = new UriBuilder(options.Endpoint).Uri; this.Headers = options.GetMetadataFromHeaders(); this.TimeoutMilliseconds = options.TimeoutMilliseconds; + this.PersistentBlobProvider = persistentBlobProvider; } #if NETSTANDARD2_1 || NET6_0_OR_GREATER @@ -50,6 +52,8 @@ protected BaseOtlpGrpcExportClient(OtlpExporterOptions options) internal int TimeoutMilliseconds { get; } + internal PersistentBlobProvider PersistentBlobProvider { get; } + /// public abstract bool SendExportRequest(TRequest request, CancellationToken cancellationToken = default); diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index b4c9084cd2c..f2a14a9f20a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -14,7 +14,9 @@ // limitations under the License. // +using Google.Protobuf; using Grpc.Core; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient @@ -24,8 +26,8 @@ internal sealed class OtlpGrpcTraceExportClient : BaseOtlpGrpcExportClient(this OtlpExporterOptions options, Ac return headers; } - public static IExportClient GetTraceExportClient(this OtlpExporterOptions options) => + public static IExportClient GetTraceExportClient(this OtlpExporterOptions options, PersistentBlobProvider persistentBlobProvider = null) => options.Protocol switch { - OtlpExportProtocol.Grpc => new OtlpGrpcTraceExportClient(options), + OtlpExportProtocol.Grpc => new OtlpGrpcTraceExportClient(options, null, persistentBlobProvider), OtlpExportProtocol.HttpProtobuf => new OtlpHttpTraceExportClient( options, options.HttpClientFactory?.Invoke() ?? throw new InvalidOperationException("OtlpExporterOptions was missing HttpClientFactory or it returned null.")), diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index b6d64c2fbac..f2f6cbd8410 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -17,6 +17,7 @@ using System.Diagnostics; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; using OtlpResource = OpenTelemetry.Proto.Resource.V1; @@ -48,10 +49,12 @@ public OtlpTraceExporter(OtlpExporterOptions options) /// . /// . /// Client used for sending export request. + /// . internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, - IExportClient exportClient = null) + IExportClient exportClient = null, + PersistentBlobProvider persistentBlobProvider = null) { Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); @@ -64,7 +67,7 @@ internal OtlpTraceExporter( } else { - this.exportClient = exporterOptions.GetTraceExportClient(); + this.exportClient = exporterOptions.GetTraceExportClient(persistentBlobProvider); } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index e03e55782c9..781660c2d9e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -107,20 +107,14 @@ internal static BaseProcessor BuildOtlpExporterProcessor( { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions); + PersistentBlobProvider persistentBlobProvider = serviceProvider.GetService(); + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentBlobProvider); if (configureExporterInstance != null) { otlpExporter = configureExporterInstance(otlpExporter); } - var persistentStorage = serviceProvider.GetService(typeof(PersistentBlobProvider)); - - if (persistentStorage != null) - { - // TODO - } - if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple) { return new SimpleActivityExportProcessor(otlpExporter); From 5012cd6cd7d6c32c72c97fc6e3a669d381e1d47c Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Sat, 4 Feb 2023 02:02:53 -0800 Subject: [PATCH 09/49] Update OtlpGrpcTraceExportClient.cs --- .../Implementation/ExportClient/OtlpGrpcTraceExportClient.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index f2a14a9f20a..da926017463 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using Google.Protobuf; using Grpc.Core; using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; From 141bc864966f63437528b0490cf969933000c8cd Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Sat, 4 Feb 2023 02:59:00 -0800 Subject: [PATCH 10/49] null check --- .../OtlpTraceExporterHelperExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 781660c2d9e..93077f90e6d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -107,7 +107,7 @@ internal static BaseProcessor BuildOtlpExporterProcessor( { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - PersistentBlobProvider persistentBlobProvider = serviceProvider.GetService(); + PersistentBlobProvider persistentBlobProvider = serviceProvider?.GetService(); BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentBlobProvider); if (configureExporterInstance != null) From ceed9cc01e599070e14006660adb5d7c70fff3e8 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 9 Feb 2023 13:45:50 -0800 Subject: [PATCH 11/49] test --- examples/Console/TestOtlpExporter.cs | 9 +++---- .../OtlpTraceExporter.cs | 6 ++--- .../OtlpTraceExporterHelperExtensions.cs | 25 +++++++++++++------ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index e174b69a1fb..e5ac1ee9a90 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -14,11 +14,9 @@ // limitations under the License. // -using Microsoft.Extensions.DependencyInjection; using OpenTelemetry; using OpenTelemetry.Exporter; using OpenTelemetry.Extensions.PersistentStorage; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -74,8 +72,8 @@ private static object RunWithActivitySource(string endpoint, string protocol) using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) - .ConfigureServices(services => services.AddSingleton(sp => new FileBlobProvider("C:\\tmp"))) - .AddOtlpExporter(opt => + .AddOtlpExporter( + opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. if (!string.IsNullOrEmpty(endpoint)) @@ -86,7 +84,8 @@ private static object RunWithActivitySource(string endpoint, string protocol) opt.Protocol = otlpExportProtocol.Value; System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); - }) + }, + () => new FileBlobProvider("C:\\tmp")) .Build(); // The above line is required only in Applications diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index f2f6cbd8410..9032d09620e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -49,12 +49,12 @@ public OtlpTraceExporter(OtlpExporterOptions options) /// . /// . /// Client used for sending export request. - /// . + /// . internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IExportClient exportClient = null, - PersistentBlobProvider persistentBlobProvider = null) + Func persistentStorageFactory = null) { Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); @@ -67,7 +67,7 @@ internal OtlpTraceExporter( } else { - this.exportClient = exporterOptions.GetTraceExportClient(persistentBlobProvider); + this.exportClient = exporterOptions.GetTraceExportClient(persistentStorageFactory()); } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 93077f90e6d..24e723f0d87 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -35,7 +35,7 @@ public static class OtlpTraceExporterHelperExtensions /// builder to use. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder) - => AddOtlpExporter(builder, name: null, configure: null); + => AddOtlpExporter(builder, name: null, configure: null, persistentStorageFactory: null); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -44,7 +44,16 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure) - => AddOtlpExporter(builder, name: null, configure); + => AddOtlpExporter(builder, name: null, configure, null); + + /// + /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. + /// + /// builder to use. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure, Func persistentStorageFactory) + => AddOtlpExporter(builder, name: null, configure, persistentStorageFactory); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -52,11 +61,13 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// builder to use. /// Name which is used when retrieving options. /// Callback action for configuring . + /// TODO. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, string name, - Action configure) + Action configure, + Func persistentStorageFactory = null) { Guard.ThrowIfNull(builder); @@ -95,7 +106,7 @@ public static TracerProviderBuilder AddOtlpExporter( // instance. var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null, persistentStorageFactory); }); } @@ -103,12 +114,12 @@ internal static BaseProcessor BuildOtlpExporterProcessor( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, - Func, BaseExporter> configureExporterInstance = null) + Func, BaseExporter> configureExporterInstance = null, + Func persistentStorageFactory = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - PersistentBlobProvider persistentBlobProvider = serviceProvider?.GetService(); - BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentBlobProvider); + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentStorageFactory); if (configureExporterInstance != null) { From dd099ce843985040964c3c9826752ee053adf874 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 9 Feb 2023 14:57:06 -0800 Subject: [PATCH 12/49] add serviceprovider --- examples/Console/TestOtlpExporter.cs | 2 +- .../OtlpTraceExporter.cs | 4 ++-- .../OtlpTraceExporterHelperExtensions.cs | 20 ++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index e5ac1ee9a90..e25d1286d87 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -85,7 +85,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); }, - () => new FileBlobProvider("C:\\tmp")) + services => new FileBlobProvider("C:\\tmp")) .Build(); // The above line is required only in Applications diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index 9032d09620e..3b59314524e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -54,7 +54,7 @@ internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IExportClient exportClient = null, - Func persistentStorageFactory = null) + PersistentBlobProvider persistentBlobProvider = null) { Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); @@ -67,7 +67,7 @@ internal OtlpTraceExporter( } else { - this.exportClient = exporterOptions.GetTraceExportClient(persistentStorageFactory()); + this.exportClient = exporterOptions.GetTraceExportClient(persistentBlobProvider); } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 24e723f0d87..9e1757c318d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -14,6 +14,7 @@ // limitations under the License. // +using System; using System.Diagnostics; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -51,8 +52,9 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// /// builder to use. /// Callback action for configuring . + /// Factory for creating an offline storage implementation. /// The instance of to chain the calls. - public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure, Func persistentStorageFactory) + public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure, Func persistentStorageFactory) => AddOtlpExporter(builder, name: null, configure, persistentStorageFactory); /// @@ -67,7 +69,7 @@ public static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, string name, Action configure, - Func persistentStorageFactory = null) + Func persistentStorageFactory = null) { Guard.ThrowIfNull(builder); @@ -100,26 +102,34 @@ public static TracerProviderBuilder AddOtlpExporter( configure(exporterOptions); } + PersistentBlobProvider persistentBlobProvider = null; + if (persistentStorageFactory != null) + { + persistentBlobProvider = persistentStorageFactory(sp); + } + // Note: Not using finalOptionsName here for SdkLimitOptions. // There should only be one provider for a given service // collection so SdkLimitOptions is treated as a single default // instance. var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null, persistentStorageFactory); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null, persistentBlobProvider); }); } + // TODO: AddOtlpExporterWithPersistenStorage + internal static BaseProcessor BuildOtlpExporterProcessor( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, Func, BaseExporter> configureExporterInstance = null, - Func persistentStorageFactory = null) + PersistentBlobProvider persistentBlobProvider = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentStorageFactory); + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentBlobProvider); if (configureExporterInstance != null) { From 7701bd603081a4f6b0edeb13d5b1c66d03a04740 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 9 Feb 2023 15:03:22 -0800 Subject: [PATCH 13/49] cleanup --- .../OtlpTraceExporter.cs | 2 +- .../OtlpTraceExporterHelperExtensions.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index 3b59314524e..f2f6cbd8410 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -49,7 +49,7 @@ public OtlpTraceExporter(OtlpExporterOptions options) /// . /// . /// Client used for sending export request. - /// . + /// . internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 9e1757c318d..3917dce1b79 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using System; using System.Diagnostics; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; From 3e95109f6f3199a8e66c591b3d173a706333f9b8 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 9 Feb 2023 15:15:14 -0800 Subject: [PATCH 14/49] Update TestOtlpExporter.cs --- examples/Console/TestOtlpExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index e25d1286d87..05b82a840e0 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -85,7 +85,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); }, - services => new FileBlobProvider("C:\\tmp")) + _ => new FileBlobProvider("C:\\tmp")) .Build(); // The above line is required only in Applications From fbc63e17858ebd222b9195e102a39fd6aec01a41 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 9 Feb 2023 15:25:32 -0800 Subject: [PATCH 15/49] Update OtlpTraceExporterHelperExtensions.cs --- .../OtlpTraceExporterHelperExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 3917dce1b79..b116b3fc449 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -62,7 +62,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// builder to use. /// Name which is used when retrieving options. /// Callback action for configuring . - /// TODO. + /// Factory for creating an offline storage implementation. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, From 557f2a79fb91ea1e25e6978d1783d8c5540d8f6f Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 9 Feb 2023 15:59:52 -0800 Subject: [PATCH 16/49] move persistentstorage factory call 1 function deeper --- .../OtlpTraceExporterHelperExtensions.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index b116b3fc449..a635044b72c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -44,7 +44,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure) - => AddOtlpExporter(builder, name: null, configure, null); + => AddOtlpExporter(builder, name: null, configure, persistentStorageFactory: null); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -101,19 +101,13 @@ public static TracerProviderBuilder AddOtlpExporter( configure(exporterOptions); } - PersistentBlobProvider persistentBlobProvider = null; - if (persistentStorageFactory != null) - { - persistentBlobProvider = persistentStorageFactory(sp); - } - // Note: Not using finalOptionsName here for SdkLimitOptions. // There should only be one provider for a given service // collection so SdkLimitOptions is treated as a single default // instance. var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null, persistentBlobProvider); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null, persistentStorageFactory); }); } @@ -124,10 +118,16 @@ internal static BaseProcessor BuildOtlpExporterProcessor( SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, Func, BaseExporter> configureExporterInstance = null, - PersistentBlobProvider persistentBlobProvider = null) + Func persistentStorageFactory = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); + PersistentBlobProvider persistentBlobProvider = null; + if (persistentStorageFactory != null) + { + persistentBlobProvider = persistentStorageFactory(serviceProvider); + } + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentBlobProvider); if (configureExporterInstance != null) From 72a55fac54abb65ceab65653e2eba314c53e5493 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 13 Feb 2023 15:34:33 -0800 Subject: [PATCH 17/49] move to new package --- OpenTelemetry.sln | 6 ++ examples/Console/Examples.Console.csproj | 17 ++-- examples/Console/TestOtlpExporter.cs | 10 ++- ...TelemetryProtocol.PersistentStorage.csproj | 15 ++++ ...orterOptionsPersistentStorageExtensions.cs | 77 +++++++++++++++++++ .../AssemblyInfo.cs | 3 + .../ExportClient/BaseOtlpGrpcExportClient.cs | 4 +- .../ExportClient/OtlpGrpcTraceExportClient.cs | 4 +- .../OtlpExporterOptions.cs | 7 ++ .../OtlpExporterOptionsExtensions.cs | 5 +- .../OtlpTraceExporter.cs | 7 +- .../OtlpTraceExporterHelperExtensions.cs | 25 ++---- 12 files changed, 139 insertions(+), 41 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs diff --git a/OpenTelemetry.sln b/OpenTelemetry.sln index 0532a56ca84..09180a7e6fb 100644 --- a/OpenTelemetry.sln +++ b/OpenTelemetry.sln @@ -249,6 +249,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-console", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-jaeger", "docs\trace\getting-started-jaeger\getting-started-jaeger.csproj", "{A0C0B77C-6C7B-4EC2-AC61-EA1F489811B9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage", "src\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj", "{2DA349A7-814F-43A6-AA22-28D03421EAF7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -523,6 +525,10 @@ Global {A0C0B77C-6C7B-4EC2-AC61-EA1F489811B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {A0C0B77C-6C7B-4EC2-AC61-EA1F489811B9}.Release|Any CPU.ActiveCfg = Release|Any CPU {A0C0B77C-6C7B-4EC2-AC61-EA1F489811B9}.Release|Any CPU.Build.0 = Release|Any CPU + {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj index c7d7507ba8d..e487ddd404e 100644 --- a/examples/Console/Examples.Console.csproj +++ b/examples/Console/Examples.Console.csproj @@ -27,17 +27,18 @@ - - + + + + + + + + + - - - - - - diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 05b82a840e0..521d210a40f 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -16,6 +16,7 @@ using OpenTelemetry; using OpenTelemetry.Exporter; +using OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; using OpenTelemetry.Extensions.PersistentStorage; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -67,12 +68,15 @@ private static object RunWithActivitySource(string endpoint, string protocol) otlpExportProtocol = OtlpExportProtocol.Grpc; } + var storagePath = Path.GetTempPath(); + // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use OTLP exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) - .AddOtlpExporter( + .AddOtlpExporterWithPersistentStorage( + "name", opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. @@ -83,9 +87,9 @@ private static object RunWithActivitySource(string endpoint, string protocol) opt.Protocol = otlpExportProtocol.Value; - System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); + System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint} and storage path {storagePath}"); }, - _ => new FileBlobProvider("C:\\tmp")) + _ => new FileBlobProvider(storagePath)) .Build(); // The above line is required only in Applications diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj new file mode 100644 index 00000000000..6427f8c0604 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj @@ -0,0 +1,15 @@ + + + + + net6.0;netstandard2.1;netstandard2.0;net462 + OpenTelemetry protocol exporter persistent storage for OpenTelemetry .NET + $(PackageTags);OTLP + core- + + + + + + + diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs new file mode 100644 index 00000000000..8e6a3ad6af8 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs @@ -0,0 +1,77 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; +using OpenTelemetry.Internal; +using OpenTelemetry.Trace; + +namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; + +/// +/// Extension methods to simplify registering of the OpenTelemetry Protocol (OTLP) exporter +/// with persistent storage. +/// +public static class OtlpExporterOptionsPersistentStorageExtensions +{ + /// + /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider + /// with access to persistent storage. + /// + /// builder to use. + /// Name which is used when retrieving options. + /// Callback action for configuring . + /// Factory function to create a . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( + this TracerProviderBuilder builder, + string name, + Action configure, + Func persistentStorageFactory) + { + Guard.ThrowIfNull(builder); + Guard.ThrowIfNull(persistentStorageFactory); + + var finalOptionsName = name ?? Options.DefaultName; + + builder.ConfigureServices(services => + { + if (name != null && configure != null) + { + services.Configure(finalOptionsName, configure); + } + + OtlpExporterOptions.RegisterOtlpExporterOptionsFactory(services); + services.RegisterOptionsFactory(configuration => new SdkLimitOptions(configuration)); + }); + + return builder.AddProcessor(sp => + { + var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + + if (name == null && configure != null) + { + configure(exporterOptions); + } + + exporterOptions.PersistentBlobProvider = persistentStorageFactory(sp); + var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; + return OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null); + }); + } +} diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs index 44e26f37879..31fa4191e04 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs @@ -21,6 +21,7 @@ [assembly: InternalsVisibleTo("Benchmarks, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] [assembly: InternalsVisibleTo("MockOpenTelemetryCollector, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] +[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] // Used by Moq. [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] @@ -28,6 +29,8 @@ [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests")] [assembly: InternalsVisibleTo("Benchmarks")] [assembly: InternalsVisibleTo("MockOpenTelemetryCollector")] +[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs")] +[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage")] // Used by Moq. [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs index e777811486e..616ec284db0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/BaseOtlpGrpcExportClient.cs @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie /// Type of export request. internal abstract class BaseOtlpGrpcExportClient : IExportClient { - protected BaseOtlpGrpcExportClient(OtlpExporterOptions options, PersistentBlobProvider persistentBlobProvider = null) + protected BaseOtlpGrpcExportClient(OtlpExporterOptions options) { Guard.ThrowIfNull(options); Guard.ThrowIfInvalidTimeout(options.TimeoutMilliseconds); @@ -37,7 +37,7 @@ protected BaseOtlpGrpcExportClient(OtlpExporterOptions options, PersistentBlobPr this.Endpoint = new UriBuilder(options.Endpoint).Uri; this.Headers = options.GetMetadataFromHeaders(); this.TimeoutMilliseconds = options.TimeoutMilliseconds; - this.PersistentBlobProvider = persistentBlobProvider; + this.PersistentBlobProvider = options.PersistentBlobProvider; } #if NETSTANDARD2_1 || NET6_0_OR_GREATER diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index da926017463..42a77f23738 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -25,8 +25,8 @@ internal sealed class OtlpGrpcTraceExportClient : BaseOtlpGrpcExportClient internal bool ProgrammaticallyModifiedEndpoint { get; private set; } + /// + /// Gets or sets the used at + /// runtime to save data from retryable errors to offline storage. + /// + internal PersistentBlobProvider PersistentBlobProvider { get; set; } + internal static void RegisterOtlpExporterOptionsFactory(IServiceCollection services) { services.RegisterOptionsFactory( diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index a3eba555348..9ecef28f071 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -20,7 +20,6 @@ using System.Reflection; using Grpc.Core; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; #if NETSTANDARD2_1 || NET6_0_OR_GREATER using Grpc.Net.Client; #endif @@ -98,10 +97,10 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac return headers; } - public static IExportClient GetTraceExportClient(this OtlpExporterOptions options, PersistentBlobProvider persistentBlobProvider = null) => + public static IExportClient GetTraceExportClient(this OtlpExporterOptions options) => options.Protocol switch { - OtlpExportProtocol.Grpc => new OtlpGrpcTraceExportClient(options, null, persistentBlobProvider), + OtlpExportProtocol.Grpc => new OtlpGrpcTraceExportClient(options, null), OtlpExportProtocol.HttpProtobuf => new OtlpHttpTraceExportClient( options, options.HttpClientFactory?.Invoke() ?? throw new InvalidOperationException("OtlpExporterOptions was missing HttpClientFactory or it returned null.")), diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index f2f6cbd8410..b6d64c2fbac 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -17,7 +17,6 @@ using System.Diagnostics; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; using OtlpResource = OpenTelemetry.Proto.Resource.V1; @@ -49,12 +48,10 @@ public OtlpTraceExporter(OtlpExporterOptions options) /// . /// . /// Client used for sending export request. - /// . internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, - IExportClient exportClient = null, - PersistentBlobProvider persistentBlobProvider = null) + IExportClient exportClient = null) { Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); @@ -67,7 +64,7 @@ internal OtlpTraceExporter( } else { - this.exportClient = exporterOptions.GetTraceExportClient(persistentBlobProvider); + this.exportClient = exporterOptions.GetTraceExportClient(); } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index a635044b72c..45b4070ea77 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -35,7 +35,7 @@ public static class OtlpTraceExporterHelperExtensions /// builder to use. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder) - => AddOtlpExporter(builder, name: null, configure: null, persistentStorageFactory: null); + => AddOtlpExporter(builder, name: null, configure: null); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -44,7 +44,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure) - => AddOtlpExporter(builder, name: null, configure, persistentStorageFactory: null); + => AddOtlpExporter(builder, name: null, configure); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -54,7 +54,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// Factory for creating an offline storage implementation. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure, Func persistentStorageFactory) - => AddOtlpExporter(builder, name: null, configure, persistentStorageFactory); + => AddOtlpExporter(builder, name: null, configure); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -62,13 +62,11 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// builder to use. /// Name which is used when retrieving options. /// Callback action for configuring . - /// Factory for creating an offline storage implementation. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, string name, - Action configure, - Func persistentStorageFactory = null) + Action configure) { Guard.ThrowIfNull(builder); @@ -107,28 +105,19 @@ public static TracerProviderBuilder AddOtlpExporter( // instance. var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null, persistentStorageFactory); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null); }); } - // TODO: AddOtlpExporterWithPersistenStorage - internal static BaseProcessor BuildOtlpExporterProcessor( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, - Func, BaseExporter> configureExporterInstance = null, - Func persistentStorageFactory = null) + Func, BaseExporter> configureExporterInstance = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - PersistentBlobProvider persistentBlobProvider = null; - if (persistentStorageFactory != null) - { - persistentBlobProvider = persistentStorageFactory(serviceProvider); - } - - BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null, persistentBlobProvider); + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null); if (configureExporterInstance != null) { From 6a098a73520db933ed03fd07913031e31d0298cb Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 13 Feb 2023 15:51:56 -0800 Subject: [PATCH 18/49] Update OtlpGrpcTraceExportClient.cs --- .../Implementation/ExportClient/OtlpGrpcTraceExportClient.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index 42a77f23738..3e75a392008 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -15,7 +15,6 @@ // using Grpc.Core; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient From 6b6621a9cd885471e96621a506e82cb76f11a379 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 13 Feb 2023 16:21:53 -0800 Subject: [PATCH 19/49] api --- .../.publicApi/net462/PublicAPI.Shipped.txt | 1 + .../.publicApi/net462/PublicAPI.Unshipped.txt | 0 .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 0 .../.publicApi/netstandard2.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 0 .../.publicApi/netstandard2.1/PublicAPI.Shipped.txt | 1 + .../.publicApi/netstandard2.1/PublicAPI.Unshipped.txt | 0 8 files changed, 4 insertions(+) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt new file mode 100644 index 00000000000..e7be5ddf7f5 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Unshipped.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt new file mode 100644 index 00000000000..e7be5ddf7f5 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Unshipped.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt new file mode 100644 index 00000000000..e7be5ddf7f5 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt new file mode 100644 index 00000000000..e7be5ddf7f5 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt new file mode 100644 index 00000000000..e69de29bb2d From be2b95f6b0163753b1b19725c278c87308e331f3 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 14 Feb 2023 14:56:23 -0800 Subject: [PATCH 20/49] undo changes to otlptraceexporterhelperextensions --- .../OtlpTraceExporterHelperExtensions.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 45b4070ea77..728ce1f503a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -19,7 +19,6 @@ using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Internal; namespace OpenTelemetry.Trace @@ -46,16 +45,6 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure) => AddOtlpExporter(builder, name: null, configure); - /// - /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. - /// - /// builder to use. - /// Callback action for configuring . - /// Factory for creating an offline storage implementation. - /// The instance of to chain the calls. - public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure, Func persistentStorageFactory) - => AddOtlpExporter(builder, name: null, configure); - /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. /// @@ -105,7 +94,7 @@ public static TracerProviderBuilder AddOtlpExporter( // instance. var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); }); } @@ -117,7 +106,7 @@ internal static BaseProcessor BuildOtlpExporterProcessor( { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions, null); + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions); if (configureExporterInstance != null) { From 3eb6da3e4f43c2e87390ff66640f7555e887e171 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 14 Feb 2023 14:59:13 -0800 Subject: [PATCH 21/49] Update Examples.Console.csproj --- examples/Console/Examples.Console.csproj | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj index e487ddd404e..80994343743 100644 --- a/examples/Console/Examples.Console.csproj +++ b/examples/Console/Examples.Console.csproj @@ -27,18 +27,18 @@ - + + - - - - - - - - + + + + + + + From 075cae0f172285219af6bbc8d1985e6ac00e408d Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 14 Feb 2023 15:03:23 -0800 Subject: [PATCH 22/49] Update OtlpExporterOptionsExtensions.cs --- .../OtlpExporterOptionsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 9ecef28f071..c4aa08f23d5 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -100,7 +100,7 @@ public static THeaders GetHeaders(this OtlpExporterOptions options, Ac public static IExportClient GetTraceExportClient(this OtlpExporterOptions options) => options.Protocol switch { - OtlpExportProtocol.Grpc => new OtlpGrpcTraceExportClient(options, null), + OtlpExportProtocol.Grpc => new OtlpGrpcTraceExportClient(options), OtlpExportProtocol.HttpProtobuf => new OtlpHttpTraceExportClient( options, options.HttpClientFactory?.Invoke() ?? throw new InvalidOperationException("OtlpExporterOptions was missing HttpClientFactory or it returned null.")), From 097344413ee6caed5c8256286dc061d964dd378d Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Tue, 14 Feb 2023 15:44:13 -0800 Subject: [PATCH 23/49] delete api line --- .../.publicApi/net462/PublicAPI.Shipped.txt | 1 - .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 - .../.publicApi/netstandard2.0/PublicAPI.Shipped.txt | 1 - .../.publicApi/netstandard2.1/PublicAPI.Shipped.txt | 1 - 4 files changed, 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt index e7be5ddf7f5..e69de29bb2d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt @@ -1 +0,0 @@ -static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt index e7be5ddf7f5..e69de29bb2d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -1 +0,0 @@ -static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt index e7be5ddf7f5..e69de29bb2d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -1 +0,0 @@ -static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt index e7be5ddf7f5..e69de29bb2d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt @@ -1 +0,0 @@ -static OpenTelemetry.Trace.OtlpTraceExporterExtensions.AddOtlpExporterWithPersistentStorage(this OpenTelemetry.Trace.TraceProviderBuilder builder, string name, Action persistentStorageFactory>) -> OpenTelemetry.Trace.TraceProviderBuilder From a0b41f7f9dcb1af3a771566bdbf7e18365f98478 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 13:36:10 -0800 Subject: [PATCH 24/49] reanme --- ...nsions.cs => OtlpExporterPersistentStorageExtensions.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/{OtlpExporterOptionsPersistentStorageExtensions.cs => OtlpExporterPersistentStorageExtensions.cs} (92%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs similarity index 92% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs index 8e6a3ad6af8..44713aa6ef0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; /// Extension methods to simplify registering of the OpenTelemetry Protocol (OTLP) exporter /// with persistent storage. /// -public static class OtlpExporterOptionsPersistentStorageExtensions +public static class OtlpExporterPersistentStorageExtensions { /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider @@ -69,7 +69,7 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( configure(exporterOptions); } - exporterOptions.PersistentBlobProvider = persistentStorageFactory(sp); + exporterOptions.PersistentStorageFactory = persistentStorageFactory; var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; return OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null); }); From c7e203473af920a6ecfec66437c70ad18a744413 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 14:15:15 -0800 Subject: [PATCH 25/49] Revert "reanme" This reverts commit a0b41f7f9dcb1af3a771566bdbf7e18365f98478. --- ...cs => OtlpExporterOptionsPersistentStorageExtensions.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/{OtlpExporterPersistentStorageExtensions.cs => OtlpExporterOptionsPersistentStorageExtensions.cs} (92%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs similarity index 92% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs index 44713aa6ef0..8e6a3ad6af8 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; /// Extension methods to simplify registering of the OpenTelemetry Protocol (OTLP) exporter /// with persistent storage. /// -public static class OtlpExporterPersistentStorageExtensions +public static class OtlpExporterOptionsPersistentStorageExtensions { /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider @@ -69,7 +69,7 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( configure(exporterOptions); } - exporterOptions.PersistentStorageFactory = persistentStorageFactory; + exporterOptions.PersistentBlobProvider = persistentStorageFactory(sp); var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; return OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null); }); From 906a520231780dea2ec29b23b0335b522d8972cd Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 14:18:14 -0800 Subject: [PATCH 26/49] remove api --- .../.publicApi/net462/PublicAPI.Shipped.txt | 0 .../.publicApi/net462/PublicAPI.Unshipped.txt | 0 .../.publicApi/net6.0/PublicAPI.Shipped.txt | 0 .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 0 .../.publicApi/netstandard2.0/PublicAPI.Shipped.txt | 0 .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 0 .../.publicApi/netstandard2.1/PublicAPI.Shipped.txt | 0 .../.publicApi/netstandard2.1/PublicAPI.Unshipped.txt | 0 8 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Unshipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Unshipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Shipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net462/PublicAPI.Unshipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Shipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/net6.0/PublicAPI.Unshipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Shipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Shipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt deleted file mode 100644 index e69de29bb2d..00000000000 From 519b42c399f6f5b6f9813fb70fd2c09322064fde Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 14:19:05 -0800 Subject: [PATCH 27/49] Update TestOtlpExporter.cs --- examples/Console/TestOtlpExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 521d210a40f..9e3367fbea0 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -76,7 +76,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) .AddOtlpExporterWithPersistentStorage( - "name", + null, opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. From 125b52346a9a724d77d5fa04c67066fdf0195e05 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 14:21:30 -0800 Subject: [PATCH 28/49] rename and remove null --- ...nsions.cs => OtlpExporterPersistentStorageExtensions.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/{OtlpExporterOptionsPersistentStorageExtensions.cs => OtlpExporterPersistentStorageExtensions.cs} (93%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs similarity index 93% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs index 8e6a3ad6af8..63077c0939f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterOptionsPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; /// Extension methods to simplify registering of the OpenTelemetry Protocol (OTLP) exporter /// with persistent storage. /// -public static class OtlpExporterOptionsPersistentStorageExtensions +public static class OtlpExporterPersistentStorageExtensions { /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider @@ -71,7 +71,7 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( exporterOptions.PersistentBlobProvider = persistentStorageFactory(sp); var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp, null); + return OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); }); } } From 5c34096a11df2282aa1e39966fa7f2249cc181f2 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 14:22:40 -0800 Subject: [PATCH 29/49] Update AssemblyInfo.cs --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs index 31fa4191e04..5cd08436353 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs @@ -29,7 +29,6 @@ [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests")] [assembly: InternalsVisibleTo("Benchmarks")] [assembly: InternalsVisibleTo("MockOpenTelemetryCollector")] -[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs")] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage")] // Used by Moq. From 70c1396ff585fef2639302cd2a6d7c461e000b49 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 15:08:39 -0800 Subject: [PATCH 30/49] Update OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj --- ...y.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj index 6427f8c0604..e532095d450 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj @@ -8,6 +8,11 @@ core- + + + false + + From 9be4d8732c18ebf6ec4b827740c5b4608096c500 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 16:45:36 -0800 Subject: [PATCH 31/49] Address @CodeBlanch 's comments --- examples/Console/TestOtlpExporter.cs | 2 - ...aceExporterPersistentStorageExtensions.cs} | 54 +++++++++---------- 2 files changed, 27 insertions(+), 29 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/{OtlpExporterPersistentStorageExtensions.cs => OtlpTraceExporterPersistentStorageExtensions.cs} (55%) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 9e3367fbea0..b76588a1f0f 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -16,7 +16,6 @@ using OpenTelemetry; using OpenTelemetry.Exporter; -using OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; using OpenTelemetry.Extensions.PersistentStorage; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -76,7 +75,6 @@ private static object RunWithActivitySource(string endpoint, string protocol) .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) .AddOtlpExporterWithPersistentStorage( - null, opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs similarity index 55% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs index 63077c0939f..74453123a0b 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpExporterPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,19 +15,17 @@ // using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; +using OpenTelemetry.Exporter; using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Internal; -using OpenTelemetry.Trace; -namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage; +namespace OpenTelemetry.Trace; /// /// Extension methods to simplify registering of the OpenTelemetry Protocol (OTLP) exporter /// with persistent storage. /// -public static class OtlpExporterPersistentStorageExtensions +public static class OtlpTraceExporterPersistentStorageExtensions { /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider @@ -47,31 +45,33 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( Guard.ThrowIfNull(builder); Guard.ThrowIfNull(persistentStorageFactory); - var finalOptionsName = name ?? Options.DefaultName; - builder.ConfigureServices(services => { - if (name != null && configure != null) - { - services.Configure(finalOptionsName, configure); - } - - OtlpExporterOptions.RegisterOtlpExporterOptionsFactory(services); - services.RegisterOptionsFactory(configuration => new SdkLimitOptions(configuration)); + // Try this if it doesn't work there are other ways to plug into options + services + .AddOptions() + .Configure((otlpExporterOptions, serviceProvider) => + { + otlpExporterOptions.PersistentBlobProvider = persistentStorageFactory(serviceProvider); + }); }); - return builder.AddProcessor(sp => - { - var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); - - if (name == null && configure != null) - { - configure(exporterOptions); - } + return builder.AddOtlpExporter(name, configure); + } - exporterOptions.PersistentBlobProvider = persistentStorageFactory(sp); - var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - return OtlpTraceExporterHelperExtensions.BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); - }); + /// + /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider + /// with access to persistent storage. + /// + /// builder to use. + /// Callback action for configuring . + /// Factory function to create a . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( + this TracerProviderBuilder builder, + Action configure, + Func persistentStorageFactory) + { + return builder.AddOtlpExporterWithPersistentStorage(configure, persistentStorageFactory); } } From 0df62763c3f594bc5e2f96db70256b5c71b556eb Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 17:12:31 -0800 Subject: [PATCH 32/49] Update OtlpTraceExporterPersistentStorageExtensions.cs --- .../OtlpTraceExporterPersistentStorageExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs index 74453123a0b..1a40efd4214 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs @@ -38,7 +38,7 @@ public static class OtlpTraceExporterPersistentStorageExtensions /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( this TracerProviderBuilder builder, - string name, + string? name, Action configure, Func persistentStorageFactory) { @@ -72,6 +72,6 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( Action configure, Func persistentStorageFactory) { - return builder.AddOtlpExporterWithPersistentStorage(configure, persistentStorageFactory); + return builder.AddOtlpExporterWithPersistentStorage(name: null, configure, persistentStorageFactory); } } From 6af0480082a51df1ce1c9786cd2bef5fa410dce1 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Wed, 15 Feb 2023 17:35:32 -0800 Subject: [PATCH 33/49] Update OtlpTraceExporterPersistentStorageExtensions.cs --- .../OtlpTraceExporterPersistentStorageExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs index 1a40efd4214..25d1d91bc19 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs @@ -47,9 +47,8 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( builder.ConfigureServices(services => { - // Try this if it doesn't work there are other ways to plug into options services - .AddOptions() + .AddOptions(name) .Configure((otlpExporterOptions, serviceProvider) => { otlpExporterOptions.PersistentBlobProvider = persistentStorageFactory(serviceProvider); From cef17ae87b63c21fd1cf9824d0c131489eb07363 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 16 Feb 2023 10:24:19 -0800 Subject: [PATCH 34/49] remove changes to example project --- examples/Console/Examples.Console.csproj | 2 -- examples/Console/TestOtlpExporter.cs | 10 +++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj index 80994343743..59cff3d55ad 100644 --- a/examples/Console/Examples.Console.csproj +++ b/examples/Console/Examples.Console.csproj @@ -21,7 +21,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - @@ -39,6 +38,5 @@ - diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index b76588a1f0f..60ead4e242b 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -67,15 +67,12 @@ private static object RunWithActivitySource(string endpoint, string protocol) otlpExportProtocol = OtlpExportProtocol.Grpc; } - var storagePath = Path.GetTempPath(); - // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use OTLP exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .ConfigureResource(r => r.AddService("otlp-test")) - .AddOtlpExporterWithPersistentStorage( - opt => + .AddOtlpExporter(opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. if (!string.IsNullOrEmpty(endpoint)) @@ -85,9 +82,8 @@ private static object RunWithActivitySource(string endpoint, string protocol) opt.Protocol = otlpExportProtocol.Value; - System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint} and storage path {storagePath}"); - }, - _ => new FileBlobProvider(storagePath)) + System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); + }) .Build(); // The above line is required only in Applications From 5d764bc553fd4cd38a81bc22f6ae670d67f2825a Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 16 Feb 2023 10:38:14 -0800 Subject: [PATCH 35/49] Update TestOtlpExporter.cs --- examples/Console/TestOtlpExporter.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 60ead4e242b..53e6b1a7243 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -16,7 +16,6 @@ using OpenTelemetry; using OpenTelemetry.Exporter; -using OpenTelemetry.Extensions.PersistentStorage; using OpenTelemetry.Resources; using OpenTelemetry.Trace; From 5dcf7fd2241b72253ad49e23488726ef5291dd42 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 16 Feb 2023 10:40:51 -0800 Subject: [PATCH 36/49] Create README.md --- .../README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md new file mode 100644 index 00000000000..c226cced0fe --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md @@ -0,0 +1,14 @@ +# OTLP Exporter Persistent Storage for OpenTelemetry .NET + +## Usage + +```csharp +var storagePath = Path.GetTempPath(); + +using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .AddSource("ActivitySourceName") + .AddOtlpExporterWithPersistentStorage( + opt => {}, + serviceProvider => new FileBlobProvider(storagePath))) + .Build(); +``` From b7fe0ff28a2f27e1b09103b31d9083c02bee27aa Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 16 Feb 2023 12:20:12 -0800 Subject: [PATCH 37/49] Added an internal way to configure options inline with service provider. --- ...raceExporterPersistentStorageExtensions.cs | 39 ++++++++++++++----- .../OtlpTraceExporterHelperExtensions.cs | 13 ++++++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs index 25d1d91bc19..bda48f83791 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/OtlpTraceExporterPersistentStorageExtensions.cs @@ -42,20 +42,39 @@ public static TracerProviderBuilder AddOtlpExporterWithPersistentStorage( Action configure, Func persistentStorageFactory) { - Guard.ThrowIfNull(builder); Guard.ThrowIfNull(persistentStorageFactory); - builder.ConfigureServices(services => + Action? inlineConfigurationAction; + if (name is not null) { - services - .AddOptions(name) - .Configure((otlpExporterOptions, serviceProvider) => - { - otlpExporterOptions.PersistentBlobProvider = persistentStorageFactory(serviceProvider); - }); - }); + // Note: If we are using named options we can safely use Options API + // to act on the instance that will be created. See: + // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 + builder.ConfigureServices(services => + { + services + .AddOptions(name) + .Configure(ConfigureOptionsAction); + }); - return builder.AddOtlpExporter(name, configure); + inlineConfigurationAction = null; + } + else + { + // Note: If we are NOT using named options we need to execute inline + // to prevent potentially impacting options for other signals. + inlineConfigurationAction = ConfigureOptionsAction; + } + + return builder.AddOtlpExporter( + name, + configure, + inlineConfigurationAction); + + void ConfigureOptionsAction(OtlpExporterOptions options, IServiceProvider serviceProvider) + { + options.PersistentBlobProvider = persistentStorageFactory(serviceProvider); + } } /// diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 728ce1f503a..fcec9dc5e85 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -34,7 +34,7 @@ public static class OtlpTraceExporterHelperExtensions /// builder to use. /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder) - => AddOtlpExporter(builder, name: null, configure: null); + => AddOtlpExporter(builder, name: null, configure: null, inlineConfigurationAction: null); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -43,7 +43,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder builder, Action configure) - => AddOtlpExporter(builder, name: null, configure); + => AddOtlpExporter(builder, name: null, configure, inlineConfigurationAction: null); /// /// Adds OpenTelemetry Protocol (OTLP) exporter to the TracerProvider. @@ -56,6 +56,13 @@ public static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, string name, Action configure) + => AddOtlpExporter(builder, name: null, configure, inlineConfigurationAction: null); + + internal static TracerProviderBuilder AddOtlpExporter( + this TracerProviderBuilder builder, + string name, + Action configure, + Action inlineConfigurationAction) { Guard.ThrowIfNull(builder); @@ -88,6 +95,8 @@ public static TracerProviderBuilder AddOtlpExporter( configure(exporterOptions); } + inlineConfigurationAction?.Invoke(exporterOptions, sp); + // Note: Not using finalOptionsName here for SdkLimitOptions. // There should only be one provider for a given service // collection so SdkLimitOptions is treated as a single default From 147217dcea9b910a207ad37a4396e9ed3703c81f Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 16 Feb 2023 13:35:58 -0800 Subject: [PATCH 38/49] Update README.md --- .../README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md index c226cced0fe..d7f35b4cd65 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage/README.md @@ -9,6 +9,6 @@ using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("ActivitySourceName") .AddOtlpExporterWithPersistentStorage( opt => {}, - serviceProvider => new FileBlobProvider(storagePath))) + serviceProvider => new FileBlobProvider(storagePath)) .Build(); ``` From ec24f4526cb4602568c3d1e438246fb06aaabba4 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Thu, 16 Feb 2023 14:31:34 -0800 Subject: [PATCH 39/49] Add test with mock file provider classes --- .../ExportClient/OtlpGrpcTraceExportClient.cs | 3 +- .../MockCollectorIntegrationTests.cs | 139 ++++++++++++++++-- ...xporter.OpenTelemetryProtocol.Tests.csproj | 1 + 3 files changed, 128 insertions(+), 15 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index 3e75a392008..33372e1077e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -14,6 +14,7 @@ // limitations under the License. // +using Google.Protobuf; using Grpc.Core; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; @@ -51,7 +52,7 @@ public override bool SendExportRequest(OtlpCollector.ExportTraceServiceRequest r { if (this.PersistentBlobProvider != null) { - // TODO: Write blob to storage + this.PersistentBlobProvider.TryCreateBlob(request.ToByteArray(), out _); } OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs index 0cad1f777cd..ba0770df6cf 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs @@ -15,16 +15,13 @@ // #if !NETFRAMEWORK -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; using Grpc.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Metrics; using OpenTelemetry.Proto.Collector.Trace.V1; using OpenTelemetry.Tests; @@ -33,12 +30,19 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests; -public sealed class MockCollectorIntegrationTests +public sealed class MockCollectorIntegrationTests : IAsyncLifetime { - [Fact] - public async Task TestRecoveryAfterFailedExport() + private readonly HttpClient httpClient; + private IHost host; + + public MockCollectorIntegrationTests() { - using var host = await new HostBuilder() + this.httpClient = new HttpClient() { BaseAddress = new Uri("http://localhost:5050") }; + } + + public async Task InitializeAsync() + { + this.host = await new HostBuilder() .ConfigureWebHostDefaults(webBuilder => webBuilder .ConfigureKestrel(options => { @@ -68,14 +72,23 @@ public async Task TestRecoveryAfterFailedExport() }); })) .StartAsync().ConfigureAwait(false); + } - var httpClient = new HttpClient() { BaseAddress = new System.Uri("http://localhost:5050") }; + public async Task DisposeAsync() + { + await this.host.StopAsync().ConfigureAwait(false); + } - var codes = new[] { Grpc.Core.StatusCode.Unimplemented, Grpc.Core.StatusCode.OK }; - await httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}").ConfigureAwait(false); + [Fact] + public async Task TestRecoveryAfterFailedExport() + { + await this.SetCollectorStatusCodes(new[] + { + Grpc.Core.StatusCode.Unimplemented, + }); var exportResults = new List(); - var otlpExporter = new OtlpTraceExporter(new OtlpExporterOptions() { Endpoint = new System.Uri("http://localhost:4317") }); + var otlpExporter = new OtlpTraceExporter(new OtlpExporterOptions() { Endpoint = new Uri("http://localhost:4317") }); var delegatingExporter = new DelegatingExporter { OnExportFunc = (batch) => @@ -104,13 +117,46 @@ public async Task TestRecoveryAfterFailedExport() Assert.Equal(2, exportResults.Count); Assert.Equal(ExportResult.Success, exportResults[1]); + } + + [Fact] + public async Task TestOtlpTraceExportWithPersistentStorage() + { + await this.SetCollectorStatusCodes(new[] + { + Grpc.Core.StatusCode.Cancelled, + }); + + var activitySourceName = "otel.mock.collector.test.persistent-storage"; + MockFileProvider mockFileProvider = new(); - await host.StopAsync().ConfigureAwait(false); + using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .AddSource(activitySourceName) + .AddOtlpExporterWithPersistentStorage( + otlpExporterOptions => + { + otlpExporterOptions.Endpoint = new Uri("http://localhost:4317"); + otlpExporterOptions.ExportProcessorType = ExportProcessorType.Simple; + }, + _ => mockFileProvider) + .Build(); + + using var source = new ActivitySource(activitySourceName); + source.StartActivity().Stop(); + tracerProvider.ForceFlush(); + + var blobs = mockFileProvider.TryGetBlobs(); + Assert.Single(blobs); + } + + private async Task SetCollectorStatusCodes(Grpc.Core.StatusCode[] codes) + { + await this.httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}"); } private class MockCollectorState { - private Grpc.Core.StatusCode[] statusCodes = { }; + private Grpc.Core.StatusCode[] statusCodes = Array.Empty(); private int statusCodeIndex = 0; public void SetStatusCodes(int[] statusCodes) @@ -147,5 +193,70 @@ public override Task Export(ExportTraceServiceReques return Task.FromResult(new ExportTraceServiceResponse()); } } + + private class MockFileProvider : PersistentBlobProvider + { + private readonly List mockStorage = new(); + + public IEnumerable TryGetBlobs() + { + return this.mockStorage.AsEnumerable(); + } + + protected override IEnumerable OnGetBlobs() + { + return this.mockStorage.AsEnumerable(); + } + + protected override bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob) + { + blob = new MockFileBlob(); + this.mockStorage.Add(blob); + return blob.TryWrite(buffer); + } + + protected override bool OnTryCreateBlob(byte[] buffer, out PersistentBlob blob) + { + blob = new MockFileBlob(); + this.mockStorage.Add(blob); + return blob.TryWrite(buffer); + } + + protected override bool OnTryGetBlob(out PersistentBlob blob) + { + blob = this.GetBlobs().FirstOrDefault(); + + return true; + } + } + + private class MockFileBlob : PersistentBlob + { + private byte[] buffer; + + protected override bool OnTryRead(out byte[] buffer) + { + buffer = this.buffer; + + return true; + } + + protected override bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) + { + this.buffer = buffer; + + return true; + } + + protected override bool OnTryLease(int leasePeriodMilliseconds) + { + return true; + } + + protected override bool OnTryDelete() + { + throw new NotImplementedException(); + } + } } #endif diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj index 57d0af9444c..d1ad2624cb3 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj @@ -37,6 +37,7 @@ + From 57fdc4de0cb45662d47e1c8a3a25767daea26ca1 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Fri, 17 Feb 2023 08:55:14 -0800 Subject: [PATCH 40/49] undo test changes --- .../MockCollectorIntegrationTests.cs | 139 ++---------------- ...xporter.OpenTelemetryProtocol.Tests.csproj | 1 - 2 files changed, 14 insertions(+), 126 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs index ba0770df6cf..0cad1f777cd 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/MockCollectorIntegrationTests.cs @@ -15,13 +15,16 @@ // #if !NETFRAMEWORK +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; using Grpc.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using OpenTelemetry.Extensions.PersistentStorage.Abstractions; using OpenTelemetry.Metrics; using OpenTelemetry.Proto.Collector.Trace.V1; using OpenTelemetry.Tests; @@ -30,19 +33,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests; -public sealed class MockCollectorIntegrationTests : IAsyncLifetime +public sealed class MockCollectorIntegrationTests { - private readonly HttpClient httpClient; - private IHost host; - - public MockCollectorIntegrationTests() - { - this.httpClient = new HttpClient() { BaseAddress = new Uri("http://localhost:5050") }; - } - - public async Task InitializeAsync() + [Fact] + public async Task TestRecoveryAfterFailedExport() { - this.host = await new HostBuilder() + using var host = await new HostBuilder() .ConfigureWebHostDefaults(webBuilder => webBuilder .ConfigureKestrel(options => { @@ -72,23 +68,14 @@ public async Task InitializeAsync() }); })) .StartAsync().ConfigureAwait(false); - } - public async Task DisposeAsync() - { - await this.host.StopAsync().ConfigureAwait(false); - } + var httpClient = new HttpClient() { BaseAddress = new System.Uri("http://localhost:5050") }; - [Fact] - public async Task TestRecoveryAfterFailedExport() - { - await this.SetCollectorStatusCodes(new[] - { - Grpc.Core.StatusCode.Unimplemented, - }); + var codes = new[] { Grpc.Core.StatusCode.Unimplemented, Grpc.Core.StatusCode.OK }; + await httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}").ConfigureAwait(false); var exportResults = new List(); - var otlpExporter = new OtlpTraceExporter(new OtlpExporterOptions() { Endpoint = new Uri("http://localhost:4317") }); + var otlpExporter = new OtlpTraceExporter(new OtlpExporterOptions() { Endpoint = new System.Uri("http://localhost:4317") }); var delegatingExporter = new DelegatingExporter { OnExportFunc = (batch) => @@ -117,46 +104,13 @@ await this.SetCollectorStatusCodes(new[] Assert.Equal(2, exportResults.Count); Assert.Equal(ExportResult.Success, exportResults[1]); - } - - [Fact] - public async Task TestOtlpTraceExportWithPersistentStorage() - { - await this.SetCollectorStatusCodes(new[] - { - Grpc.Core.StatusCode.Cancelled, - }); - - var activitySourceName = "otel.mock.collector.test.persistent-storage"; - MockFileProvider mockFileProvider = new(); - using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource(activitySourceName) - .AddOtlpExporterWithPersistentStorage( - otlpExporterOptions => - { - otlpExporterOptions.Endpoint = new Uri("http://localhost:4317"); - otlpExporterOptions.ExportProcessorType = ExportProcessorType.Simple; - }, - _ => mockFileProvider) - .Build(); - - using var source = new ActivitySource(activitySourceName); - source.StartActivity().Stop(); - tracerProvider.ForceFlush(); - - var blobs = mockFileProvider.TryGetBlobs(); - Assert.Single(blobs); - } - - private async Task SetCollectorStatusCodes(Grpc.Core.StatusCode[] codes) - { - await this.httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}"); + await host.StopAsync().ConfigureAwait(false); } private class MockCollectorState { - private Grpc.Core.StatusCode[] statusCodes = Array.Empty(); + private Grpc.Core.StatusCode[] statusCodes = { }; private int statusCodeIndex = 0; public void SetStatusCodes(int[] statusCodes) @@ -193,70 +147,5 @@ public override Task Export(ExportTraceServiceReques return Task.FromResult(new ExportTraceServiceResponse()); } } - - private class MockFileProvider : PersistentBlobProvider - { - private readonly List mockStorage = new(); - - public IEnumerable TryGetBlobs() - { - return this.mockStorage.AsEnumerable(); - } - - protected override IEnumerable OnGetBlobs() - { - return this.mockStorage.AsEnumerable(); - } - - protected override bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob) - { - blob = new MockFileBlob(); - this.mockStorage.Add(blob); - return blob.TryWrite(buffer); - } - - protected override bool OnTryCreateBlob(byte[] buffer, out PersistentBlob blob) - { - blob = new MockFileBlob(); - this.mockStorage.Add(blob); - return blob.TryWrite(buffer); - } - - protected override bool OnTryGetBlob(out PersistentBlob blob) - { - blob = this.GetBlobs().FirstOrDefault(); - - return true; - } - } - - private class MockFileBlob : PersistentBlob - { - private byte[] buffer; - - protected override bool OnTryRead(out byte[] buffer) - { - buffer = this.buffer; - - return true; - } - - protected override bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) - { - this.buffer = buffer; - - return true; - } - - protected override bool OnTryLease(int leasePeriodMilliseconds) - { - return true; - } - - protected override bool OnTryDelete() - { - throw new NotImplementedException(); - } - } } #endif diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj index d1ad2624cb3..57d0af9444c 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests.csproj @@ -37,7 +37,6 @@ - From 1014de1d92f4c11456e45780f2f90a4411503e58 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Fri, 17 Feb 2023 09:08:51 -0800 Subject: [PATCH 41/49] add test --- OpenTelemetry.sln | 8 +- .../AssemblyInfo.cs | 2 + ...tryProtocol.PersistentStorage.Tests.csproj | 39 +++ .../TestPersistentStorage.cs | 224 ++++++++++++++++++ 4 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj create mode 100644 test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/TestPersistentStorage.cs diff --git a/OpenTelemetry.sln b/OpenTelemetry.sln index 09180a7e6fb..4323e20a678 100644 --- a/OpenTelemetry.sln +++ b/OpenTelemetry.sln @@ -249,7 +249,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-console", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-jaeger", "docs\trace\getting-started-jaeger\getting-started-jaeger.csproj", "{A0C0B77C-6C7B-4EC2-AC61-EA1F489811B9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage", "src\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj", "{2DA349A7-814F-43A6-AA22-28D03421EAF7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage", "src\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.csproj", "{2DA349A7-814F-43A6-AA22-28D03421EAF7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests", "test\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests\OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj", "{448837FD-6DEA-4B37-A1F5-42BC7AD8E9BE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -529,6 +531,10 @@ Global {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Debug|Any CPU.Build.0 = Debug|Any CPU {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Release|Any CPU.ActiveCfg = Release|Any CPU {2DA349A7-814F-43A6-AA22-28D03421EAF7}.Release|Any CPU.Build.0 = Release|Any CPU + {448837FD-6DEA-4B37-A1F5-42BC7AD8E9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {448837FD-6DEA-4B37-A1F5-42BC7AD8E9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {448837FD-6DEA-4B37-A1F5-42BC7AD8E9BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {448837FD-6DEA-4B37-A1F5-42BC7AD8E9BE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs index 5cd08436353..56dcf3d457b 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/AssemblyInfo.cs @@ -22,6 +22,7 @@ [assembly: InternalsVisibleTo("MockOpenTelemetryCollector, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] +[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] // Used by Moq. [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] @@ -30,6 +31,7 @@ [assembly: InternalsVisibleTo("Benchmarks")] [assembly: InternalsVisibleTo("MockOpenTelemetryCollector")] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage")] +[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests")] // Used by Moq. [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj new file mode 100644 index 00000000000..25959626531 --- /dev/null +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj @@ -0,0 +1,39 @@ + + + + net6.0 + disable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/TestPersistentStorage.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/TestPersistentStorage.cs new file mode 100644 index 00000000000..96849cdddaa --- /dev/null +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/TestPersistentStorage.cs @@ -0,0 +1,224 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#if !NETFRAMEWORK +using System.Diagnostics; +using Grpc.Core; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using OpenTelemetry.Extensions.PersistentStorage.Abstractions; +using OpenTelemetry.Metrics; +using OpenTelemetry.Proto.Collector.Trace.V1; +using OpenTelemetry.Trace; +using Xunit; + +namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests; + +public sealed class TestPersistentStorage : IAsyncLifetime +{ + private readonly HttpClient httpClient; + private IHost host; + + public TestPersistentStorage() + { + this.httpClient = new HttpClient() { BaseAddress = new Uri("http://localhost:5050") }; + } + + public async Task InitializeAsync() + { + this.host = await new HostBuilder() + .ConfigureWebHostDefaults(webBuilder => webBuilder + .ConfigureKestrel(options => + { + options.ListenLocalhost(5050, listenOptions => listenOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1); + options.ListenLocalhost(4317, listenOptions => listenOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2); + }) + .ConfigureServices(services => + { + services.AddSingleton(new MockCollectorState()); + services.AddGrpc(); + }) + .Configure(app => + { + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapGet( + "/MockCollector/SetResponseCodes/{responseCodesCsv}", + (MockCollectorState collectorState, string responseCodesCsv) => + { + var codes = responseCodesCsv.Split(",").Select(x => int.Parse(x)).ToArray(); + collectorState.SetStatusCodes(codes); + }); + + endpoints.MapGrpcService(); + }); + })) + .StartAsync().ConfigureAwait(false); + } + + public async Task DisposeAsync() + { + if (this.host != null) + { + await this.host.StopAsync().ConfigureAwait(false); + } + } + + [Fact] + public async Task TestOtlpTraceExportWithPersistentStorage() + { + await this.SetCollectorStatusCodes(new[] + { + Grpc.Core.StatusCode.Cancelled, + }); + + var activitySourceName = "otel.mock.collector.test.persistent-storage"; + MockFileProvider mockFileProvider = new(); + + using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .AddSource(activitySourceName) + .AddOtlpExporterWithPersistentStorage( + otlpExporterOptions => + { + otlpExporterOptions.Endpoint = new Uri("http://localhost:4317"); + otlpExporterOptions.ExportProcessorType = ExportProcessorType.Simple; + }, + _ => mockFileProvider) + .Build(); + + using var source = new ActivitySource(activitySourceName); + source.StartActivity().Stop(); + tracerProvider.ForceFlush(); + + var blobs = mockFileProvider.TryGetBlobs(); + Assert.Single(blobs); + } + + private async Task SetCollectorStatusCodes(Grpc.Core.StatusCode[] codes) + { + await this.httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}"); + } + + private class MockCollectorState + { + private Grpc.Core.StatusCode[] statusCodes = Array.Empty(); + private int statusCodeIndex = 0; + + public void SetStatusCodes(int[] statusCodes) + { + this.statusCodeIndex = 0; + this.statusCodes = statusCodes.Select(x => (Grpc.Core.StatusCode)x).ToArray(); + } + + public Grpc.Core.StatusCode NextStatus() + { + return this.statusCodeIndex < this.statusCodes.Length + ? this.statusCodes[this.statusCodeIndex++] + : Grpc.Core.StatusCode.OK; + } + } + + private class MockTraceService : TraceService.TraceServiceBase + { + private readonly MockCollectorState state; + + public MockTraceService(MockCollectorState state) + { + this.state = state; + } + + public override Task Export(ExportTraceServiceRequest request, ServerCallContext context) + { + var statusCode = this.state.NextStatus(); + if (statusCode != Grpc.Core.StatusCode.OK) + { + throw new RpcException(new Grpc.Core.Status(statusCode, "Error.")); + } + + return Task.FromResult(new ExportTraceServiceResponse()); + } + } + + private class MockFileProvider : PersistentBlobProvider + { + private readonly List mockStorage = new(); + + public IEnumerable TryGetBlobs() + { + return this.mockStorage.AsEnumerable(); + } + + protected override IEnumerable OnGetBlobs() + { + return this.mockStorage.AsEnumerable(); + } + + protected override bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob) + { + blob = new MockFileBlob(); + this.mockStorage.Add(blob); + return blob.TryWrite(buffer); + } + + protected override bool OnTryCreateBlob(byte[] buffer, out PersistentBlob blob) + { + blob = new MockFileBlob(); + this.mockStorage.Add(blob); + return blob.TryWrite(buffer); + } + + protected override bool OnTryGetBlob(out PersistentBlob blob) + { + blob = this.GetBlobs().FirstOrDefault(); + + return true; + } + } + + private class MockFileBlob : PersistentBlob + { + private byte[] buffer; + + protected override bool OnTryRead(out byte[] buffer) + { + buffer = this.buffer; + + return true; + } + + protected override bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) + { + this.buffer = buffer; + + return true; + } + + protected override bool OnTryLease(int leasePeriodMilliseconds) + { + return true; + } + + protected override bool OnTryDelete() + { + throw new NotImplementedException(); + } + } +} +#endif From ad3f2505717a231dc9dd408161a2eadb874a65ba Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Fri, 17 Feb 2023 09:11:23 -0800 Subject: [PATCH 42/49] Update Common.nonprod.props --- build/Common.nonprod.props | 1 - 1 file changed, 1 deletion(-) diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index 6e3dc69d1ca..12049e6e3c0 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -42,7 +42,6 @@ [6.0.0,) [17.4.1] [4.18.3,5.0) - 1.0.0-beta.1 [6.4.0,7.0) [1.0.0,2.0) [6.4.0] From a1e370998963597fdbc298061e95c81911a40c32 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Fri, 17 Feb 2023 09:58:54 -0800 Subject: [PATCH 43/49] Update OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj --- ...tryProtocol.PersistentStorage.Tests.csproj | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj index 25959626531..8cb57a02960 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests/OpenTelemetry.Exporter.OpenTelemetryProtocol.PersistentStorage.Tests.csproj @@ -6,34 +6,13 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + - - - - - - - - - - - - - - From 05e8e3a856cf91b2c815de8933ba5f5df1c583ce Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Fri, 17 Feb 2023 10:00:52 -0800 Subject: [PATCH 44/49] Update OtlpTraceExporterTests.cs --- .../OtlpTraceExporterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index dd94e5dc95e..ff52e1c382e 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -51,7 +51,7 @@ static OtlpTraceExporterTests() ActivitySource.AddActivityListener(listener); } - [Fact] + [Fact(Skip="Unblocking OTLP Exporter PersistentStorage")] public void AddOtlpTraceExporterNamedOptionsSupported() { int defaultExporterOptionsConfigureOptionsInvocations = 0; From 87ce1fee57dd1dbabed9aead13c56dafbfac0d73 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Fri, 17 Feb 2023 10:05:11 -0800 Subject: [PATCH 45/49] Fix name not being passed to internal helper. --- .../OtlpTraceExporterHelperExtensions.cs | 2 +- .../OtlpTraceExporterTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index fcec9dc5e85..9f1f08d7c68 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -56,7 +56,7 @@ public static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, string name, Action configure) - => AddOtlpExporter(builder, name: null, configure, inlineConfigurationAction: null); + => AddOtlpExporter(builder, name, configure, inlineConfigurationAction: null); internal static TracerProviderBuilder AddOtlpExporter( this TracerProviderBuilder builder, diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index ff52e1c382e..dd94e5dc95e 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -51,7 +51,7 @@ static OtlpTraceExporterTests() ActivitySource.AddActivityListener(listener); } - [Fact(Skip="Unblocking OTLP Exporter PersistentStorage")] + [Fact] public void AddOtlpTraceExporterNamedOptionsSupported() { int defaultExporterOptionsConfigureOptionsInvocations = 0; From 0edcb0734e7256dded1b63bc8070629ef4711eee Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 16 Feb 2023 14:04:45 -0800 Subject: [PATCH 46/49] [Otlp] Make sure Otlp trace and metric exporters have dedicated options instances (#4200) * Make sure Otlp trace and metric exporters have dedicated options instances. * CHANGELOG patch. --- .../CHANGELOG.md | 4 ++++ .../OtlpMetricExporterExtensions.cs | 19 ++++++++++++++----- .../OtlpTraceExporterHelperExtensions.cs | 19 ++++++++++++++----- .../OtlpTraceExporterTests.cs | 13 +++++++------ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index f6822468af9..f4b74cb539f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* `AddOtlpExporter` extension methods will now always create a new options + instance when named options are NOT used. + ([#4200](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4200)) + ## 1.4.0-rc.4 Released 2023-Feb-10 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index 80979dd38f9..df4f9e5be80 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -73,16 +73,25 @@ public static MeterProviderBuilder AddOtlpExporter( return builder.AddReader(sp => { - var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + OtlpExporterOptions exporterOptions; - if (name == null && configureExporter != null) + if (name == null) { - // If we are NOT using named options, we execute the - // configuration delegate inline. The reason for this is + // If we are NOT using named options we create a new + // instance always. The reason for this is // OtlpExporterOptions is shared by all signals. Without a // name, delegates for all signals will mix together. See: // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 - configureExporter(exporterOptions); + exporterOptions = sp.GetRequiredService>().Create(finalOptionsName); + + // Configuration delegate is executed inline on the fresh instance. + configureExporter?.Invoke(exporterOptions); + } + else + { + // When using named options we can properly utilize Options + // API to create or reuse an instance. + exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); } return BuildOtlpExporterMetricReader( diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 9f1f08d7c68..26099aaec2a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -83,16 +83,25 @@ internal static TracerProviderBuilder AddOtlpExporter( return builder.AddProcessor(sp => { - var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + OtlpExporterOptions exporterOptions; - if (name == null && configure != null) + if (name == null) { - // If we are NOT using named options, we execute the - // configuration delegate inline. The reason for this is + // If we are NOT using named options we create a new + // instance always. The reason for this is // OtlpExporterOptions is shared by all signals. Without a // name, delegates for all signals will mix together. See: // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 - configure(exporterOptions); + exporterOptions = sp.GetRequiredService>().Create(finalOptionsName); + + // Configuration delegate is executed inline on the fresh instance. + configure?.Invoke(exporterOptions); + } + else + { + // When using named options we can properly utilize Options + // API to create or reuse an instance. + exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); } inlineConfigurationAction?.Invoke(exporterOptions, sp); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index dd94e5dc95e..a3003baf8a7 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -641,6 +641,8 @@ public void Null_BatchExportProcessorOptions_SupportedTest() [Fact] public void NonnamedOptionsMutateSharedInstanceTest() { + var testOptionsInstance = new OtlpExporterOptions(); + OtlpExporterOptions tracerOptions = null; OtlpExporterOptions meterOptions = null; @@ -649,11 +651,15 @@ public void NonnamedOptionsMutateSharedInstanceTest() services.AddOpenTelemetry() .WithTracing(builder => builder.AddOtlpExporter(o => { + Assert.Equal(testOptionsInstance.Endpoint, o.Endpoint); + tracerOptions = o; o.Endpoint = new("http://localhost/traces"); })) .WithMetrics(builder => builder.AddOtlpExporter(o => { + Assert.Equal(testOptionsInstance.Endpoint, o.Endpoint); + meterOptions = o; o.Endpoint = new("http://localhost/metrics"); })); @@ -676,12 +682,7 @@ public void NonnamedOptionsMutateSharedInstanceTest() Assert.NotNull(meterOptions); Assert.Equal("http://localhost/metrics", meterOptions.Endpoint.OriginalString); - // Note: tracerOptions & meterOptions are actually the same instance - // in memory and that instance was actually mutated after - // OtlpTraceExporter was created but this is OK because it doesn't - // use the options after ctor. - Assert.True(ReferenceEquals(tracerOptions, meterOptions)); - Assert.Equal("http://localhost/metrics", tracerOptions.Endpoint.OriginalString); + Assert.False(ReferenceEquals(tracerOptions, meterOptions)); } [Fact] From 01b097d78cb4dded14167f6ede4a386d84f1a1f7 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Fri, 17 Feb 2023 10:09:51 -0800 Subject: [PATCH 47/49] Revert "[Otlp] Make sure Otlp trace and metric exporters have dedicated options instances (#4200)" This reverts commit 0edcb0734e7256dded1b63bc8070629ef4711eee. --- .../CHANGELOG.md | 4 ---- .../OtlpMetricExporterExtensions.cs | 19 +++++-------------- .../OtlpTraceExporterHelperExtensions.cs | 19 +++++-------------- .../OtlpTraceExporterTests.cs | 13 ++++++------- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index f4b74cb539f..f6822468af9 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,10 +2,6 @@ ## Unreleased -* `AddOtlpExporter` extension methods will now always create a new options - instance when named options are NOT used. - ([#4200](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4200)) - ## 1.4.0-rc.4 Released 2023-Feb-10 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index df4f9e5be80..80979dd38f9 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -73,25 +73,16 @@ public static MeterProviderBuilder AddOtlpExporter( return builder.AddReader(sp => { - OtlpExporterOptions exporterOptions; + var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); - if (name == null) + if (name == null && configureExporter != null) { - // If we are NOT using named options we create a new - // instance always. The reason for this is + // If we are NOT using named options, we execute the + // configuration delegate inline. The reason for this is // OtlpExporterOptions is shared by all signals. Without a // name, delegates for all signals will mix together. See: // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 - exporterOptions = sp.GetRequiredService>().Create(finalOptionsName); - - // Configuration delegate is executed inline on the fresh instance. - configureExporter?.Invoke(exporterOptions); - } - else - { - // When using named options we can properly utilize Options - // API to create or reuse an instance. - exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + configureExporter(exporterOptions); } return BuildOtlpExporterMetricReader( diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 26099aaec2a..9f1f08d7c68 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -83,25 +83,16 @@ internal static TracerProviderBuilder AddOtlpExporter( return builder.AddProcessor(sp => { - OtlpExporterOptions exporterOptions; + var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); - if (name == null) + if (name == null && configure != null) { - // If we are NOT using named options we create a new - // instance always. The reason for this is + // If we are NOT using named options, we execute the + // configuration delegate inline. The reason for this is // OtlpExporterOptions is shared by all signals. Without a // name, delegates for all signals will mix together. See: // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 - exporterOptions = sp.GetRequiredService>().Create(finalOptionsName); - - // Configuration delegate is executed inline on the fresh instance. - configure?.Invoke(exporterOptions); - } - else - { - // When using named options we can properly utilize Options - // API to create or reuse an instance. - exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + configure(exporterOptions); } inlineConfigurationAction?.Invoke(exporterOptions, sp); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index a3003baf8a7..dd94e5dc95e 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -641,8 +641,6 @@ public void Null_BatchExportProcessorOptions_SupportedTest() [Fact] public void NonnamedOptionsMutateSharedInstanceTest() { - var testOptionsInstance = new OtlpExporterOptions(); - OtlpExporterOptions tracerOptions = null; OtlpExporterOptions meterOptions = null; @@ -651,15 +649,11 @@ public void NonnamedOptionsMutateSharedInstanceTest() services.AddOpenTelemetry() .WithTracing(builder => builder.AddOtlpExporter(o => { - Assert.Equal(testOptionsInstance.Endpoint, o.Endpoint); - tracerOptions = o; o.Endpoint = new("http://localhost/traces"); })) .WithMetrics(builder => builder.AddOtlpExporter(o => { - Assert.Equal(testOptionsInstance.Endpoint, o.Endpoint); - meterOptions = o; o.Endpoint = new("http://localhost/metrics"); })); @@ -682,7 +676,12 @@ public void NonnamedOptionsMutateSharedInstanceTest() Assert.NotNull(meterOptions); Assert.Equal("http://localhost/metrics", meterOptions.Endpoint.OriginalString); - Assert.False(ReferenceEquals(tracerOptions, meterOptions)); + // Note: tracerOptions & meterOptions are actually the same instance + // in memory and that instance was actually mutated after + // OtlpTraceExporter was created but this is OK because it doesn't + // use the options after ctor. + Assert.True(ReferenceEquals(tracerOptions, meterOptions)); + Assert.Equal("http://localhost/metrics", tracerOptions.Endpoint.OriginalString); } [Fact] From c1c87e5f5cad3edba8539b040678205333eaaabd Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 27 Feb 2023 09:26:35 -0800 Subject: [PATCH 48/49] Update OtlpGrpcTraceExportClient.cs --- .../Implementation/ExportClient/OtlpGrpcTraceExportClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index 33372e1077e..d4cc416ceb6 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -50,6 +50,7 @@ public override bool SendExportRequest(OtlpCollector.ExportTraceServiceRequest r } catch (RpcException ex) { + // TODO: Add check to only create blob for a retryable error if (this.PersistentBlobProvider != null) { this.PersistentBlobProvider.TryCreateBlob(request.ToByteArray(), out _); From e360ae318ffb4c66a85b7135f7b04c4f41de2859 Mon Sep 17 00:00:00 2001 From: Michael Maxwell Date: Mon, 27 Feb 2023 09:46:46 -0800 Subject: [PATCH 49/49] ci rerun