From 85ebeef39b39d1436609a5132c6a89aa4dac4660 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Tue, 13 Sep 2022 15:05:37 -0700 Subject: [PATCH 1/2] Add named options support to console exporter tracer & logger provider builder extensions. --- .../.publicApi/net462/PublicAPI.Unshipped.txt | 8 +++++ .../netstandard2.0/PublicAPI.Unshipped.txt | 8 +++++ .../CHANGELOG.md | 10 ++++++ .../ConsoleExporterHelperExtensions.cs | 31 ++++++++++++++++--- .../ConsoleExporterLoggingExtensions.cs | 31 ++++++++++++++++--- 5 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt index 0f6bd0c9e9a..427104a7a52 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,3 +1,11 @@ override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void +*REMOVED*static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions +static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions +static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions +static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder +*REMOVED*static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 0f6bd0c9e9a..427104a7a52 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,3 +1,11 @@ override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void +*REMOVED*static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions +static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions +static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions +static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder +*REMOVED*static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.ConsoleExporterHelperExtensions.AddConsoleExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 1b584dd454a..f251a723892 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -11,6 +11,16 @@ management ([#3648](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3648)) +* Added overloads which accept a name to the `OpenTelemetryLoggerOptions` + `AddConsoleExporter` extension to allow for more fine-grained options + management + ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + +* Added overloads which accept a name to the `TracerProviderBuilder` + `AddConsoleExporter` extension to allow for more fine-grained options + management + ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ## 1.4.0-alpha.2 Released 2022-Aug-18 diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs index 2f5ed77ab4d..2bb84b49c8b 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs @@ -28,20 +28,43 @@ public static class ConsoleExporterHelperExtensions /// Adds Console exporter to the TracerProvider. /// /// builder to use. - /// Exporter configuration options. /// The instance of to chain the calls. - public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder, Action configure = null) + public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder) + => AddConsoleExporter(builder, name: null, configure: null); + + /// + /// Adds Console exporter to the TracerProvider. + /// + /// builder to use. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilder builder, Action configure) + => AddConsoleExporter(builder, name: null, configure); + + /// + /// Adds Console 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 AddConsoleExporter( + 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); builder.AddProcessor(new SimpleActivityExportProcessor(new ConsoleActivityExporter(options))); }); diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs index 5e5de098833..7e85c968cb5 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs @@ -28,20 +28,43 @@ public static class ConsoleExporterLoggingExtensions /// Adds Console exporter with OpenTelemetryLoggerOptions. /// /// options to use. - /// Exporter configuration options. /// The instance of to chain the calls. - public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action configure = null) + public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions) + => AddConsoleExporter(loggerOptions, name: null, configure: null); + + /// + /// Adds Console exporter with OpenTelemetryLoggerOptions. + /// + /// options to use. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action configure) + => AddConsoleExporter(loggerOptions, name: null, configure); + + /// + /// Adds Console exporter with OpenTelemetryLoggerOptions. + /// + /// options to use. + /// Name which is used when retrieving options. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static OpenTelemetryLoggerOptions AddConsoleExporter( + this OpenTelemetryLoggerOptions loggerOptions, + string name, + Action configure) { Guard.ThrowIfNull(loggerOptions); + name ??= Options.DefaultName; + if (configure != null) { - loggerOptions.ConfigureServices(services => services.Configure(configure)); + loggerOptions.ConfigureServices(services => services.Configure(name, configure)); } return loggerOptions.ConfigureProvider((sp, provider) => { - var options = sp.GetRequiredService>().Value; + var options = sp.GetRequiredService>().Get(name); provider.AddProcessor(new SimpleLogRecordExportProcessor(new ConsoleLogRecordExporter(options))); }); From fc0807dd6c0be29792e80f90e9f8c8e3fd3ef86c Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Tue, 13 Sep 2022 15:07:45 -0700 Subject: [PATCH 2/2] CHANGELOG update. --- src/OpenTelemetry.Exporter.Console/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index f251a723892..535977e3b31 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -14,12 +14,12 @@ * Added overloads which accept a name to the `OpenTelemetryLoggerOptions` `AddConsoleExporter` extension to allow for more fine-grained options management - ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ([#3657](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3657)) * Added overloads which accept a name to the `TracerProviderBuilder` `AddConsoleExporter` extension to allow for more fine-grained options management - ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ([#3657](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3657)) ## 1.4.0-alpha.2