From ee5b0385407acabda73da8f72740142c54917911 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Fri, 21 Aug 2020 12:32:53 -0300 Subject: [PATCH] Migrate JaegerExporter to BatchExportActivityProcessor (#1125) * Updating Jaeger Exporter * updating changelog --- .../CHANGELOG.md | 2 ++ .../JaegerExporter.cs | 27 ++++++++++++------- .../JaegerExporterHelperExtensions.cs | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md index 29f5caba5d2..037bc050ac3 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +* Changed `JaegerExporter` to use `BatchExportActivityProcessor` by default + ([#1125](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1125)) * Span links will now be sent as `FOLLOWS_FROM` reference type. Previously they were sent as `CHILD_OF`. ([#970](https://github.com/open-telemetry/opentelemetry-dotnet/pull/970)) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index e8857dd0045..4483cd9aa0b 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -13,19 +13,18 @@ // See the License for the specific language governing permissions and // limitations under the License. // + using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Threading; -using System.Threading.Tasks; using OpenTelemetry.Exporter.Jaeger.Implementation; using OpenTelemetry.Resources; using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter.Jaeger { - public class JaegerExporter : ActivityExporter + public class JaegerExporter : ActivityExporterSync { private bool libraryResourceApplied; private bool disposedValue; // To detect redundant dispose calls @@ -37,26 +36,34 @@ public JaegerExporter(JaegerExporterOptions options) internal JaegerUdpBatcher JaegerAgentUdpBatcher { get; } - public override async Task ExportAsync(IEnumerable activityBatch, CancellationToken cancellationToken) + /// + public override ExportResultSync Export(in Batch activityBatch) { - if (!this.libraryResourceApplied && activityBatch.Any()) + var activities = new List(); + foreach (var activity in activityBatch) + { + activities.Add(activity); + } + + if (!this.libraryResourceApplied && activities.Any()) { - var libraryResource = activityBatch.First().GetResource(); + var libraryResource = activities.First().GetResource(); this.ApplyLibraryResource(libraryResource ?? Resource.Empty); this.libraryResourceApplied = true; } - await this.JaegerAgentUdpBatcher.AppendBatchAsync(activityBatch, cancellationToken).ConfigureAwait(false); + this.JaegerAgentUdpBatcher.AppendBatchAsync(activities, default).GetAwaiter().GetResult(); // TODO jaeger status to ExportResult - return ExportResult.Success; + return ExportResultSync.Success; } - public override async Task ShutdownAsync(CancellationToken cancellationToken) + /// + public override void Shutdown() { - await this.JaegerAgentUdpBatcher.FlushAsync(cancellationToken).ConfigureAwait(false); + this.JaegerAgentUdpBatcher.FlushAsync(default).GetAwaiter().GetResult(); } internal void ApplyLibraryResource(Resource libraryResource) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs index eec7165e9c1..88e9b6f9e4d 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs @@ -42,7 +42,7 @@ public static TracerProviderBuilder AddJaegerExporter(this TracerProviderBuilder var jaegerExporter = new JaegerExporter(exporterOptions); // TODO: Pick Simple vs Batching based on JaegerExporterOptions - return builder.AddProcessor(new SimpleActivityProcessor(jaegerExporter)); + return builder.AddProcessor(new BatchExportActivityProcessor(jaegerExporter)); } } }