diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index f985add3e53..753e2ee4873 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -68,7 +68,8 @@ internal static object Run(MetricsOptions options) providerBuilder .AddOtlpExporter(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.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt index a2b66e32a7b..019222ac6fc 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt @@ -9,8 +9,10 @@ OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTeleme OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.get -> int -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.OtlpExporterOptions() -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.set -> void diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Shipped.txt index 8ec11493d3a..b457c2d381d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Shipped.txt @@ -15,4 +15,4 @@ OpenTelemetry.Exporter.OtlpTraceExporter.OtlpTraceExporter(OpenTelemetry.Exporte OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions override OpenTelemetry.Exporter.OtlpTraceExporter.Export(in OpenTelemetry.Batch activityBatch) -> OpenTelemetry.ExportResult override OpenTelemetry.Exporter.OtlpTraceExporter.OnShutdown(int timeoutMilliseconds) -> bool -static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder \ No newline at end of file +static OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Unshipped.txt index 5623755decc..5e639038eaa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Unshipped.txt @@ -1,7 +1,9 @@ OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.get -> int -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.set -> void OpenTelemetry.Exporter.OtlpExportProtocol @@ -12,4 +14,4 @@ OpenTelemetry.Exporter.OtlpMetricExporter.OtlpMetricExporter(OpenTelemetry.Expor OpenTelemetry.Metrics.OtlpMetricExporterExtensions override OpenTelemetry.Exporter.OtlpMetricExporter.Export(in OpenTelemetry.Batch metrics) -> OpenTelemetry.ExportResult override OpenTelemetry.Exporter.OtlpMetricExporter.OnShutdown(int timeoutMilliseconds) -> bool -static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder \ No newline at end of file +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index cb00454d3bf..5e639038eaa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,7 +1,9 @@ OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.get -> int -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.set -> void OpenTelemetry.Exporter.OtlpExportProtocol diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index cb00454d3bf..5e639038eaa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,7 +1,9 @@ OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.set -> void -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.get -> int -OpenTelemetry.Exporter.OtlpExporterOptions.MetricExportIntervalMilliseconds.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Exporter.OtlpExporterOptions.MetricReaderType.set -> void +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Exporter.OtlpExporterOptions.PeriodicExportingMetricReaderOptions.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.set -> void OpenTelemetry.Exporter.OtlpExportProtocol diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 704f3ed69c9..152b15123ef 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Added configuration options for `MetricReaderType` to allow for configuring + the `OtlpMetricExporter` to export either manually or periodically. + ([#2674](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2674)) + ## 1.2.0-beta2 Released 2021-Nov-19 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index 6ed3e13a161..f46bbe61559 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -109,9 +109,14 @@ public OtlpExporterOptions() public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchExportActivityProcessorOptions(); /// - /// Gets or sets the metric export interval in milliseconds. The default value is 60000. + /// Gets or sets the to use. Defaults to MetricReaderType.Periodic. /// - public int MetricExportIntervalMilliseconds { get; set; } = 60000; + public MetricReaderType MetricReaderType { get; set; } = MetricReaderType.Periodic; + + /// + /// 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.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index 8b314befe5a..46e672a844c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -55,7 +55,11 @@ private static MeterProviderBuilder AddOtlpExporter(MeterProviderBuilder builder options.AppendExportPath(initialEndpoint, OtlpExporterOptions.MetricsExportPath); var metricExporter = new OtlpMetricExporter(options); - var metricReader = new PeriodicExportingMetricReader(metricExporter, options.MetricExportIntervalMilliseconds); + + var metricReader = options.MetricReaderType == MetricReaderType.Manual + ? new BaseExportingMetricReader(metricExporter) + : new PeriodicExportingMetricReader(metricExporter, options.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds); + metricReader.Temporality = options.AggregationTemporality; return builder.AddReader(metricReader); }