From 48ff62c57a4055ee6a9d967902c1672efb1bf664 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 12 Sep 2023 19:56:12 -0700 Subject: [PATCH 01/16] add interface --- ...penTelemetryProtocolExporterEventSource.cs | 10 +-- .../retry/OtlpExporterTransmissionHandler.cs | 66 +++++++++++++++++++ .../OtlpTraceExporter.cs | 16 +++-- .../OtlpTraceExporterHelperExtensions.cs | 6 +- 4 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs index e7f09b3ca9b..9581ee595e0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs @@ -35,11 +35,11 @@ public void FailedToReachCollector(Uri collectorUri, Exception ex) } [NonEvent] - public void ExportMethodException(Exception ex) + public void ExportMethodException(Exception ex, bool isRetry = false) { if (Log.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.ExportMethodException(ex.ToInvariantString()); + this.ExportMethodException(ex.ToInvariantString(), isRetry); } } @@ -55,10 +55,10 @@ public void CouldNotTranslateActivity(string className, string methodName) this.WriteEvent(3, className, methodName); } - [Event(4, Message = "Unknown error in export method: {0}", Level = EventLevel.Error)] - public void ExportMethodException(string ex) + [Event(4, Message = "Unknown error in export method. Message: '{0}'. IsRetry: {1}", Level = EventLevel.Error)] + public void ExportMethodException(string ex, bool isRetry) { - this.WriteEvent(4, ex); + this.WriteEvent(4, ex, isRetry); } [Event(5, Message = "Could not translate metric from class '{0}' and method '{1}', metric will not be recorded.", Level = EventLevel.Informational)] diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs new file mode 100644 index 00000000000..a33e56b9127 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -0,0 +1,66 @@ +// +// 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 OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; +using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; + +namespace OpenTelemetry.Exporter; + +internal class OtlpExporterTransmissionHandler +{ + internal IExportClient ExportClient; + + public OtlpExporterOptions Options { get; internal set; } + + public virtual bool SubmitRequest(T request) + { + try + { + return this.ExportClient.SendExportRequest(request); + } + catch (Exception ex) + { + OpenTelemetryProtocolExporterEventSource.Log.ExportMethodException(ex); + return this.OnSubmitRequestExceptionThrown(request, ex); + } + } + + protected virtual bool RetryRequest(T request, out Exception exception) + { + try + { + var result = this.ExportClient.SendExportRequest(request); + exception = null; + return result; + } + catch (Exception ex) + { + OpenTelemetryProtocolExporterEventSource.Log.ExportMethodException(ex, isRetry: true); + exception = ex; + return false; + } + } + + protected virtual bool OnSubmitRequestExceptionThrown(T request, Exception exception) + { + return this.OnHandleDroppedRequest(request); + } + + protected virtual bool OnHandleDroppedRequest(T request) + { + return false; + } +} diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index 2c9bcb95bba..94f2522b633 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -31,6 +31,7 @@ public class OtlpTraceExporter : BaseExporter { private readonly SdkLimitOptions sdkLimitOptions; private readonly IExportClient exportClient; + private readonly OtlpExporterTransmissionHandler transmissionHandler; private OtlpResource.Resource processResource; @@ -39,7 +40,7 @@ public class OtlpTraceExporter : BaseExporter /// /// Configuration options for the export. public OtlpTraceExporter(OtlpExporterOptions options) - : this(options, new(), null) + : this(options, new(), null, null) { } @@ -49,10 +50,12 @@ public OtlpTraceExporter(OtlpExporterOptions options) /// . /// . /// Client used for sending export request. + /// Transmission handler for retrying failed requests. internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, - IExportClient exportClient = null) + IExportClient exportClient = null, + OtlpExporterTransmissionHandler transmissionHandler = null) { Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); @@ -77,6 +80,11 @@ internal OtlpTraceExporter( { this.exportClient = exporterOptions.GetTraceExportClient(); } + + transmissionHandler ??= new OtlpExporterTransmissionHandler(); + + transmissionHandler.ExportClient = exportClient; + transmissionHandler.Options = exporterOptions; } internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource(); @@ -93,7 +101,7 @@ public override ExportResult Export(in Batch activityBatch) { request.AddBatch(this.sdkLimitOptions, this.ProcessResource, activityBatch); - if (!this.exportClient.SendExportRequest(request)) + if (!this.transmissionHandler.SubmitRequest(request)) { return ExportResult.Failure; } @@ -114,6 +122,6 @@ public override ExportResult Export(in Batch activityBatch) /// protected override bool OnShutdown(int timeoutMilliseconds) { - return this.exportClient?.Shutdown(timeoutMilliseconds) ?? true; + return this.transmissionHandler.ExportClient?.Shutdown(timeoutMilliseconds) ?? true; } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index b25b5e847f8..a8de2f5694c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -20,6 +20,7 @@ using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Internal; +using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; namespace OpenTelemetry.Trace; @@ -115,7 +116,10 @@ internal static BaseProcessor BuildOtlpExporterProcessor( { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions); + BaseExporter otlpExporter = new OtlpTraceExporter( + exporterOptions, + sdkLimitOptions, + transmissionHandler: serviceProvider.GetRequiredService>()); if (configureExporterInstance != null) { From 9eda8f76e727524ec10cad6bd69aba155416083a Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 20 Sep 2023 21:38:54 -0700 Subject: [PATCH 02/16] draft 2 --- .../ExportClient/OtlpGrpcTraceExportClient.cs | 11 +-- ...acePersistentStorageTransmissionHandler.cs | 76 +++++++++++++++++++ .../OtlpTraceExporter.cs | 4 +- .../OtlpTraceExporterHelperExtensions.cs | 4 + 4 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index 2825c1d611e..58e39973372 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -43,16 +43,7 @@ public override bool SendExportRequest(OtlpCollector.ExportTraceServiceRequest r { var deadline = DateTime.UtcNow.AddMilliseconds(this.TimeoutMilliseconds); - try - { - this.traceClient.Export(request, headers: this.Headers, deadline: deadline, cancellationToken: cancellationToken); - } - catch (RpcException ex) - { - OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex); - - return false; - } + this.traceClient.Export(request, headers: this.Headers, deadline: deadline, cancellationToken: cancellationToken); return true; } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs new file mode 100644 index 00000000000..07615ae7709 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs @@ -0,0 +1,76 @@ +// +// 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 System.Timers; +using Google.Protobuf; +using OpenTelemetry.PersistentStorage.Abstractions; +using OpenTelemetry.PersistentStorage.FileSystem; +using OpenTelemetry.Proto.Collector.Trace.V1; + +namespace OpenTelemetry.Exporter; + +internal class TracePersistentStorageTransmissionHandler : OtlpExporterTransmissionHandler +{ + private PersistentBlobProvider persistentBlobProvider; + private System.Timers.Timer timer; + + public TracePersistentStorageTransmissionHandler() + { + this.persistentBlobProvider = new FileBlobProvider(@"c:\temp\otlp\trace"); + this.timer = new System.Timers.Timer(); + this.timer.Elapsed += this.RetryRequestFromStorage; + this.timer.Interval = 20000; + this.timer.AutoReset = true; + this.timer.Start(); + } + + protected override bool OnSubmitRequestExceptionThrown(ExportTraceServiceRequest request, Exception exception) + { + if (this.persistentBlobProvider.TryCreateBlob(request.ToByteArray(), out _)) + { + return true; + } + + return this.OnHandleDroppedRequest(request); + } + + private void RetryRequestFromStorage(object sender, ElapsedEventArgs e) + { + int fileCount = 0; + while (fileCount < 10) + { + if (this.persistentBlobProvider.TryGetBlob(out var blob)) + { + if (blob != null && blob.TryLease(20000) && blob.TryRead(out var data)) + { + var request = new ExportTraceServiceRequest(); + request.MergeFrom(data); + this.RetryRequest(request, out var exception); + if (exception == null) + { + blob.TryDelete(); + } + } + } + else + { + break; + } + + fileCount++; + } + } +} diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index 94f2522b633..63f1c04f146 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -83,8 +83,10 @@ internal OtlpTraceExporter( transmissionHandler ??= new OtlpExporterTransmissionHandler(); - transmissionHandler.ExportClient = exportClient; + transmissionHandler.ExportClient = this.exportClient; transmissionHandler.Options = exporterOptions; + + this.transmissionHandler = transmissionHandler; } internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource(); diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index a8de2f5694c..167932307eb 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -16,6 +16,7 @@ using System.Diagnostics; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; @@ -73,6 +74,9 @@ public static TracerProviderBuilder AddOtlpExporter( OtlpExporterOptions.RegisterOtlpExporterOptionsFactory(services); services.RegisterOptionsFactory(configuration => new SdkLimitOptions(configuration)); + services.TryAddSingleton< + OtlpExporterTransmissionHandler, + TracePersistentStorageTransmissionHandler>(); }); return builder.AddProcessor(sp => From 7182b25b07d011ae28bd7713455935ff23ecc028 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 21 Sep 2023 11:55:39 -0700 Subject: [PATCH 03/16] Remove persistent handler --- .../retry/OtlpExporterTransmissionHandler.cs | 3 +- ...acePersistentStorageTransmissionHandler.cs | 76 ------------------- .../OtlpTraceExporter.cs | 1 + .../OtlpTraceExporterHelperExtensions.cs | 5 +- 4 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index a33e56b9127..e614932edd0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -14,10 +14,11 @@ // limitations under the License. // +using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; -namespace OpenTelemetry.Exporter; +namespace OpenTelemetry.ExporterOpenTelemetryProtocol.Implementation.Retry; internal class OtlpExporterTransmissionHandler { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs deleted file mode 100644 index 07615ae7709..00000000000 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/TracePersistentStorageTransmissionHandler.cs +++ /dev/null @@ -1,76 +0,0 @@ -// -// 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 System.Timers; -using Google.Protobuf; -using OpenTelemetry.PersistentStorage.Abstractions; -using OpenTelemetry.PersistentStorage.FileSystem; -using OpenTelemetry.Proto.Collector.Trace.V1; - -namespace OpenTelemetry.Exporter; - -internal class TracePersistentStorageTransmissionHandler : OtlpExporterTransmissionHandler -{ - private PersistentBlobProvider persistentBlobProvider; - private System.Timers.Timer timer; - - public TracePersistentStorageTransmissionHandler() - { - this.persistentBlobProvider = new FileBlobProvider(@"c:\temp\otlp\trace"); - this.timer = new System.Timers.Timer(); - this.timer.Elapsed += this.RetryRequestFromStorage; - this.timer.Interval = 20000; - this.timer.AutoReset = true; - this.timer.Start(); - } - - protected override bool OnSubmitRequestExceptionThrown(ExportTraceServiceRequest request, Exception exception) - { - if (this.persistentBlobProvider.TryCreateBlob(request.ToByteArray(), out _)) - { - return true; - } - - return this.OnHandleDroppedRequest(request); - } - - private void RetryRequestFromStorage(object sender, ElapsedEventArgs e) - { - int fileCount = 0; - while (fileCount < 10) - { - if (this.persistentBlobProvider.TryGetBlob(out var blob)) - { - if (blob != null && blob.TryLease(20000) && blob.TryRead(out var data)) - { - var request = new ExportTraceServiceRequest(); - request.MergeFrom(data); - this.RetryRequest(request, out var exception); - if (exception == null) - { - blob.TryDelete(); - } - } - } - else - { - break; - } - - fileCount++; - } - } -} diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index 63f1c04f146..ce7bd8dd510 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.ExporterOpenTelemetryProtocol.Implementation.Retry; using OpenTelemetry.Internal; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; using OtlpResource = OpenTelemetry.Proto.Resource.V1; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 167932307eb..cfd3a5813f8 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -20,6 +20,7 @@ using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; +using OpenTelemetry.ExporterOpenTelemetryProtocol.Implementation.Retry; using OpenTelemetry.Internal; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; @@ -74,9 +75,7 @@ public static TracerProviderBuilder AddOtlpExporter( OtlpExporterOptions.RegisterOtlpExporterOptionsFactory(services); services.RegisterOptionsFactory(configuration => new SdkLimitOptions(configuration)); - services.TryAddSingleton< - OtlpExporterTransmissionHandler, - TracePersistentStorageTransmissionHandler>(); + services.TryAddSingleton>(); }); return builder.AddProcessor(sp => From 83c4e93e045bb18267d415dd3f1f89d653e02549 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 21 Sep 2023 13:23:33 -0700 Subject: [PATCH 04/16] rmv using --- .../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 58e39973372..fe982be89a4 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 Grpc.Core; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; From c0b13d16ad75f4eefe164df86f7990f3bb804bfa Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 21 Sep 2023 14:12:18 -0700 Subject: [PATCH 05/16] fix integration test --- .../OtlpTraceExporterHelperExtensions.cs | 55 ++++++++++--------- .../IntegrationTest/IntegrationTests.cs | 1 + 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index cfd3a5813f8..2daf1b06f9f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -80,34 +80,36 @@ public static TracerProviderBuilder AddOtlpExporter( return builder.AddProcessor(sp => { - OtlpExporterOptions exporterOptions; + OtlpExporterOptions exporterOptions; - if (name == null) - { - // 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 - 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); - } + if (name == null) + { + // 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 + 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); + } + + // 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; - // 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; + var transmissionmanager = sp.GetRequiredService>(); - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); }); } @@ -115,6 +117,7 @@ internal static BaseProcessor BuildOtlpExporterProcessor( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, + OtlpExporterTransmissionHandler transmissionHandler = null, Func, BaseExporter> configureExporterInstance = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); @@ -122,7 +125,7 @@ internal static BaseProcessor BuildOtlpExporterProcessor( BaseExporter otlpExporter = new OtlpTraceExporter( exporterOptions, sdkLimitOptions, - transmissionHandler: serviceProvider.GetRequiredService>()); + transmissionHandler: transmissionHandler ?? serviceProvider.GetRequiredService>()); if (configureExporterInstance != null) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs index e72b54bd3db..dea94219c23 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs @@ -86,6 +86,7 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo exporterOptions, DefaultSdkLimitOptions, serviceProvider: null, + new ExporterOpenTelemetryProtocol.Implementation.Retry.OtlpExporterTransmissionHandler(), configureExporterInstance: otlpExporter => { delegatingExporter = new DelegatingExporter From 185c5bea718b2c790efc44eeffaac4bde3f92cf8 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 21 Sep 2023 14:19:52 -0700 Subject: [PATCH 06/16] fix whitespace --- .../OtlpTraceExporterHelperExtensions.cs | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 2daf1b06f9f..0658196e15b 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -80,36 +80,36 @@ public static TracerProviderBuilder AddOtlpExporter( return builder.AddProcessor(sp => { - OtlpExporterOptions exporterOptions; + OtlpExporterOptions exporterOptions; - if (name == null) - { - // 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 - 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); - } + if (name == null) + { + // 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 + 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); + } - // 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; + // 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; - var transmissionmanager = sp.GetRequiredService>(); + var transmissionmanager = sp.GetRequiredService>(); - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); + return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); }); } From 04a69b4c2308825a49acc7af920f6c4011d5e653 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 25 Sep 2023 11:03:03 -0700 Subject: [PATCH 07/16] remarks --- .../retry/OtlpExporterTransmissionHandler.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index e614932edd0..342a1965d66 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -26,6 +26,11 @@ internal class OtlpExporterTransmissionHandler public OtlpExporterOptions Options { get; internal set; } + /// + /// Sends export request to the server. + /// + /// The request to send to the server. + /// True if the request is sent successfully or else false. public virtual bool SubmitRequest(T request) { try @@ -39,6 +44,12 @@ public virtual bool SubmitRequest(T request) } } + /// + /// Retries sending request to the server. + /// + /// The request to send to the server. + /// Exception encountered when trying to send request. + /// True if the request is sent successfully or else false. protected virtual bool RetryRequest(T request, out Exception exception) { try @@ -55,11 +66,22 @@ protected virtual bool RetryRequest(T request, out Exception exception) } } + /// + /// Callback to call when encountered exception while sending request to server. + /// + /// The request that was attempted to send to the server. + /// Exception that was encountered during request processing. + /// True or False, based on the implementation of handling errors. protected virtual bool OnSubmitRequestExceptionThrown(T request, Exception exception) { return this.OnHandleDroppedRequest(request); } + /// + /// Action to take when dropping request. + /// + /// The request that was attempted to send to the server. + /// True or False, based on the implementation. protected virtual bool OnHandleDroppedRequest(T request) { return false; From 28394d344977745f2418333ef758dd324f214263 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 25 Sep 2023 11:16:20 -0700 Subject: [PATCH 08/16] fix AOT --- .../OpenTelemetryProtocolExporterEventSource.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs index 9581ee595e0..2306db6db51 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs @@ -14,6 +14,9 @@ // limitations under the License. // +#if NET6_0_OR_GREATER +using System.Diagnostics.CodeAnalysis; +#endif using System.Diagnostics.Tracing; using OpenTelemetry.Internal; @@ -55,6 +58,9 @@ public void CouldNotTranslateActivity(string className, string methodName) this.WriteEvent(3, className, methodName); } +#if NET6_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe.")] +#endif [Event(4, Message = "Unknown error in export method. Message: '{0}'. IsRetry: {1}", Level = EventLevel.Error)] public void ExportMethodException(string ex, bool isRetry) { From 0de8c8275b6cc66bc5d39486de413ed1b0002f97 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 25 Sep 2023 15:54:51 -0700 Subject: [PATCH 09/16] nullable enable --- .../retry/OtlpExporterTransmissionHandler.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index 342a1965d66..c930d9a4c3c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -14,6 +14,8 @@ // limitations under the License. // +#nullable enable + using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; @@ -22,9 +24,9 @@ namespace OpenTelemetry.ExporterOpenTelemetryProtocol.Implementation.Retry; internal class OtlpExporterTransmissionHandler { - internal IExportClient ExportClient; + internal IExportClient? ExportClient; - public OtlpExporterOptions Options { get; internal set; } + public OtlpExporterOptions? Options { get; internal set; } /// /// Sends export request to the server. @@ -35,7 +37,7 @@ public virtual bool SubmitRequest(T request) { try { - return this.ExportClient.SendExportRequest(request); + return this.ExportClient == null ? false : this.ExportClient.SendExportRequest(request); } catch (Exception ex) { @@ -50,11 +52,11 @@ public virtual bool SubmitRequest(T request) /// The request to send to the server. /// Exception encountered when trying to send request. /// True if the request is sent successfully or else false. - protected virtual bool RetryRequest(T request, out Exception exception) + protected virtual bool RetryRequest(T request, out Exception? exception) { try { - var result = this.ExportClient.SendExportRequest(request); + var result = this.ExportClient == null ? false : this.ExportClient.SendExportRequest(request); exception = null; return result; } From f20c8e61529feb24e67e698a1b6261867a459d64 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 23 Jan 2024 09:35:03 -0800 Subject: [PATCH 10/16] nullable --- .../OtlpTraceExporterHelperExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 70695fadbf1..4dfe0c0b814 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -106,8 +106,8 @@ internal static BaseProcessor BuildOtlpExporterProcessor( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, - OtlpExporterTransmissionHandler transmissionHandler = null, - Func, BaseExporter> configureExporterInstance = null) + OtlpExporterTransmissionHandler? transmissionHandler = null, + Func, BaseExporter>? configureExporterInstance = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); From 64d2fbdf4418dce12113e23e0f0fe432050cc8e7 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 23 Jan 2024 10:17:40 -0800 Subject: [PATCH 11/16] fix header --- .../retry/OtlpExporterTransmissionHandler.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index c930d9a4c3c..b332ddd1b2c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -1,18 +1,5 @@ -// // 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. -// +// SPDX-License-Identifier: Apache-2.0 #nullable enable From 5cad7a3aa93e1f647dc0271197d23d0262503d91 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 24 Jan 2024 13:32:35 -0800 Subject: [PATCH 12/16] revert additional changes --- .../ExportClient/OtlpGrpcTraceExportClient.cs | 12 +++++++++++- .../retry/OtlpExporterTransmissionHandler.cs | 4 ++-- .../OtlpTraceExporter.cs | 19 ++++--------------- .../OtlpTraceExporterHelperExtensions.cs | 12 +----------- .../IntegrationTest/IntegrationTests.cs | 1 - 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs index c7fb7c34f13..8210587698a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcTraceExportClient.cs @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using Grpc.Core; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; @@ -29,7 +30,16 @@ public override bool SendExportRequest(OtlpCollector.ExportTraceServiceRequest r { var deadline = DateTime.UtcNow.AddMilliseconds(this.TimeoutMilliseconds); - this.traceClient.Export(request, headers: this.Headers, deadline: deadline, cancellationToken: cancellationToken); + try + { + this.traceClient.Export(request, headers: this.Headers, deadline: deadline, cancellationToken: cancellationToken); + } + catch (RpcException ex) + { + OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(this.Endpoint, ex); + + return false; + } return true; } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index b332ddd1b2c..72eebdde112 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -24,7 +24,7 @@ public virtual bool SubmitRequest(T request) { try { - return this.ExportClient == null ? false : this.ExportClient.SendExportRequest(request); + return this.ExportClient != null && this.ExportClient.SendExportRequest(request); } catch (Exception ex) { @@ -43,7 +43,7 @@ protected virtual bool RetryRequest(T request, out Exception? exception) { try { - var result = this.ExportClient == null ? false : this.ExportClient.SendExportRequest(request); + var result = this.ExportClient != null && this.ExportClient.SendExportRequest(request); exception = null; return result; } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs index 188c7fc2eb4..9e3ce7d283c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; -using OpenTelemetry.ExporterOpenTelemetryProtocol.Implementation.Retry; using OpenTelemetry.Internal; using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; using OtlpResource = OpenTelemetry.Proto.Resource.V1; @@ -19,7 +18,6 @@ public class OtlpTraceExporter : BaseExporter { private readonly SdkLimitOptions sdkLimitOptions; private readonly IExportClient exportClient; - private readonly OtlpExporterTransmissionHandler transmissionHandler; private OtlpResource.Resource processResource; @@ -28,7 +26,7 @@ public class OtlpTraceExporter : BaseExporter /// /// Configuration options for the export. public OtlpTraceExporter(OtlpExporterOptions options) - : this(options, new(), null, null) + : this(options, new(), null) { } @@ -38,12 +36,10 @@ public OtlpTraceExporter(OtlpExporterOptions options) /// . /// . /// Client used for sending export request. - /// Transmission handler for retrying failed requests. internal OtlpTraceExporter( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, - IExportClient exportClient = null, - OtlpExporterTransmissionHandler transmissionHandler = null) + IExportClient exportClient = null) { Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); @@ -68,13 +64,6 @@ internal OtlpTraceExporter( { this.exportClient = exporterOptions.GetTraceExportClient(); } - - transmissionHandler ??= new OtlpExporterTransmissionHandler(); - - transmissionHandler.ExportClient = this.exportClient; - transmissionHandler.Options = exporterOptions; - - this.transmissionHandler = transmissionHandler; } internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource(); @@ -91,7 +80,7 @@ public override ExportResult Export(in Batch activityBatch) { request.AddBatch(this.sdkLimitOptions, this.ProcessResource, activityBatch); - if (!this.transmissionHandler.SubmitRequest(request)) + if (!this.exportClient.SendExportRequest(request)) { return ExportResult.Failure; } @@ -112,6 +101,6 @@ public override ExportResult Export(in Batch activityBatch) /// protected override bool OnShutdown(int timeoutMilliseconds) { - return this.transmissionHandler.ExportClient?.Shutdown(timeoutMilliseconds) ?? true; + return this.exportClient?.Shutdown(timeoutMilliseconds) ?? true; } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 4dfe0c0b814..45231f63604 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -5,13 +5,10 @@ using System.Diagnostics; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; -using OpenTelemetry.ExporterOpenTelemetryProtocol.Implementation.Retry; using OpenTelemetry.Internal; -using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1; namespace OpenTelemetry.Trace; @@ -64,7 +61,6 @@ public static TracerProviderBuilder AddOtlpExporter( OtlpExporterOptions.RegisterOtlpExporterOptionsFactory(services); services.RegisterOptionsFactory(configuration => new SdkLimitOptions(configuration)); - services.TryAddSingleton>(); }); return builder.AddProcessor(sp => @@ -96,8 +92,6 @@ public static TracerProviderBuilder AddOtlpExporter( // instance. var sdkOptionsManager = sp.GetRequiredService>().CurrentValue; - var transmissionmanager = sp.GetRequiredService>(); - return BuildOtlpExporterProcessor(exporterOptions, sdkOptionsManager, sp); }); } @@ -106,15 +100,11 @@ internal static BaseProcessor BuildOtlpExporterProcessor( OtlpExporterOptions exporterOptions, SdkLimitOptions sdkLimitOptions, IServiceProvider serviceProvider, - OtlpExporterTransmissionHandler? transmissionHandler = null, Func, BaseExporter>? configureExporterInstance = null) { exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpTraceExporter"); - BaseExporter otlpExporter = new OtlpTraceExporter( - exporterOptions, - sdkLimitOptions, - transmissionHandler: transmissionHandler ?? serviceProvider.GetRequiredService>()); + BaseExporter otlpExporter = new OtlpTraceExporter(exporterOptions, sdkLimitOptions); if (configureExporterInstance != null) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs index d31097d0d5e..11b5b797127 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs @@ -73,7 +73,6 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo exporterOptions, DefaultSdkLimitOptions, serviceProvider: null, - new ExporterOpenTelemetryProtocol.Implementation.Retry.OtlpExporterTransmissionHandler(), configureExporterInstance: otlpExporter => { delegatingExporter = new DelegatingExporter From 728323b11342a2559c711c1cc1e124f95a95a655 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 24 Jan 2024 13:42:30 -0800 Subject: [PATCH 13/16] fix namespace --- .../Implementation/retry/OtlpExporterTransmissionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index 72eebdde112..7ec287ef2f2 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -7,7 +7,7 @@ using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; -namespace OpenTelemetry.ExporterOpenTelemetryProtocol.Implementation.Retry; +namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Retry; internal class OtlpExporterTransmissionHandler { From ce23a86120de20a0bd0c304bdc010f6776da7b50 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 24 Jan 2024 13:43:40 -0800 Subject: [PATCH 14/16] rmv using --- .../Implementation/retry/OtlpExporterTransmissionHandler.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs index 7ec287ef2f2..10ae69e7a3f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs @@ -3,8 +3,6 @@ #nullable enable -using OpenTelemetry.Exporter; -using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Retry; From 0fe45e74d841bc4777c8dddedb5de9dd6b580958 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 26 Jan 2024 12:12:15 -0800 Subject: [PATCH 15/16] rename --- .../{retry => Retry-t}/OtlpExporterTransmissionHandler.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/{retry => Retry-t}/OtlpExporterTransmissionHandler.cs (100%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Retry-t/OtlpExporterTransmissionHandler.cs similarity index 100% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/retry/OtlpExporterTransmissionHandler.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Retry-t/OtlpExporterTransmissionHandler.cs From f4b114c918f875016d90927c6908bc625343e6c6 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 26 Jan 2024 12:12:34 -0800 Subject: [PATCH 16/16] rename --- .../{Retry-t => Retry}/OtlpExporterTransmissionHandler.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/{Retry-t => Retry}/OtlpExporterTransmissionHandler.cs (100%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Retry-t/OtlpExporterTransmissionHandler.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Retry/OtlpExporterTransmissionHandler.cs similarity index 100% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Retry-t/OtlpExporterTransmissionHandler.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Retry/OtlpExporterTransmissionHandler.cs