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..4777e306a67 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` + ([#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 + ([#3664](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3664)) + ## 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)); }); 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() {