From db300af4c4db8d6e9df6cb179fef7c216c32955d Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:34:55 -0800 Subject: [PATCH 1/4] Remove options for MetricReader from ConsoleExporterOptions --- examples/AspNetCore/Startup.cs | 8 +- examples/Console/TestMetrics.cs | 10 ++- .../ConsoleExporterMetricsExtensions.cs | 88 ++++++++++++++++--- .../ConsoleExporterOptions.cs | 18 ---- 4 files changed, 87 insertions(+), 37 deletions(-) diff --git a/examples/AspNetCore/Startup.cs b/examples/AspNetCore/Startup.cs index 51c485b1303..88199d052d7 100644 --- a/examples/AspNetCore/Startup.cs +++ b/examples/AspNetCore/Startup.cs @@ -134,12 +134,14 @@ public void ConfigureServices(IServiceCollection services) builder.AddOtlpExporter(); break; default: - builder.AddConsoleExporter(options => + builder.AddConsoleExporter((exporterOptions, metricReaderOptions) => { + exporterOptions.Targets = ConsoleExporterOutputTargets.Console; + // The ConsoleMetricExporter defaults to a manual collect cycle. // This configuration causes metrics to be exported to stdout on a 10s interval. - options.MetricReaderType = MetricReaderType.Periodic; - options.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 10000; + metricReaderOptions.MetricReaderType = MetricReaderType.Periodic; + metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 10000; }); break; } diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index 3e20efcc541..15abffbded4 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -79,11 +79,13 @@ internal static object Run(MetricsOptions options) else { providerBuilder - .AddConsoleExporter(o => + .AddConsoleExporter((exporterOptions, metricReaderOptions) => { - o.MetricReaderType = MetricReaderType.Periodic; - o.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds; - o.AggregationTemporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative; + exporterOptions.Targets = ConsoleExporterOutputTargets.Console; + + metricReaderOptions.MetricReaderType = MetricReaderType.Periodic; + metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds; + metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative; }); } diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs index e2cfba27fe0..c2a9c3f24c0 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs @@ -20,31 +20,95 @@ namespace OpenTelemetry.Metrics { + /// + /// Extension methods to simplify registering of the Console exporter. + /// public static class ConsoleExporterMetricsExtensions { /// - /// Adds Console exporter to the TracerProvider. + /// Adds to the using default options. /// /// builder to use. - /// Exporter configuration options. /// The instance of to chain the calls. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The objects should not be disposed.")] - public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder builder, Action configure = null) + public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder builder) + { + return AddConsoleExporter(builder, options => { }); + } + + /// + /// Adds to the . + /// + /// builder to use. + /// Exporter configuration options. + /// The instance of to chain the calls. + public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder builder, Action configureExporter) { Guard.ThrowIfNull(builder); - var options = new ConsoleExporterOptions(); - configure?.Invoke(options); + if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder) + { + return deferredMeterProviderBuilder.Configure((sp, builder) => + { + AddConsoleExporter(builder, sp.GetOptions(), sp.GetOptions(), configureExporter, null, sp); + }); + } + + return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), configureExporter, null, serviceProvider: null); + } + + /// + /// Adds to the . + /// + /// builder to use. + /// Exporter and configuration options. + /// The instance of to chain the calls. + public static MeterProviderBuilder AddConsoleExporter( + this MeterProviderBuilder builder, + Action configureExporterAndMetricReader) + { + Guard.ThrowIfNull(builder, nameof(builder)); + + if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder) + { + return deferredMeterProviderBuilder.Configure((sp, builder) => + { + AddConsoleExporter(builder, sp.GetOptions(), sp.GetOptions(), null, configureExporterAndMetricReader, sp); + }); + } + + return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), null, configureExporterAndMetricReader, serviceProvider: null); + } + + private static MeterProviderBuilder AddConsoleExporter( + MeterProviderBuilder builder, + ConsoleExporterOptions exporterOptions, + MetricReaderOptions metricReaderOptions, + Action configureExporter, + Action configureExporterAndMetricReader, + IServiceProvider serviceProvider) + { + if (configureExporterAndMetricReader != null) + { + configureExporterAndMetricReader.Invoke(exporterOptions, metricReaderOptions); + } + else + { + configureExporter?.Invoke(exporterOptions); + } - var exporter = new ConsoleMetricExporter(options); + var metricExporter = new ConsoleMetricExporter(exporterOptions); - var reader = options.MetricReaderType == MetricReaderType.Manual - ? new BaseExportingMetricReader(exporter) - : new PeriodicExportingMetricReader(exporter, options.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds); + if (metricReaderOptions.MetricReaderType == (MetricReaderType)(-1)) + { + metricReaderOptions.MetricReaderType = MetricReaderType.Manual; + } - reader.Temporality = options.AggregationTemporality; + var metricReader = metricReaderOptions.MetricReaderType == MetricReaderType.Manual + ? new BaseExportingMetricReader(metricExporter) + : new PeriodicExportingMetricReader(metricExporter, metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds); - return builder.AddReader(reader); + metricReader.Temporality = metricReaderOptions.Temporality; + return builder.AddReader(metricReader); } } } diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs index 93c7e3422c5..a7183ea489f 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs @@ -14,8 +14,6 @@ // limitations under the License. // -using OpenTelemetry.Metrics; - namespace OpenTelemetry.Exporter { public class ConsoleExporterOptions @@ -24,21 +22,5 @@ public class ConsoleExporterOptions /// Gets or sets the output targets for the console exporter. /// public ConsoleExporterOutputTargets Targets { get; set; } = ConsoleExporterOutputTargets.Console; - - /// - /// Gets or sets the to use. Defaults to MetricReaderType.Manual. - /// - public MetricReaderType MetricReaderType { get; set; } = MetricReaderType.Manual; - - /// - /// Gets or sets the options. Ignored unless MetricReaderType is Periodic. - /// - public PeriodicExportingMetricReaderOptions PeriodicExportingMetricReaderOptions { get; set; } = new PeriodicExportingMetricReaderOptions(); - - /// - /// Gets or sets the AggregationTemporality used for Histogram - /// and Sum metrics. - /// - public AggregationTemporality AggregationTemporality { get; set; } = AggregationTemporality.Delta; } } From 0b6f0142e014dc47f65c6305d2c7d6dc309336f1 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:48:01 -0800 Subject: [PATCH 2/4] Update changelogs --- src/OpenTelemetry.Exporter.Console/CHANGELOG.md | 5 +++++ .../CHANGELOG.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 69e9e9aa40f..cffe9d5dfd6 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Removes metric related configuration options from `ConsoleExporterOptions`. + `MetricReaderType`, `PeriodicExporterMetricReaderOptions`, and `Temporality` + are now configurable via the `MetricReaderOptions`. + ([#2929](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2929)) + ## 1.2.0-rc2 Released 2022-Feb-02 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index da8dedcd2ad..e8ddd8a3c72 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -9,6 +9,11 @@ The default value is `http://localhost:4318`. ([#2868](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2868)) +* Removes metric related configuration options from `OtlpExporterOptions`. + `MetricReaderType`, `PeriodicExporterMetricReaderOptions`, and `Temporality` + are now configurable via the `MetricReaderOptions`. + ([#2717](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2717)) + ## 1.2.0-rc2 Released 2022-Feb-02 From 06225b52c518ffc364ae67fc3b9780c6f4599893 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 22 Feb 2022 16:17:49 -0800 Subject: [PATCH 3/4] Remove unused parameter --- .../ConsoleExporterMetricsExtensions.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs index c2a9c3f24c0..0c35b81bdea 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs @@ -49,11 +49,11 @@ public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder { return deferredMeterProviderBuilder.Configure((sp, builder) => { - AddConsoleExporter(builder, sp.GetOptions(), sp.GetOptions(), configureExporter, null, sp); + AddConsoleExporter(builder, sp.GetOptions(), sp.GetOptions(), configureExporter, null); }); } - return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), configureExporter, null, serviceProvider: null); + return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), configureExporter, null); } /// @@ -72,11 +72,11 @@ public static MeterProviderBuilder AddConsoleExporter( { return deferredMeterProviderBuilder.Configure((sp, builder) => { - AddConsoleExporter(builder, sp.GetOptions(), sp.GetOptions(), null, configureExporterAndMetricReader, sp); + AddConsoleExporter(builder, sp.GetOptions(), sp.GetOptions(), null, configureExporterAndMetricReader); }); } - return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), null, configureExporterAndMetricReader, serviceProvider: null); + return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), null, configureExporterAndMetricReader); } private static MeterProviderBuilder AddConsoleExporter( @@ -84,8 +84,7 @@ private static MeterProviderBuilder AddConsoleExporter( ConsoleExporterOptions exporterOptions, MetricReaderOptions metricReaderOptions, Action configureExporter, - Action configureExporterAndMetricReader, - IServiceProvider serviceProvider) + Action configureExporterAndMetricReader) { if (configureExporterAndMetricReader != null) { From e66970ddf3b521fb5fbfa76a04261f8080e348c1 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:17:54 -0800 Subject: [PATCH 4/4] Update public API --- .../.publicApi/net461/PublicAPI.Unshipped.txt | 10 +++------- .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt index 1e1b5bf2eb4..157653feeb4 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt @@ -1,11 +1,7 @@ -OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality -OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricReaderType.set -> void -OpenTelemetry.Exporter.ConsoleExporterOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions -OpenTelemetry.Exporter.ConsoleExporterOptions.PeriodicExportingMetricReaderOptions.set -> void OpenTelemetry.Exporter.ConsoleMetricExporter OpenTelemetry.Exporter.ConsoleMetricExporter.ConsoleMetricExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions override OpenTelemetry.Exporter.ConsoleMetricExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder \ No newline at end of file +static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder 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 1e1b5bf2eb4..157653feeb4 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,11 +1,7 @@ -OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality -OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricReaderType.set -> void -OpenTelemetry.Exporter.ConsoleExporterOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions -OpenTelemetry.Exporter.ConsoleExporterOptions.PeriodicExportingMetricReaderOptions.set -> void OpenTelemetry.Exporter.ConsoleMetricExporter OpenTelemetry.Exporter.ConsoleMetricExporter.ConsoleMetricExporter(OpenTelemetry.Exporter.ConsoleExporterOptions options) -> void OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions override OpenTelemetry.Exporter.ConsoleMetricExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult -static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder \ No newline at end of file +static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder