Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PeriodicExporterOptions for console exporter #2648

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
3 changes: 2 additions & 1 deletion examples/Console/TestMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
o.AggregationTemporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System;
using System.Threading;
using OpenTelemetry.Exporter;
using OpenTelemetry.Internal;

Expand All @@ -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;

Expand Down
10 changes: 7 additions & 3 deletions src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

using System.Threading;
using OpenTelemetry.Metrics;

namespace OpenTelemetry.Exporter
Expand All @@ -27,9 +26,14 @@ public class ConsoleExporterOptions
public ConsoleExporterOutputTargets Targets { get; set; } = ConsoleExporterOutputTargets.Console;

/// <summary>
/// Gets or sets the metric export interval in milliseconds. The default value is <c>Timeout.Infinite</c>.
/// Gets or sets the <see cref="MetricReaderType" /> to use. Defaults to <c>MetricReaderType.Manual</c>.
/// </summary>
public int MetricExportIntervalMilliseconds { get; set; } = Timeout.Infinite;
public MetricReaderType MetricReaderType { get; set; } = MetricReaderType.Manual;

/// <summary>
/// Gets or sets the <see cref="PeriodicExportingMetricReaderOptions" /> options. Ignored unless <c>MetricReaderType</c> is <c>Periodic</c>.
/// </summary>
public PeriodicExportingMetricReaderOptions PeriodicExportingMetricReaderOptions { get; set; } = new PeriodicExportingMetricReaderOptions();

/// <summary>
/// Gets or sets the AggregationTemporality used for Histogram
Expand Down
7 changes: 7 additions & 0 deletions src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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
Expand All @@ -91,6 +94,10 @@ OpenTelemetry.Metrics.MetricType.LongSum = 26 -> OpenTelemetry.Metrics.MetricTyp
OpenTelemetry.Metrics.MetricTypeExtensions
OpenTelemetry.Metrics.PeriodicExportingMetricReader
OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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
Expand All @@ -91,6 +94,10 @@ OpenTelemetry.Metrics.MetricType.LongSum = 26 -> OpenTelemetry.Metrics.MetricTyp
OpenTelemetry.Metrics.MetricTypeExtensions
OpenTelemetry.Metrics.PeriodicExportingMetricReader
OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> 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
Expand Down
36 changes: 36 additions & 0 deletions src/OpenTelemetry/Metrics/MetricReaderType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <copyright file="MetricReaderType.cs" company="OpenTelemetry Authors">
// 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.
// </copyright>

namespace OpenTelemetry.Metrics
{
/// <summary>
/// Type of <see cref="MetricReader" /> to be used.
/// </summary>
public enum MetricReaderType
{
/// <summary>
/// Use the <see cref="BaseExportingMetricReader" />.
/// This requires manually invoking <c>MetricReader.Collect()</c> to export metrics.
/// </summary>
Manual,

/// <summary>
/// Use the <see cref="PeriodicExportingMetricReader" />.
/// <c>MetricReader.Collect()</c> will be invoked on a defined interval.
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
Periodic,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="PeriodicExportingMetricReaderOptions.cs" company="OpenTelemetry Authors">
// 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.
// </copyright>

namespace OpenTelemetry.Metrics
{
public class PeriodicExportingMetricReaderOptions
{
/// <summary>
/// Gets or sets the metric export interval in milliseconds. The default value is <c>60000</c>.
/// </summary>
public int ExportIntervalMilliseconds { get; set; } = 60000;
}
}