From 485b19ea0fd21f3192a3cb9539f241bfb1752c90 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 2 Jun 2023 17:58:32 -0700 Subject: [PATCH 1/5] Add named options support for GenevaTraceExporter and GenevaMetricExporter --- .../.publicApi/net462/PublicAPI.Shipped.txt | 1 - .../.publicApi/net462/PublicAPI.Unshipped.txt | 4 ++ .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 - .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 6 ++- .../netstandard2.0/PublicAPI.Shipped.txt | 1 - .../netstandard2.0/PublicAPI.Unshipped.txt | 4 ++ .../GenevaExporterHelperExtensions.cs | 27 ++++++++++- .../Internal/ServiceProviderExtensions.cs | 46 ------------------- .../Metrics/GenevaMetricExporterExtensions.cs | 31 ++++++++++++- .../GenevaMetricExporterTests.cs | 30 ++++++++++++ .../GenevaTraceExporterTests.cs | 30 ++++++++++++ 11 files changed, 128 insertions(+), 53 deletions(-) delete mode 100644 src/OpenTelemetry.Exporter.Geneva/Internal/ServiceProviderExtensions.cs diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt index 37648818db..49f63ba795 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt @@ -40,4 +40,3 @@ override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Dispose(bool disposin override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions options, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt index 1fd2dcd539..b92dacd24f 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt @@ -3,3 +3,7 @@ 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 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 configure) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt index 37648818db..49f63ba795 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -40,4 +40,3 @@ override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Dispose(bool disposin override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions options, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt index 4ca0ea2c19..8cd60f76ed 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -2,4 +2,8 @@ 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 \ No newline at end of file +OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.set -> void +static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action 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 configure) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder \ No newline at end of file diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt index 37648818db..49f63ba795 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -40,4 +40,3 @@ override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Dispose(bool disposin override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions options, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 1fd2dcd539..b92dacd24f 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -3,3 +3,7 @@ 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 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 configure) -> OpenTelemetry.Metrics.MeterProviderBuilder +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterHelperExtensions.cs index 266c1b11e4..c050b34c3b 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterHelperExtensions.cs @@ -16,6 +16,8 @@ using System; using System.Diagnostics; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OpenTelemetry.Internal; using OpenTelemetry.Trace; @@ -23,13 +25,36 @@ namespace OpenTelemetry.Exporter.Geneva; public static class GenevaExporterHelperExtensions { + /// + /// Adds to the . + /// + /// builder to use. + /// Exporter configuration options. + /// The instance of to chain the calls. public static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderBuilder builder, Action configure) + => AddGenevaTraceExporter(builder, name: null, configure); + + /// + /// Adds to the . + /// + /// builder to use. + /// /// Name which is used when retrieving options. + /// Exporter configuration options. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderBuilder builder, string name, Action 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(); + var exporterOptions = sp.GetRequiredService>().Get(name); return BuildGenevaTraceExporter(exporterOptions, configure); }); diff --git a/src/OpenTelemetry.Exporter.Geneva/Internal/ServiceProviderExtensions.cs b/src/OpenTelemetry.Exporter.Geneva/Internal/ServiceProviderExtensions.cs deleted file mode 100644 index 9175001b9f..0000000000 --- a/src/OpenTelemetry.Exporter.Geneva/Internal/ServiceProviderExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// 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. -// - -#if NET462_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1_OR_GREATER -using Microsoft.Extensions.Options; -#endif - -namespace System; - -/// -/// Extension methods for OpenTelemetry dependency injection support. -/// -internal static class ServiceProviderExtensions -{ - /// - /// Get options from the supplied . - /// - /// Options type. - /// . - /// Options instance. - public static T GetOptions(this IServiceProvider serviceProvider) - where T : class, new() - { -#if NET462_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1_OR_GREATER - IOptions options = (IOptions)serviceProvider.GetService(typeof(IOptions)); - - // Note: options could be null if user never invoked services.AddOptions(). - return options?.Value ?? new T(); -#else - return new T(); -#endif - } -} diff --git a/src/OpenTelemetry.Exporter.Geneva/Metrics/GenevaMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.Geneva/Metrics/GenevaMetricExporterExtensions.cs index 67da1c315c..4933ad7a62 100644 --- a/src/OpenTelemetry.Exporter.Geneva/Metrics/GenevaMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.Geneva/Metrics/GenevaMetricExporterExtensions.cs @@ -15,6 +15,8 @@ // using System; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OpenTelemetry.Internal; using OpenTelemetry.Metrics; @@ -26,15 +28,40 @@ public static class GenevaMetricExporterExtensions /// Adds to the . /// /// builder to use. + /// The instance of to chain the calls. + public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder) + => AddGenevaMetricExporter(builder, name: null, configure: null); + + /// + /// Adds to the . + /// + /// builder to use. + /// Exporter configuration options. + /// The instance of to chain the calls. + public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder, Action configure) + => AddGenevaMetricExporter(builder, name: null, configure); + + /// + /// Adds to the . + /// + /// builder to use. + /// /// Name which is used when retrieving options. /// Exporter configuration options. /// The instance of to chain the calls. - public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder, Action configure = null) + public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBuilder builder, string name, Action 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(); + var exporterOptions = sp.GetRequiredService>().Get(name); return BuildGenevaMetricExporter(exporterOptions, configure); }); diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs index 2054179466..6633c19499 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs @@ -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; @@ -873,6 +875,34 @@ public void SuccessfulSerializationWithCustomAccountAndNamespace() } } + [Fact] + public void AddGenevaMetricExporterNamedOptionsSupport() + { + using var meterProvider = Sdk.CreateMeterProviderBuilder() + .ConfigureServices(services => + { + services.Configure(options => + { + options.ConnectionString = "Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace"; + }); + services.Configure("ExporterWithNamedOptions", options => + { + options.ConnectionString = "Account=OTelMonitoringAccount-NamedOptions;Namespace=OTelMetricNamespace-NamedOptions"; + }); + }) + .AddGenevaMetricExporter(options => + { + // ConnectionString for the options is already set in `IServiceCollection Configure` calls above + Assert.Equal("Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace", options.ConnectionString); + }) + .AddGenevaMetricExporter("ExporterWithNamedOptions", options => + { + // ConnectionString for the named options is already set in `IServiceCollection Configure` calls above + Assert.Equal("Account=OTelMonitoringAccount-NamedOptions;Namespace=OTelMetricNamespace-NamedOptions", options.ConnectionString); + }) + .Build(); + } + private static string GenerateTempFilePath() { while (true) diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs index cb7c61447a..f2a6e08bd7 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs @@ -24,6 +24,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OpenTelemetry.Trace; using Xunit; @@ -514,6 +516,34 @@ public void TLDTraceExporter_Success_Windows() } } + [Fact] + public void AddGenevaTraceExporterNamedOptionsSupport() + { + using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .ConfigureServices(services => + { + services.Configure(options => + { + options.ConnectionString = "EtwSession=OpenTelemetry"; + }); + services.Configure("ExporterWithNamedOptions", options => + { + options.ConnectionString = "EtwSession=OpenTelemetry-NamedOptions"; + }); + }) + .AddGenevaTraceExporter(options => + { + // ConnectionString for the options is already set in `IServiceCollection Configure` calls above + Assert.Equal("EtwSession=OpenTelemetry", options.ConnectionString); + }) + .AddGenevaTraceExporter("ExporterWithNamedOptions", options => + { + // ConnectionString for the named options is already set in `IServiceCollection Configure` calls above + Assert.Equal("EtwSession=OpenTelemetry-NamedOptions", options.ConnectionString); + }) + .Build(); + } + private static string GetRandomFilePath() { while (true) From 42e44cab56e2c45eb3be49193c0f06117b78753b Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 2 Jun 2023 18:06:58 -0700 Subject: [PATCH 2/5] Update public API files --- .../.publicApi/net462/PublicAPI.Shipped.txt | 1 + .../.publicApi/net462/PublicAPI.Unshipped.txt | 1 + .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 3 ++- .../.publicApi/netstandard2.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt index 49f63ba795..37648818db 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Shipped.txt @@ -40,3 +40,4 @@ override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Dispose(bool disposin override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions options, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt index b92dacd24f..db58b7a99f 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net462/PublicAPI.Unshipped.txt @@ -7,3 +7,4 @@ static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTra 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 configure) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder +*REMOVED*static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt index 49f63ba795..37648818db 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -40,3 +40,4 @@ override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Dispose(bool disposin override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions options, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt index 8cd60f76ed..db58b7a99f 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -6,4 +6,5 @@ OpenTelemetry.Exporter.Geneva.GenevaExporterOptions.EventNameExportMode.set -> v static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action 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 configure) -> OpenTelemetry.Metrics.MeterProviderBuilder -static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder \ No newline at end of file +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder +*REMOVED*static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt index 49f63ba795..37648818db 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -40,3 +40,4 @@ override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Dispose(bool disposin override OpenTelemetry.Exporter.Geneva.GenevaTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static Microsoft.Extensions.Logging.GenevaLoggingExtensions.AddGenevaLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions options, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index b92dacd24f..db58b7a99f 100644 --- a/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Geneva/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -7,3 +7,4 @@ static OpenTelemetry.Exporter.Geneva.GenevaExporterHelperExtensions.AddGenevaTra 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 configure) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder +*REMOVED*static OpenTelemetry.Exporter.Geneva.GenevaMetricExporterExtensions.AddGenevaMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder From e10106439763d209974be36c56f293afe32fc2cf Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 2 Jun 2023 18:13:43 -0700 Subject: [PATCH 3/5] Update CHANGELOG --- src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md index 693592d177..be1bc1cd30 100644 --- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md @@ -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 @@ -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)) From 2f7d0188fe2ae176f9149db85bc1d72220e479ce Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 2 Jun 2023 19:51:03 -0700 Subject: [PATCH 4/5] Update unit tests --- .../GenevaMetricExporterTests.cs | 22 ++++++++++++++---- .../GenevaTraceExporterTests.cs | 23 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs index 6633c19499..f9b3ead921 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs @@ -878,27 +878,41 @@ 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(options => { - options.ConnectionString = "Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace"; + options.ConnectionString = connectionString; }); services.Configure("ExporterWithNamedOptions", options => { - options.ConnectionString = "Account=OTelMonitoringAccount-NamedOptions;Namespace=OTelMetricNamespace-NamedOptions"; + options.ConnectionString = connectionStringForNamedOptions; }); }) .AddGenevaMetricExporter(options => { // ConnectionString for the options is already set in `IServiceCollection Configure` calls above - Assert.Equal("Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace", options.ConnectionString); + Assert.Equal(connectionString, options.ConnectionString); }) .AddGenevaMetricExporter("ExporterWithNamedOptions", options => { // ConnectionString for the named options is already set in `IServiceCollection Configure` calls above - Assert.Equal("Account=OTelMonitoringAccount-NamedOptions;Namespace=OTelMetricNamespace-NamedOptions", options.ConnectionString); + Assert.Equal(connectionStringForNamedOptions, options.ConnectionString); }) .Build(); } diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs index f2a6e08bd7..2fab8b53de 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs @@ -23,6 +23,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Serialization; using System.Threading; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -519,27 +520,41 @@ 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(options => { - options.ConnectionString = "EtwSession=OpenTelemetry"; + options.ConnectionString = connectionString; }); services.Configure("ExporterWithNamedOptions", options => { - options.ConnectionString = "EtwSession=OpenTelemetry-NamedOptions"; + options.ConnectionString = connectionStringForNamedOptions; }); }) .AddGenevaTraceExporter(options => { // ConnectionString for the options is already set in `IServiceCollection Configure` calls above - Assert.Equal("EtwSession=OpenTelemetry", options.ConnectionString); + Assert.Equal(connectionString, options.ConnectionString); }) .AddGenevaTraceExporter("ExporterWithNamedOptions", options => { // ConnectionString for the named options is already set in `IServiceCollection Configure` calls above - Assert.Equal("EtwSession=OpenTelemetry-NamedOptions", options.ConnectionString); + Assert.Equal(connectionStringForNamedOptions, options.ConnectionString); }) .Build(); } From 206e9584e53cf719f6c1ced25e7348f65b2dbb07 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 2 Jun 2023 19:52:09 -0700 Subject: [PATCH 5/5] Remove unnecessary using staements --- .../GenevaTraceExporterTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs index 2fab8b53de..7d9dbde3d0 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs @@ -23,10 +23,8 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Runtime.Serialization; using System.Threading; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using OpenTelemetry.Trace; using Xunit;