From c48c014b5059d693a6cd1fdf7ae8e31fe065baf8 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 1 Dec 2023 15:19:05 -0800 Subject: [PATCH] Rename AspNetCoreInstrumentationOptions (#5108) --- examples/AspNetCore/Program.cs | 2 +- .../.publicApi/PublicAPI.Unshipped.txt | 28 +++++++++---------- ... AspNetCoreTraceInstrumentationOptions.cs} | 4 +-- .../CHANGELOG.md | 4 +++ .../Implementation/HttpInListener.cs | 4 +-- .../README.md | 12 ++++---- .../TracerProviderBuilderExtensions.cs | 18 ++++++------ .../BasicTests.cs | 10 +++---- .../DependencyInjectionConfigTests.cs | 4 +-- 9 files changed, 46 insertions(+), 40 deletions(-) rename src/OpenTelemetry.Instrumentation.AspNetCore/{AspNetCoreInstrumentationOptions.cs => AspNetCoreTraceInstrumentationOptions.cs} (96%) diff --git a/examples/AspNetCore/Program.cs b/examples/AspNetCore/Program.cs index ad841f993a7..9ecff725e81 100644 --- a/examples/AspNetCore/Program.cs +++ b/examples/AspNetCore/Program.cs @@ -63,7 +63,7 @@ .AddAspNetCoreInstrumentation(); // Use IConfiguration binding for AspNetCore instrumentation options. - appBuilder.Services.Configure(appBuilder.Configuration.GetSection("AspNetCoreInstrumentation")); + appBuilder.Services.Configure(appBuilder.Configuration.GetSection("AspNetCoreInstrumentation")); switch (tracingExporter) { diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/PublicAPI.Unshipped.txt index 6033fda11cc..859e71b936e 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/PublicAPI.Unshipped.txt @@ -1,18 +1,18 @@ -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.AspNetCoreTraceInstrumentationOptions() -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.EnrichWithException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.EnrichWithException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.EnrichWithHttpRequest.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.EnrichWithHttpResponse.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.Filter.get -> System.Func +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.Filter.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.RecordException.get -> bool +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreTraceInstrumentationOptions.RecordException.set -> void OpenTelemetry.Metrics.MeterProviderBuilderExtensions OpenTelemetry.Trace.TracerProviderBuilderExtensions static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configureAspNetCoreTraceInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetCoreTraceInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs similarity index 96% rename from src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs rename to src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs index 4b4e6f8e71d..69fe58f0424 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore; /// /// Options for requests instrumentation. /// -public class AspNetCoreInstrumentationOptions +public class AspNetCoreTraceInstrumentationOptions { /// /// Gets or sets a filter function that determines whether or not to diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 14066d82cc5..b59a49e140f 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -16,6 +16,10 @@ [#5098](https://github.com/open-telemetry/opentelemetry-dotnet/issues/5098) ([#5097](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5097)) +* **Breaking Change** : Renamed `AspNetCoreInstrumentationOptions` to + `AspNetCoreTraceInstrumentationOptions`. + ([#5108](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5108)) + ## 1.6.0-beta.3 Released 2023-Nov-17 diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 93bcf74080c..b10c8a6c4ca 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -64,9 +64,9 @@ internal class HttpInListener : ListenerHandler private readonly PropertyFetcher beforeActionAttributeRouteInfoFetcher = new("AttributeRouteInfo"); private readonly PropertyFetcher beforeActionTemplateFetcher = new("Template"); #endif - private readonly AspNetCoreInstrumentationOptions options; + private readonly AspNetCoreTraceInstrumentationOptions options; - public HttpInListener(AspNetCoreInstrumentationOptions options) + public HttpInListener(AspNetCoreTraceInstrumentationOptions options) : base(DiagnosticSourceName) { Guard.ThrowIfNull(options); diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md index c21322a9726..38269610e48 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md @@ -139,17 +139,19 @@ newer versions. ## Advanced configuration This instrumentation can be configured to change the default behavior by using -`AspNetCoreInstrumentationOptions`, which allows adding [`Filter`](#filter), +`AspNetCoreTraceInstrumentationOptions`, which allows adding [`Filter`](#filter), [`Enrich`](#enrich) as explained below. // TODO: This section could be refined. -When used with [`OpenTelemetry.Extensions.Hosting`](../OpenTelemetry.Extensions.Hosting/README.md), -all configurations to `AspNetCoreInstrumentationOptions` can be done in the `ConfigureServices` +When used with +[`OpenTelemetry.Extensions.Hosting`](../OpenTelemetry.Extensions.Hosting/README.md), +all configurations to `AspNetCoreTraceInstrumentationOptions` can be done in the +`ConfigureServices` method of you applications `Startup` class as shown below. ```csharp // Configure -services.Configure(options => +services.Configure(options => { options.Filter = (httpContext) => { @@ -168,7 +170,7 @@ services.AddOpenTelemetry() This instrumentation by default collects all the incoming http requests. It allows filtering of requests by using the `Filter` function in -`AspNetCoreInstrumentationOptions`. This defines the condition for allowable +`AspNetCoreTraceInstrumentationOptions`. This defines the condition for allowable requests. The Filter receives the `HttpContext` of the incoming request, and does not collect telemetry about the request if the Filter returns false or throws exception. diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/TracerProviderBuilderExtensions.cs index 7038d5a75cf..357cbad6f05 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/TracerProviderBuilderExtensions.cs @@ -36,30 +36,30 @@ public static class TracerProviderBuilderExtensions /// being configured. /// The instance of to chain the calls. public static TracerProviderBuilder AddAspNetCoreInstrumentation(this TracerProviderBuilder builder) - => AddAspNetCoreInstrumentation(builder, name: null, configureAspNetCoreInstrumentationOptions: null); + => AddAspNetCoreInstrumentation(builder, name: null, configureAspNetCoreTraceInstrumentationOptions: null); /// /// Enables the incoming requests automatic data collection for ASP.NET Core. /// /// being configured. - /// Callback action for configuring . + /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddAspNetCoreInstrumentation( this TracerProviderBuilder builder, - Action configureAspNetCoreInstrumentationOptions) - => AddAspNetCoreInstrumentation(builder, name: null, configureAspNetCoreInstrumentationOptions); + Action configureAspNetCoreTraceInstrumentationOptions) + => AddAspNetCoreInstrumentation(builder, name: null, configureAspNetCoreTraceInstrumentationOptions); /// /// Enables the incoming requests automatic data collection for ASP.NET Core. /// /// being configured. /// Name which is used when retrieving options. - /// Callback action for configuring . + /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddAspNetCoreInstrumentation( this TracerProviderBuilder builder, string name, - Action configureAspNetCoreInstrumentationOptions) + Action configureAspNetCoreTraceInstrumentationOptions) { Guard.ThrowIfNull(builder); @@ -71,9 +71,9 @@ public static TracerProviderBuilder AddAspNetCoreInstrumentation( builder.ConfigureServices(services => { - if (configureAspNetCoreInstrumentationOptions != null) + if (configureAspNetCoreTraceInstrumentationOptions != null) { - services.Configure(name, configureAspNetCoreInstrumentationOptions); + services.Configure(name, configureAspNetCoreTraceInstrumentationOptions); } }); @@ -87,7 +87,7 @@ public static TracerProviderBuilder AddAspNetCoreInstrumentation( return builder.AddInstrumentation(sp => { - var options = sp.GetRequiredService>().Get(name); + var options = sp.GetRequiredService>().Get(name); return new AspNetCoreInstrumentation( new HttpInListener(options)); diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 30d829f4382..11ebcbc8d79 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -496,7 +496,7 @@ void ConfigureTestServices(IServiceCollection services) { this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation( - new TestHttpInListener(new AspNetCoreInstrumentationOptions()) + new TestHttpInListener(new AspNetCoreTraceInstrumentationOptions()) { OnEventWrittenCallback = (name, payload) => { @@ -836,7 +836,7 @@ public async Task DiagnosticSourceCallbacksAreReceivedOnlyForSubscribedEvents() this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation( - new TestHttpInListener(new AspNetCoreInstrumentationOptions()) + new TestHttpInListener(new AspNetCoreTraceInstrumentationOptions()) { OnEventWrittenCallback = (name, payload) => { @@ -892,7 +892,7 @@ public async Task DiagnosticSourceExceptionCallbackIsReceivedForUnHandledExcepti this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation( - new TestHttpInListener(new AspNetCoreInstrumentationOptions()) + new TestHttpInListener(new AspNetCoreTraceInstrumentationOptions()) { OnEventWrittenCallback = (name, payload) => { @@ -968,7 +968,7 @@ public async Task DiagnosticSourceExceptionCallBackIsNotReceivedForExceptionsHan // configure SDK this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation( - new TestHttpInListener(new AspNetCoreInstrumentationOptions()) + new TestHttpInListener(new AspNetCoreTraceInstrumentationOptions()) { OnEventWrittenCallback = (name, payload) => { @@ -1134,7 +1134,7 @@ public override SamplingResult ShouldSample(in SamplingParameters samplingParame } } - private class TestHttpInListener(AspNetCoreInstrumentationOptions options) : HttpInListener(options) + private class TestHttpInListener(AspNetCoreTraceInstrumentationOptions options) : HttpInListener(options) { public Action OnEventWrittenCallback; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/DependencyInjectionConfigTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/DependencyInjectionConfigTests.cs index ec78facc67e..fef23ae73e9 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/DependencyInjectionConfigTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/DependencyInjectionConfigTests.cs @@ -46,9 +46,9 @@ void ConfigureTestServices(IServiceCollection services) { services.AddOpenTelemetry() .WithTracing(builder => builder - .AddAspNetCoreInstrumentation(name, configureAspNetCoreInstrumentationOptions: null)); + .AddAspNetCoreInstrumentation(name, configureAspNetCoreTraceInstrumentationOptions: null)); - services.Configure(name, options => + services.Configure(name, options => { optionsPickedFromDI = true; });