diff --git a/examples/AspNetCore/Startup.cs b/examples/AspNetCore/Startup.cs index edd68209111..af1e9717659 100644 --- a/examples/AspNetCore/Startup.cs +++ b/examples/AspNetCore/Startup.cs @@ -134,7 +134,13 @@ public void ConfigureServices(IServiceCollection services) builder.AddOtlpExporter(); break; default: - builder.AddConsoleExporter(); + builder.AddConsoleExporter(options => + { + // 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; + }); break; } }); diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index f58b63a6b2f..f985add3e53 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -77,7 +77,8 @@ internal static object Run(MetricsOptions options) providerBuilder .AddConsoleExporter(o => { - o.MetricExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds; + o.MetricReaderType = MetricReaderType.Periodic; + o.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds; o.AggregationTemporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative; }); } diff --git a/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt index 62138841224..1e1b5bf2eb4 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/net461/PublicAPI.Unshipped.txt @@ -1,7 +1,9 @@ OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricExportIntervalMilliseconds.get -> int -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricExportIntervalMilliseconds.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 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 62138841224..1e1b5bf2eb4 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,7 +1,9 @@ OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Exporter.ConsoleExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricExportIntervalMilliseconds.get -> int -OpenTelemetry.Exporter.ConsoleExporterOptions.MetricExportIntervalMilliseconds.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 diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 93ccc8b92e5..df9b24ea5df 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Added configuration options for `MetricReaderType` to allow for configuring + the `ConsoleMetricExporter` to export either manually or periodically. + ([#2648](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2648)) + ## 1.2.0-beta2 Released 2021-Nov-19 diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs index cd56b910dc3..d75a31bbee2 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterMetricsExtensions.cs @@ -15,7 +15,6 @@ // using System; -using System.Threading; using OpenTelemetry.Exporter; using OpenTelemetry.Internal; @@ -39,9 +38,9 @@ public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder var exporter = new ConsoleMetricExporter(options); - var reader = options.MetricExportIntervalMilliseconds == Timeout.Infinite + var reader = options.MetricReaderType == MetricReaderType.Manual ? new BaseExportingMetricReader(exporter) - : new PeriodicExportingMetricReader(exporter, options.MetricExportIntervalMilliseconds); + : new PeriodicExportingMetricReader(exporter, options.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds); reader.PreferredAggregationTemporality = options.AggregationTemporality; diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs index 3c75ef2d9d1..93c7e3422c5 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using System.Threading; using OpenTelemetry.Metrics; namespace OpenTelemetry.Exporter @@ -27,9 +26,14 @@ public class ConsoleExporterOptions public ConsoleExporterOutputTargets Targets { get; set; } = ConsoleExporterOutputTargets.Console; /// - /// Gets or sets the metric export interval in milliseconds. The default value is Timeout.Infinite. + /// Gets or sets the to use. Defaults to MetricReaderType.Manual. /// - public int MetricExportIntervalMilliseconds { get; set; } = Timeout.Infinite; + 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 diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index 9bfa7df92f2..4d61f50b233 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -70,6 +70,9 @@ OpenTelemetry.Metrics.MetricReader.PreferredAggregationTemporality.set -> void OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Metrics.MetricReader.SupportedAggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Metrics.MetricReader.SupportedAggregationTemporality.set -> void +OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Metrics.MetricReaderType.Manual = 0 -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Metrics.MetricReaderType.Periodic = 1 -> OpenTelemetry.Metrics.MetricReaderType OpenTelemetry.Metrics.MetricStreamConfiguration OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void @@ -87,6 +90,10 @@ OpenTelemetry.Metrics.MetricType.LongSum = 26 -> OpenTelemetry.Metrics.MetricTyp OpenTelemetry.Metrics.MetricTypeExtensions OpenTelemetry.Metrics.PeriodicExportingMetricReader OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter exporter, int exportIntervalMilliseconds = 60000, int exportTimeoutMilliseconds = 30000) -> void +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.PeriodicExportingMetricReaderOptions() -> void +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds.get -> int +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds.set -> void OpenTelemetry.ReadOnlyTagCollection OpenTelemetry.ReadOnlyTagCollection.Count.get -> int OpenTelemetry.ReadOnlyTagCollection.Enumerator diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 9bfa7df92f2..4d61f50b233 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -70,6 +70,9 @@ OpenTelemetry.Metrics.MetricReader.PreferredAggregationTemporality.set -> void OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Metrics.MetricReader.SupportedAggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Metrics.MetricReader.SupportedAggregationTemporality.set -> void +OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Metrics.MetricReaderType.Manual = 0 -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Metrics.MetricReaderType.Periodic = 1 -> OpenTelemetry.Metrics.MetricReaderType OpenTelemetry.Metrics.MetricStreamConfiguration OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void @@ -87,6 +90,10 @@ OpenTelemetry.Metrics.MetricType.LongSum = 26 -> OpenTelemetry.Metrics.MetricTyp OpenTelemetry.Metrics.MetricTypeExtensions OpenTelemetry.Metrics.PeriodicExportingMetricReader OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter exporter, int exportIntervalMilliseconds = 60000, int exportTimeoutMilliseconds = 30000) -> void +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.PeriodicExportingMetricReaderOptions() -> void +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds.get -> int +OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds.set -> void OpenTelemetry.ReadOnlyTagCollection OpenTelemetry.ReadOnlyTagCollection.Count.get -> int OpenTelemetry.ReadOnlyTagCollection.Enumerator diff --git a/src/OpenTelemetry/Metrics/MetricReaderType.cs b/src/OpenTelemetry/Metrics/MetricReaderType.cs new file mode 100644 index 00000000000..4c20574f552 --- /dev/null +++ b/src/OpenTelemetry/Metrics/MetricReaderType.cs @@ -0,0 +1,36 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace OpenTelemetry.Metrics +{ + /// + /// Type of to be used. + /// + public enum MetricReaderType + { + /// + /// Use the . + /// This requires manually invoking MetricReader.Collect() to export metrics. + /// + Manual, + + /// + /// Use the . + /// MetricReader.Collect() will be invoked on a defined interval. + /// + Periodic, + } +} diff --git a/src/OpenTelemetry/Metrics/PeriodicExportingMetricReaderOptions.cs b/src/OpenTelemetry/Metrics/PeriodicExportingMetricReaderOptions.cs new file mode 100644 index 00000000000..af1df534cdc --- /dev/null +++ b/src/OpenTelemetry/Metrics/PeriodicExportingMetricReaderOptions.cs @@ -0,0 +1,26 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace OpenTelemetry.Metrics +{ + public class PeriodicExportingMetricReaderOptions + { + /// + /// Gets or sets the metric export interval in milliseconds. The default value is 60000. + /// + public int ExportIntervalMilliseconds { get; set; } = 60000; + } +}