From a87f8f7373b13dad994e5a9414aed356ec712f67 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Tue, 13 Sep 2022 14:22:04 -0700 Subject: [PATCH] [Traces] Add named options support to ZipkinExporter builder extensions (#3655) * Add named options support to zipkin provider builder extensions. * CHANGELOG update. --- .../.publicApi/net462/PublicAPI.Unshipped.txt | 4 +++ .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 4 +++ .../netstandard2.0/PublicAPI.Unshipped.txt | 4 +++ .../CHANGELOG.md | 5 +++ .../ZipkinExporterHelperExtensions.cs | 31 ++++++++++++++++--- .../ZipkinExporterTests.cs | 21 +++++++++++++ 6 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net462/PublicAPI.Unshipped.txt index e69de29bb2d..62aa18b630b 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net462/PublicAPI.Unshipped.txt @@ -0,0 +1,4 @@ +*REMOVED*static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net6.0/PublicAPI.Unshipped.txt index e69de29bb2d..62aa18b630b 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -0,0 +1,4 @@ +*REMOVED*static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index e69de29bb2d..62aa18b630b 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -0,0 +1,4 @@ +*REMOVED*static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md index a25f7cd903c..cfed2ec4145 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Added overloads which accept a name to the `TracerProviderBuilder` + `AddZipkinExporter` extension to allow for more fine-grained options + management + ([#3655](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3655)) + ## 1.4.0-alpha.2 Released 2022-Aug-18 diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs index cccf2c432cd..484254c68e2 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs @@ -33,20 +33,43 @@ public static class ZipkinExporterHelperExtensions /// Adds Zipkin exporter to the TracerProvider. /// /// builder to use. - /// Exporter configuration options. /// The instance of to chain the calls. - public static TracerProviderBuilder AddZipkinExporter(this TracerProviderBuilder builder, Action configure = null) + public static TracerProviderBuilder AddZipkinExporter(this TracerProviderBuilder builder) + => AddZipkinExporter(builder, name: null, configure: null); + + /// + /// Adds Zipkin exporter to the TracerProvider. + /// + /// builder to use. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddZipkinExporter(this TracerProviderBuilder builder, Action configure) + => AddZipkinExporter(builder, name: null, configure); + + /// + /// Adds Zipkin exporter to the TracerProvider. + /// + /// builder to use. + /// Name which is used when retrieving options. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddZipkinExporter( + this TracerProviderBuilder builder, + string name, + Action configure) { Guard.ThrowIfNull(builder); + name ??= Options.DefaultName; + if (configure != null) { - builder.ConfigureServices(services => services.Configure(configure)); + builder.ConfigureServices(services => services.Configure(name, configure)); } return builder.ConfigureBuilder((sp, builder) => { - var options = sp.GetRequiredService>().Value; + var options = sp.GetRequiredService>().Get(name); AddZipkinExporter(builder, options, sp); }); diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index 37b715501a6..4cd2d97d2e5 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -84,6 +84,27 @@ public void Dispose() GC.SuppressFinalize(this); } + [Fact] + public void AddAddZipkinExporterNamedOptionsSupported() + { + int defaultExporterOptionsConfigureOptionsInvocations = 0; + int namedExporterOptionsConfigureOptionsInvocations = 0; + + using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .ConfigureServices(services => + { + services.Configure(o => defaultExporterOptionsConfigureOptionsInvocations++); + + services.Configure("Exporter2", o => namedExporterOptionsConfigureOptionsInvocations++); + }) + .AddZipkinExporter() + .AddZipkinExporter("Exporter2", o => { }) + .Build(); + + Assert.Equal(1, defaultExporterOptionsConfigureOptionsInvocations); + Assert.Equal(1, namedExporterOptionsConfigureOptionsInvocations); + } + [Fact] public void BadArgs() {