Skip to content

Commit

Permalink
Merge branch 'main' into add-configurable-path-to-jaeger-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
abe545 authored Feb 24, 2022
2 parents 102edb0 + f2fcb53 commit 1f7ec6a
Show file tree
Hide file tree
Showing 39 changed files with 454 additions and 228 deletions.
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ labels: bug

# Bug Report

List of [NuGet packages](https://www.nuget.org/profiles/OpenTelemetry) and
version that you are using (e.g. `OpenTelemetry 1.0.2`):
List of [all OpenTelemetry NuGet
packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are
using (e.g. `OpenTelemetry 1.0.2`):

* TBD

Expand Down
12 changes: 1 addition & 11 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,5 @@ labels: question

# Question

**Describe your environment.**
Use [Github Discussions](https://github.com/open-telemetry/opentelemetry-dotnet/discussions/new).

Describe any aspect of your environment relevant to the question.

**What are you trying to achieve?**

What did you expect to see?

## Additional Context

Add any other context about the problem here. If you followed an existing
documentation, please share the link to it.
8 changes: 5 additions & 3 deletions examples/AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions examples/Console/TestMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<OpenTelemetry.Metrics.Metric> batch) -> OpenTelemetry.ExportResult
static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
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<OpenTelemetry.Exporter.ConsoleExporterOptions, OpenTelemetry.Metrics.MetricReaderOptions> configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder
Original file line number Diff line number Diff line change
@@ -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<OpenTelemetry.Metrics.Metric> batch) -> OpenTelemetry.ExportResult
static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
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<OpenTelemetry.Exporter.ConsoleExporterOptions, OpenTelemetry.Metrics.MetricReaderOptions> configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ConsoleExporterOptions> configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,94 @@

namespace OpenTelemetry.Metrics
{
/// <summary>
/// Extension methods to simplify registering of the Console exporter.
/// </summary>
public static class ConsoleExporterMetricsExtensions
{
/// <summary>
/// Adds Console exporter to the TracerProvider.
/// Adds <see cref="ConsoleMetricExporter"/> to the <see cref="MeterProviderBuilder"/> using default options.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
[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<ConsoleExporterOptions> configure = null)
public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder builder)
{
return AddConsoleExporter(builder, options => { });
}

/// <summary>
/// Adds <see cref="ConsoleMetricExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <param name="configureExporter">Exporter configuration options.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddConsoleExporter(this MeterProviderBuilder builder, Action<ConsoleExporterOptions> 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<ConsoleExporterOptions>(), sp.GetOptions<MetricReaderOptions>(), configureExporter, null);
});
}

return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), configureExporter, null);
}

/// <summary>
/// Adds <see cref="ConsoleMetricExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <param name="configureExporterAndMetricReader">Exporter and <see cref="MetricReader"/> configuration options.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddConsoleExporter(
this MeterProviderBuilder builder,
Action<ConsoleExporterOptions, MetricReaderOptions> configureExporterAndMetricReader)
{
Guard.ThrowIfNull(builder, nameof(builder));

if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder)
{
return deferredMeterProviderBuilder.Configure((sp, builder) =>
{
AddConsoleExporter(builder, sp.GetOptions<ConsoleExporterOptions>(), sp.GetOptions<MetricReaderOptions>(), null, configureExporterAndMetricReader);
});
}

return AddConsoleExporter(builder, new ConsoleExporterOptions(), new MetricReaderOptions(), null, configureExporterAndMetricReader);
}

private static MeterProviderBuilder AddConsoleExporter(
MeterProviderBuilder builder,
ConsoleExporterOptions exporterOptions,
MetricReaderOptions metricReaderOptions,
Action<ConsoleExporterOptions> configureExporter,
Action<ConsoleExporterOptions, MetricReaderOptions> configureExporterAndMetricReader)
{
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);
}
}
}
18 changes: 0 additions & 18 deletions src/OpenTelemetry.Exporter.Console/ConsoleExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// limitations under the License.
// </copyright>

using OpenTelemetry.Metrics;

namespace OpenTelemetry.Exporter
{
public class ConsoleExporterOptions
Expand All @@ -24,21 +22,5 @@ public class ConsoleExporterOptions
/// Gets or sets the output targets for the console exporter.
/// </summary>
public ConsoleExporterOutputTargets Targets { get; set; } = ConsoleExporterOutputTargets.Console;

/// <summary>
/// Gets or sets the <see cref="MetricReaderType" /> to use. Defaults to <c>MetricReaderType.Manual</c>.
/// </summary>
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
/// and Sum metrics.
/// </summary>
public AggregationTemporality AggregationTemporality { get; set; } = AggregationTemporality.Delta;
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions
static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection<OpenTelemetry.Metrics.Metric> exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection<OpenTelemetry.Metrics.Metric> exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection<OpenTelemetry.Metrics.Metric> exportedItems, System.Action<OpenTelemetry.Metrics.MetricReaderOptions> configureMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions
static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection<OpenTelemetry.Metrics.Metric> exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection<OpenTelemetry.Metrics.Metric> exportedItems) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.InMemoryExporterMetricsExtensions.AddInMemoryExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Collections.Generic.ICollection<OpenTelemetry.Metrics.Metric> exportedItems, System.Action<OpenTelemetry.Metrics.MetricReaderOptions> configureMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Adds the ability to configure `MetricReaderOptions` via the
`AddInMemoryExporter` extension method.
([#2931](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2931))

## 1.2.0-rc2

Released 2022-Feb-02
Expand Down
Loading

0 comments on commit 1f7ec6a

Please sign in to comment.