Skip to content

Commit

Permalink
[Exporter.Geneva] Add named options support for GenevaTraceExporter a…
Browse files Browse the repository at this point in the history
…nd GenevaMetricExporter (#1218)
  • Loading branch information
utpilla authored Jun 7, 2023
1 parent 966727e commit 698e70a
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ OpenTelemetry.Exporter.Geneva.EventNameExportMode.ExportAsPartAName = 1 -> OpenT
OpenTelemetry.Exporter.Geneva.EventNameExportMode.None = 0 -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.get -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.set -> void
static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaExporterOptions> configure) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
*REMOVED*static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.EventNameExportMode.ExportAsPartAName = 1 -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.EventNameExportMode.None = 0 -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.get -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.set -> void
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.set -> void
static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaExporterOptions> configure) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
*REMOVED*static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ OpenTelemetry.Exporter.Geneva.EventNameExportMode.ExportAsPartAName = 1 -> OpenT
OpenTelemetry.Exporter.Geneva.EventNameExportMode.None = 0 -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.get -> OpenTelemetry.Exporter.Geneva.EventNameExportMode
OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.set -> void
static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaExporterOptions> configure) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
*REMOVED*static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Geneva.GenevaMetricExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
10 changes: 10 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

* Add named options support for `GenevaTraceExporter` and
`GenevaMetricExporter`.
([#1218](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1218))

* Add a new overload for `AddGenevaMetricExporter` without any parameters to
avoid warning
[RS0026](https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md#rs0026-do-not-add-multiple-public-overloads-with-optional-parameters).
([#1218](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1218))

## 1.5.0-rc.1

Released 2023-Jun-05
Expand All @@ -13,6 +22,7 @@ Released 2023-Jun-05
* TldLogExporter to export `SpanId` value in `ext_dt_spanId` field instead of
`TraceId` value.
([#1184](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1184))

* Add support for abstract domain sockets.
([#1199](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1199))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,45 @@

using System;
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter.Geneva;

public static class GenevaExporterHelperExtensions
{
/// <summary>
/// Adds <see cref="GenevaTraceExporter"/> to the <see cref="TracerProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderBuilder builder, Action<GenevaExporterOptions> configure)
=> AddGenevaTraceExporter(builder, name: null, configure);

/// <summary>
/// Adds <see cref="GenevaTraceExporter"/> to the <see cref="TracerProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
/// /// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderBuilder builder, string name, Action<GenevaExporterOptions> configure)
{
Guard.ThrowIfNull(builder);

name ??= Options.DefaultName;

if (configure != null)
{
builder.ConfigureServices(services => services.Configure(name, configure));
}

return builder.AddProcessor(sp =>
{
var exporterOptions = sp.GetOptions<GenevaExporterOptions>();
var exporterOptions = sp.GetRequiredService<IOptionsMonitor<GenevaExporterOptions>>().Get(name);

return BuildGenevaTraceExporter(exporterOptions, configure);
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// </copyright>

using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Internal;
using OpenTelemetry.Metrics;

Expand All @@ -26,15 +28,40 @@ public static class GenevaMetricExporterExtensions
/// Adds <see cref="GenevaMetricExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder)
=> AddGenevaMetricExporter(builder, name: null, configure: null);

/// <summary>
/// Adds <see cref="GenevaMetricExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </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>
public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder, Action<GenevaMetricExporterOptions> configure)
=> AddGenevaMetricExporter(builder, name: null, configure);

/// <summary>
/// Adds <see cref="GenevaMetricExporter"/> to the <see cref="MeterProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param>
/// /// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder, Action<GenevaMetricExporterOptions> configure = null)
public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder, string name, Action<GenevaMetricExporterOptions> configure)
{
Guard.ThrowIfNull(builder);

name ??= Options.DefaultName;

if (configure != null)
{
builder.ConfigureServices(services => services.Configure(name, configure));
}

return builder.AddReader(sp =>
{
var exporterOptions = sp.GetOptions<GenevaMetricExporterOptions>();
var exporterOptions = sp.GetRequiredService<IOptionsMonitor<GenevaMetricExporterOptions>>().Get(name);

return BuildGenevaMetricExporter(exporterOptions, configure);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Kaitai;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Xunit;
using static OpenTelemetry.Exporter.Geneva.Tests.MetricsContract;

Expand Down Expand Up @@ -873,6 +875,48 @@ public void SuccessfulSerializationWithCustomAccountAndNamespace()
}
}

[Fact]
public void AddGenevaMetricExporterNamedOptionsSupport()
{
string connectionString;
string connectionStringForNamedOptions;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
connectionString = "Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace";
connectionStringForNamedOptions = "Account=OTelMonitoringAccount-NamedOptions;Namespace=OTelMetricNamespace-NamedOptions";
}
else
{
var path = GenerateTempFilePath();
connectionString = $"Endpoint=unix:{path};Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace";
connectionStringForNamedOptions = $"Endpoint=unix:{path};Account=OTelMonitoringAccount-NamedOptions;Namespace=OTelMetricNamespace-NamedOptions";
}

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.ConfigureServices(services =>
{
services.Configure<GenevaMetricExporterOptions>(options =>
{
options.ConnectionString = connectionString;
});
services.Configure<GenevaMetricExporterOptions>("ExporterWithNamedOptions", options =>
{
options.ConnectionString = connectionStringForNamedOptions;
});
})
.AddGenevaMetricExporter(options =>
{
// ConnectionString for the options is already set in `IServiceCollection Configure<TOptions>` calls above
Assert.Equal(connectionString, options.ConnectionString);
})
.AddGenevaMetricExporter("ExporterWithNamedOptions", options =>
{
// ConnectionString for the named options is already set in `IServiceCollection Configure<TOptions>` calls above
Assert.Equal(connectionStringForNamedOptions, options.ConnectionString);
})
.Build();
}

private static string GenerateTempFilePath()
{
while (true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Trace;
using Xunit;

Expand Down Expand Up @@ -514,6 +515,48 @@ public void TLDTraceExporter_Success_Windows()
}
}

[Fact]
public void AddGenevaTraceExporterNamedOptionsSupport()
{
string connectionString;
string connectionStringForNamedOptions;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
connectionString = "EtwSession=OpenTelemetry";
connectionStringForNamedOptions = "EtwSession=OpenTelemetry-NamedOptions";
}
else
{
var path = GetRandomFilePath();
connectionString = "Endpoint=unix:" + path;
connectionStringForNamedOptions = "Endpoint=unix:" + path + "NamedOptions";
}

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureServices(services =>
{
services.Configure<GenevaExporterOptions>(options =>
{
options.ConnectionString = connectionString;
});
services.Configure<GenevaExporterOptions>("ExporterWithNamedOptions", options =>
{
options.ConnectionString = connectionStringForNamedOptions;
});
})
.AddGenevaTraceExporter(options =>
{
// ConnectionString for the options is already set in `IServiceCollection Configure<TOptions>` calls above
Assert.Equal(connectionString, options.ConnectionString);
})
.AddGenevaTraceExporter("ExporterWithNamedOptions", options =>
{
// ConnectionString for the named options is already set in `IServiceCollection Configure<TOptions>` calls above
Assert.Equal(connectionStringForNamedOptions, options.ConnectionString);
})
.Build();
}

private static string GetRandomFilePath()
{
while (true)
Expand Down

0 comments on commit 698e70a

Please sign in to comment.