From 4f40d740e8015c1f656c0755fcb00ae5c05e1ab1 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 18 Feb 2022 10:49:51 -0800 Subject: [PATCH 1/2] Fix console log exporter extension method summary (#2912) --- .../ConsoleExporterLoggingExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs index 95320a69617..6cec91dfed2 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry.Logs public static class ConsoleExporterLoggingExtensions { /// - /// Adds Console Exporter as a configuration to the OpenTelemetry ILoggingBuilder. + /// Adds Console exporter with OpenTelemetryLoggerOptions. /// /// options to use. /// Exporter configuration options. From f234829964a2e59078d3d02c1a881ff35ffd65b8 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Fri, 18 Feb 2022 12:02:14 -0800 Subject: [PATCH 2/2] OTLP exporter options separate out MetricReader options (#2717) * Separate out OtlpMetricReaderOptions from OtlpExporterOptions * Collapse config delegates into one * Rename AggregationTemporality to Temporatlity * Update public API * Change parameter names * Move MetricReaderOptions to SDK * Default OTLP metric exporter to use a periodic metric reader and cumulative temporality * Update example to configure exporter options * Update public API * Everyone loves a good stackoverflow * Update public API * Fix bad merge * Change namespace * Fix the public API * I :heart: trying to get the public API correct without Visual Studio * Remove check for unspecified temporality Co-authored-by: Cijo Thomas --- examples/Console/Program.cs | 3 + examples/Console/TestMetrics.cs | 11 ++- .../.publicApi/net461/PublicAPI.Unshipped.txt | 10 +-- .../.publicApi/net5.0/PublicAPI.Unshipped.txt | 10 +-- .../netstandard2.0/PublicAPI.Unshipped.txt | 10 +-- .../netstandard2.1/PublicAPI.Unshipped.txt | 10 +-- .../OtlpExporterOptions.cs | 16 ---- .../OtlpMetricExporterExtensions.cs | 73 +++++++++++++++---- .../.publicApi/net461/PublicAPI.Unshipped.txt | 8 ++ .../netstandard2.0/PublicAPI.Unshipped.txt | 8 ++ .../Metrics/MetricReaderOptions.cs | 58 +++++++++++++++ 11 files changed, 156 insertions(+), 61 deletions(-) create mode 100644 src/OpenTelemetry/Metrics/MetricReaderOptions.cs diff --git a/examples/Console/Program.cs b/examples/Console/Program.cs index d00d11db443..2c0468c7a7e 100644 --- a/examples/Console/Program.cs +++ b/examples/Console/Program.cs @@ -117,6 +117,9 @@ internal class MetricsOptions [Option("useExporter", Default = "console", HelpText = "Options include otlp or console.", Required = false)] public string UseExporter { get; set; } + + [Option('p', "useGrpc", HelpText = "Use gRPC or HTTP when using the OTLP exporter", Required = false, Default = true)] + public bool UseGrpc { get; set; } } [Verb("grpc", HelpText = "Specify the options required to test Grpc.Net.Client")] diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index 1f41b5380f3..3e20efcc541 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -21,6 +21,7 @@ using System.Threading; using System.Threading.Tasks; using OpenTelemetry; +using OpenTelemetry.Exporter; using OpenTelemetry.Metrics; using OpenTelemetry.Resources; @@ -66,11 +67,13 @@ internal static object Run(MetricsOptions options) AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); providerBuilder - .AddOtlpExporter(o => + .AddOtlpExporter((exporterOptions, metricReaderOptions) => { - o.MetricReaderType = MetricReaderType.Periodic; - o.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds; - o.AggregationTemporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative; + exporterOptions.Protocol = options.UseGrpc ? OtlpExportProtocol.Grpc : OtlpExportProtocol.HttpProtobuf; + + metricReaderOptions.MetricReaderType = MetricReaderType.Periodic; + metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds; + metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative; }); } else diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt index ed28f69db50..a019b19a6ba 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net461/PublicAPI.Unshipped.txt @@ -1,6 +1,4 @@ OpenTelemetry.Exporter.OtlpExporterOptions -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri @@ -9,10 +7,6 @@ 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.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.HttpClientFactory.get -> System.Func OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.OtlpExporterOptions() -> void @@ -33,5 +27,7 @@ override OpenTelemetry.Exporter.OtlpMetricExporter.Export(in OpenTelemetry.Batch override OpenTelemetry.Exporter.OtlpMetricExporter.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.Exporter.OtlpTraceExporter.Export(in OpenTelemetry.Batch activityBatch) -> OpenTelemetry.ExportResult override OpenTelemetry.Exporter.OtlpTraceExporter.OnShutdown(int timeoutMilliseconds) -> bool -static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder 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 f59367caac1..4e91c691456 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/net5.0/PublicAPI.Unshipped.txt @@ -1,9 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.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.HttpClientFactory.get -> System.Func OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol @@ -16,4 +10,6 @@ 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 +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporter) -> 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 f59367caac1..4e91c691456 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,9 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.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.HttpClientFactory.get -> System.Func OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol @@ -16,4 +10,6 @@ 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 +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder 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 f59367caac1..4e91c691456 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,9 +1,3 @@ -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.get -> OpenTelemetry.Metrics.AggregationTemporality -OpenTelemetry.Exporter.OtlpExporterOptions.AggregationTemporality.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.HttpClientFactory.get -> System.Func OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.set -> void OpenTelemetry.Exporter.OtlpExporterOptions.Protocol.get -> OpenTelemetry.Exporter.OtlpExportProtocol @@ -16,4 +10,6 @@ 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 +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Metrics.OtlpMetricExporterExtensions.AddOtlpExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index e8b06e43914..0a624c68957 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -146,22 +146,6 @@ public Uri Endpoint /// public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchExportActivityProcessorOptions(); - /// - /// Gets or sets the to use. Defaults to MetricReaderType.Periodic. - /// - 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 - /// and Sum metrics. - /// - public AggregationTemporality AggregationTemporality { get; set; } = AggregationTemporality.Cumulative; - /// /// Gets or sets the factory function called to create the instance that will be used at runtime to diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index 09e5dc69fee..118c1e89808 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -25,13 +25,23 @@ namespace OpenTelemetry.Metrics /// public static class OtlpMetricExporterExtensions { + /// + /// Adds to the using default options. + /// + /// builder to use. + /// The instance of to chain the calls. + public static MeterProviderBuilder AddOtlpExporter(this MeterProviderBuilder builder) + { + return AddOtlpExporter(builder, options => { }); + } + /// /// Adds to the . /// /// builder to use. - /// Exporter configuration options. + /// Exporter configuration options. /// The instance of to chain the calls. - public static MeterProviderBuilder AddOtlpExporter(this MeterProviderBuilder builder, Action configure = null) + public static MeterProviderBuilder AddOtlpExporter(this MeterProviderBuilder builder, Action configureExporter) { Guard.ThrowIfNull(builder); @@ -39,32 +49,69 @@ public static MeterProviderBuilder AddOtlpExporter(this MeterProviderBuilder bui { return deferredMeterProviderBuilder.Configure((sp, builder) => { - AddOtlpExporter(builder, sp.GetOptions(), configure, sp); + AddOtlpExporter(builder, sp.GetOptions(), sp.GetOptions(), configureExporter, null, sp); + }); + } + + return AddOtlpExporter(builder, new OtlpExporterOptions(), 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 AddOtlpExporter( + this MeterProviderBuilder builder, + Action configureExporterAndMetricReader) + { + Guard.ThrowIfNull(builder, nameof(builder)); + + if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder) + { + return deferredMeterProviderBuilder.Configure((sp, builder) => + { + AddOtlpExporter(builder, sp.GetOptions(), sp.GetOptions(), null, configureExporterAndMetricReader, sp); }); } - return AddOtlpExporter(builder, new OtlpExporterOptions(), configure, serviceProvider: null); + return AddOtlpExporter(builder, new OtlpExporterOptions(), new MetricReaderOptions(), null, configureExporterAndMetricReader, serviceProvider: null); } private static MeterProviderBuilder AddOtlpExporter( MeterProviderBuilder builder, - OtlpExporterOptions options, - Action configure, + OtlpExporterOptions exporterOptions, + MetricReaderOptions metricReaderOptions, + Action configureExporter, + Action configureExporterAndMetricReader, IServiceProvider serviceProvider) { - configure?.Invoke(options); + if (configureExporterAndMetricReader != null) + { + configureExporterAndMetricReader.Invoke(exporterOptions, metricReaderOptions); + } + else + { + configureExporter?.Invoke(exporterOptions); + } - options.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpMetricExporter"); + exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpMetricExporter"); - options.AppendExportPath(OtlpExporterOptions.MetricsExportPath); + exporterOptions.AppendExportPath(OtlpExporterOptions.MetricsExportPath); - var metricExporter = new OtlpMetricExporter(options); + var metricExporter = new OtlpMetricExporter(exporterOptions); + + if (metricReaderOptions.MetricReaderType == (MetricReaderType)(-1)) + { + metricReaderOptions.MetricReaderType = MetricReaderType.Periodic; + } - var metricReader = options.MetricReaderType == MetricReaderType.Manual + var metricReader = metricReaderOptions.MetricReaderType == MetricReaderType.Manual ? new BaseExportingMetricReader(metricExporter) - : new PeriodicExportingMetricReader(metricExporter, options.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds); + : new PeriodicExportingMetricReader(metricExporter, metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds); - metricReader.Temporality = options.AggregationTemporality; + metricReader.Temporality = metricReaderOptions.Temporality; return builder.AddReader(metricReader); } } diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index dd09baf95e8..bee50adc683 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -1,6 +1,14 @@ OpenTelemetry.BaseExporter.ForceFlush(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Batch.Batch(T[] items, int count) -> void OpenTelemetry.Batch.Count.get -> long +OpenTelemetry.Metrics.MetricReaderOptions +OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void +OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderType.set -> void +OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.set -> void +OpenTelemetry.Metrics.MetricReaderOptions.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality +OpenTelemetry.Metrics.MetricReaderOptions.Temporality.set -> void OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> OpenTelemetry.Metrics.AggregationTemporality diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index dd09baf95e8..bee50adc683 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,6 +1,14 @@ OpenTelemetry.BaseExporter.ForceFlush(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Batch.Batch(T[] items, int count) -> void OpenTelemetry.Batch.Count.get -> long +OpenTelemetry.Metrics.MetricReaderOptions +OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void +OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderType.get -> OpenTelemetry.Metrics.MetricReaderType +OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderType.set -> void +OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions +OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.set -> void +OpenTelemetry.Metrics.MetricReaderOptions.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality +OpenTelemetry.Metrics.MetricReaderOptions.Temporality.set -> void OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> OpenTelemetry.Metrics.AggregationTemporality diff --git a/src/OpenTelemetry/Metrics/MetricReaderOptions.cs b/src/OpenTelemetry/Metrics/MetricReaderOptions.cs new file mode 100644 index 00000000000..d9fe24b909d --- /dev/null +++ b/src/OpenTelemetry/Metrics/MetricReaderOptions.cs @@ -0,0 +1,58 @@ +// +// 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; + +/// +/// Options for configuring either a or . +/// +public class MetricReaderOptions +{ + private const MetricReaderType MetricReaderTypeUnspecified = (MetricReaderType)(-1); + private MetricReaderType metricReaderType = MetricReaderTypeUnspecified; + + /// + /// Gets or sets the AggregationTemporality used for Histogram + /// and Sum metrics. + /// + public AggregationTemporality Temporality { get; set; } = AggregationTemporality.Cumulative; + + /// + /// Gets or sets the to use. Defaults to MetricReaderType.Manual. + /// + public MetricReaderType MetricReaderType + { + get + { + if (this.metricReaderType == MetricReaderTypeUnspecified) + { + this.metricReaderType = MetricReaderType.Manual; + } + + return this.metricReaderType; + } + + set + { + this.metricReaderType = value; + } + } + + /// + /// Gets or sets the options. Ignored unless MetricReaderType is Periodic. + /// + public PeriodicExportingMetricReaderOptions PeriodicExportingMetricReaderOptions { get; set; } = new PeriodicExportingMetricReaderOptions(); +}