From 0a161b63cbcadc7c1fcbc7ceb3570b50a72d9284 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Wed, 19 Aug 2020 17:54:21 -0700 Subject: [PATCH 1/3] migrate zipkin exporter to BatchExportActivityProcessor --- .../ZipkinExporter.cs | 27 +++++++++---------- .../ZipkinExporterHelperExtensions.cs | 2 +- .../Exporter/ZipkinExporterBenchmarks.cs | 9 +++---- .../ZipkinExporterTests.cs | 10 +++---- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index fe1ec5ef1e9..ab8cd1db3e1 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -37,7 +37,7 @@ namespace OpenTelemetry.Exporter.Zipkin /// /// Zipkin exporter. /// - public class ZipkinExporter : ActivityExporter + public class ZipkinExporter : ActivityExporterSync { private readonly ZipkinExporterOptions options; private readonly HttpClient httpClient; @@ -57,33 +57,30 @@ public ZipkinExporter(ZipkinExporterOptions options, HttpClient client = null) internal ZipkinEndpoint LocalEndpoint { get; } /// - public override async Task ExportAsync(IEnumerable batchActivity, CancellationToken cancellationToken) + public override ExportResultSync Export(in Batch batch) { try { - await this.SendBatchActivityAsync(batchActivity, cancellationToken).ConfigureAwait(false); + // take a snapshot of the batch + var activities = new List(); + foreach (var activity in batch) + { + activities.Add(activity); + } + + this.SendBatchActivityAsync(activities, CancellationToken.None).RunSynchronously(); - return ExportResult.Success; + return ExportResultSync.Success; } catch (Exception ex) { ZipkinExporterEventSource.Log.FailedExport(ex); // TODO distinguish retryable exceptions - return ExportResult.FailedNotRetryable; + return ExportResultSync.Failure; } } - /// - public override Task ShutdownAsync(CancellationToken cancellationToken) - { -#if NET452 - return Task.FromResult(0); -#else - return Task.CompletedTask; -#endif - } - private static string ResolveHostAddress(string hostName, AddressFamily family) { string result = null; diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs index bbc157423c7..142cc7203b1 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs @@ -42,7 +42,7 @@ public static TracerProviderBuilder AddZipkinExporter(this TracerProviderBuilder var zipkinExporter = new ZipkinExporter(exporterOptions); // TODO: Pick Simple vs Batching based on ZipkinExporterOptions - return builder.AddProcessor(new SimpleActivityProcessor(zipkinExporter)); + return builder.AddProcessor(new BatchExportActivityProcessor(zipkinExporter)); } } } diff --git a/test/Benchmarks/Exporter/ZipkinExporterBenchmarks.cs b/test/Benchmarks/Exporter/ZipkinExporterBenchmarks.cs index bc14d492cde..30075ef2bcc 100644 --- a/test/Benchmarks/Exporter/ZipkinExporterBenchmarks.cs +++ b/test/Benchmarks/Exporter/ZipkinExporterBenchmarks.cs @@ -22,6 +22,7 @@ using BenchmarkDotNet.Attributes; using OpenTelemetry.Exporter.Zipkin; using OpenTelemetry.Tests; +using OpenTelemetry.Trace; namespace Benchmarks.Exporter { @@ -60,21 +61,19 @@ public void GlobalCleanup() } [Benchmark] - public async Task ZipkinExporter_ExportAsync() + public void ZipkinExporter_Export() { var zipkinExporter = new ZipkinExporter( new ZipkinExporterOptions { Endpoint = new Uri($"http://{this.serverHost}:{this.serverPort}"), }); + var processor = new SimpleExportActivityProcessor(zipkinExporter); - var activities = new List(this.NumberOfActivities); for (int i = 0; i < this.NumberOfActivities; i++) { - activities.Add(this.testActivity); + processor.OnEnd(this.testActivity); } - - await zipkinExporter.ExportAsync(activities, CancellationToken.None).ConfigureAwait(false); } private Activity CreateTestActivity() diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index a9dc31b6295..0f869c4e8b1 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -94,10 +94,8 @@ public void ZipkinExporter_BadArgs() [Theory] [InlineData(true)] [InlineData(false)] - public async Task ZipkinExporterIntegrationTest(bool useShortTraceIds) + public void ZipkinExporterIntegrationTest(bool useShortTraceIds) { - var batchActivity = new List { CreateTestActivity() }; - Guid requestId = Guid.NewGuid(); ZipkinExporter exporter = new ZipkinExporter( @@ -107,11 +105,11 @@ public async Task ZipkinExporterIntegrationTest(bool useShortTraceIds) UseShortTraceIds = useShortTraceIds, }); - await exporter.ExportAsync(batchActivity, CancellationToken.None).ConfigureAwait(false); + var activity = CreateTestActivity(); + var processor = new SimpleExportActivityProcessor(exporter); - await exporter.ShutdownAsync(CancellationToken.None).ConfigureAwait(false); + processor.OnEnd(activity); - var activity = batchActivity[0]; var context = activity.Context; var timestamp = activity.StartTimeUtc.ToEpochMicroseconds(); From 8ef24c127555cd6d636076b77c8aa247d97c9805 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Wed, 19 Aug 2020 18:08:16 -0700 Subject: [PATCH 2/3] update changelog --- src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md index 6ccc9e6e3e1..a1c959756db 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md @@ -2,7 +2,10 @@ ## Unreleased -Renamed extension method from `UseZipkinExporter` to `AddZipkinExporter`. +* Renamed extension method from `UseZipkinExporter` to `AddZipkinExporter` + ([#1066](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1066)) +* Changed `ZipkinExporter` to use `BatchExportActivityProcessor` by default + ([#1103](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1103)) ## 0.4.0-beta.2 From 407b750d58b0f969758d39fa384b7973086b2a84 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Wed, 19 Aug 2020 20:24:56 -0700 Subject: [PATCH 3/3] fix test failure --- src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index ab8cd1db3e1..38cb49b82ee 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -68,7 +68,7 @@ public override ExportResultSync Export(in Batch batch) activities.Add(activity); } - this.SendBatchActivityAsync(activities, CancellationToken.None).RunSynchronously(); + this.SendBatchActivityAsync(activities, CancellationToken.None).GetAwaiter().GetResult(); return ExportResultSync.Success; }