From 0988a82c37817233d9730d9f1ae39212a0095871 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 14 Sep 2022 15:57:53 -0700 Subject: [PATCH 1/3] Enabled named options in httpclient instrumentation. --- .../PublicAPI.Shipped.txt | 0 .../PublicAPI.Unshipped.txt | 4 ++- .../CHANGELOG.md | 8 +++++ .../OpenTelemetry.Instrumentation.Http.csproj | 7 ++++- .../TracerProviderBuilderExtensions.cs | 31 ++++++++++++++++--- 5 files changed, 44 insertions(+), 6 deletions(-) rename src/OpenTelemetry.Instrumentation.Http/.publicApi/{netstandard2.0 => net6.0}/PublicAPI.Shipped.txt (100%) rename src/OpenTelemetry.Instrumentation.Http/.publicApi/{netstandard2.0 => net6.0}/PublicAPI.Unshipped.txt (70%) diff --git a/src/OpenTelemetry.Instrumentation.Http/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Instrumentation.Http/.publicApi/net6.0/PublicAPI.Shipped.txt similarity index 100% rename from src/OpenTelemetry.Instrumentation.Http/.publicApi/netstandard2.0/PublicAPI.Shipped.txt rename to src/OpenTelemetry.Instrumentation.Http/.publicApi/net6.0/PublicAPI.Shipped.txt diff --git a/src/OpenTelemetry.Instrumentation.Http/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.Http/.publicApi/net6.0/PublicAPI.Unshipped.txt similarity index 70% rename from src/OpenTelemetry.Instrumentation.Http/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt rename to src/OpenTelemetry.Instrumentation.Http/.publicApi/net6.0/PublicAPI.Unshipped.txt index 8ac18d7a6e1..0224a11a2e5 100644 --- a/src/OpenTelemetry.Instrumentation.Http/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.Http/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -9,4 +9,6 @@ OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions.RecordExcept OpenTelemetry.Metrics.MeterProviderBuilderExtensions OpenTelemetry.Trace.TracerProviderBuilderExtensions static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureHttpClientInstrumentationOptions = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index c7ce6fdac9b..b840ead348d 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +* Dropped `netstandard2.0` target and added `net6.0` + ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + +* Added overloads which accept a name to the `TracerProviderBuilder` + `AddHttpClientInstrumentation` extension to allow for more fine-grained + options management + ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ## 1.0.0-rc9.6 Released 2022-Aug-18 diff --git a/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj b/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj index 3665f2c85e0..621422a822b 100644 --- a/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj +++ b/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj @@ -2,12 +2,17 @@ - netstandard2.0;net462 + net6.0;net462 Http instrumentation for OpenTelemetry .NET $(PackageTags);distributed-tracing true + + + false + + diff --git a/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs index 3a6640c61c1..619035e82bc 100644 --- a/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs @@ -61,22 +61,45 @@ public static TracerProviderBuilder AddHttpClientInstrumentation( /// Enables HttpClient instrumentation. /// /// being configured. - /// HttpClient configuration options. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddHttpClientInstrumentation(this TracerProviderBuilder builder) + => AddHttpClientInstrumentation(builder, name: null, configureHttpClientInstrumentationOptions: null); + + /// + /// Enables HttpClient instrumentation. + /// + /// being configured. + /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddHttpClientInstrumentation( this TracerProviderBuilder builder, - Action configureHttpClientInstrumentationOptions = null) + Action configureHttpClientInstrumentationOptions) + => AddHttpClientInstrumentation(builder, name: null, configureHttpClientInstrumentationOptions); + + /// + /// Enables HttpClient instrumentation. + /// + /// being configured. + /// Name which is used when retrieving options. + /// Callback action for configuring . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddHttpClientInstrumentation( + this TracerProviderBuilder builder, + string name, + Action configureHttpClientInstrumentationOptions) { Guard.ThrowIfNull(builder); + name ??= Options.DefaultName; + if (configureHttpClientInstrumentationOptions != null) { - builder.ConfigureServices(services => services.Configure(configureHttpClientInstrumentationOptions)); + builder.ConfigureServices(services => services.Configure(name, configureHttpClientInstrumentationOptions)); } return builder.ConfigureBuilder((sp, builder) => { - var options = sp.GetRequiredService>().Value; + var options = sp.GetRequiredService>().Get(name); AddHttpClientInstrumentation(builder, new HttpClientInstrumentation(options)); }); From c13c4629290c3a979bbe6218d0d34e06c16700e8 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 14 Sep 2022 16:01:02 -0700 Subject: [PATCH 2/3] Tests. --- .../HttpClientTests.Basic.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs index c06a18bc89f..3b49cac0348 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs @@ -19,6 +19,7 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Moq; using OpenTelemetry.Context.Propagation; using OpenTelemetry.Instrumentation.Http.Implementation; @@ -47,6 +48,27 @@ public HttpClientTests() this.url = $"http://{host}:{port}/"; } + [Fact] + public void AddHttpClientInstrumentation_NamedOptions() + { + int defaultExporterOptionsConfigureOptionsInvocations = 0; + int namedExporterOptionsConfigureOptionsInvocations = 0; + + using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .ConfigureServices(services => + { + services.Configure(o => defaultExporterOptionsConfigureOptionsInvocations++); + + services.Configure("Instrumentation2", o => namedExporterOptionsConfigureOptionsInvocations++); + }) + .AddHttpClientInstrumentation() + .AddHttpClientInstrumentation("Instrumentation2", configureHttpClientInstrumentationOptions: null) + .Build(); + + Assert.Equal(1, defaultExporterOptionsConfigureOptionsInvocations); + Assert.Equal(1, namedExporterOptionsConfigureOptionsInvocations); + } + [Fact] public void AddHttpClientInstrumentation_BadArgs() { From 16e8b82683f91fec4399257ee2bb30dbbe4b58b1 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 14 Sep 2022 16:03:39 -0700 Subject: [PATCH 3/3] CHANGELOG update. --- src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index b840ead348d..4777e306a67 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -3,12 +3,12 @@ ## Unreleased * Dropped `netstandard2.0` target and added `net6.0` - ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ([#3664](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3664)) * Added overloads which accept a name to the `TracerProviderBuilder` `AddHttpClientInstrumentation` extension to allow for more fine-grained options management - ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet/pull/XXXX)) + ([#3664](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3664)) ## 1.0.0-rc9.6