[ASP.NET Core] Enable diagnostic source events using explicit names (#3519)

This commit is contained in:
Vishwesh Bankwar 2022-09-21 11:54:34 -07:00 committed by GitHub
parent 988a27be05
commit 74412f0b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 10 deletions

View File

@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using OpenTelemetry.Instrumentation.AspNetCore.Implementation;
namespace OpenTelemetry.Instrumentation.AspNetCore
@ -23,11 +24,23 @@ namespace OpenTelemetry.Instrumentation.AspNetCore
/// </summary>
internal class AspNetCoreInstrumentation : IDisposable
{
private static readonly HashSet<string> DiagnosticSourceEvents = new()
{
"Microsoft.AspNetCore.Hosting.HttpRequestIn.Start",
"Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop",
"Microsoft.AspNetCore.Mvc.BeforeAction",
"Microsoft.AspNetCore.Diagnostics.UnhandledException",
"Microsoft.AspNetCore.Hosting.UnhandledException",
};
private readonly Func<string, object, object, bool> isEnabled = (eventName, obj1, obj2)
=> DiagnosticSourceEvents.Contains(eventName);
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;
public AspNetCoreInstrumentation(HttpInListener httpInListener)
{
this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(httpInListener, null);
this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(httpInListener, this.isEnabled);
this.diagnosticSourceSubscriber.Subscribe();
}

View File

@ -2,15 +2,19 @@
## Unreleased
* Fix issue where when an application has an ExceptionFilter, the exception data
wouldn't be collected.
([#3475](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3475))
* Performance improvement (Reduced memory allocation) - Updated DiagnosticSource
event subscription to specific set of events.
([#3519](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3519))
* Added overloads which accept a name to the `TracerProviderBuilder`
`AddAspNetCoreInstrumentation` extension to allow for more fine-grained
options management
([#3661](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3661))
* Fix issue where when an application has an ExceptionFilter, the exception data
wouldn't be collected.
([#3475](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3475))
## 1.0.0-rc9.6
Released 2022-Aug-18

View File

@ -27,17 +27,17 @@ using OpenTelemetry.Trace;
/*
// * Summary *
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22621
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET SDK=7.0.100-preview.6.22275.1
[Host] : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT
[Host] : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT
Job=InProcess Toolchain=InProcessEmitToolchain
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|-------------------------------------------- |---------:|--------:|--------:|-------:|----------:|
| UninstrumentedAspNetCoreApp | 155.6 us | 2.63 us | 2.33 us | 0.9766 | 5 KB |
| InstrumentedAspNetCoreAppWithDefaultOptions | 176.8 us | 3.24 us | 2.70 us | 1.2207 | 7 KB |
| UninstrumentedAspNetCoreApp | 164.7 us | 1.66 us | 1.39 us | 0.9766 | 5 KB |
| InstrumentedAspNetCoreAppWithDefaultOptions | 178.7 us | 2.65 us | 2.35 us | 0.9766 | 5 KB |
*/
namespace Benchmarks.Instrumentation

View File

@ -695,7 +695,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
AssertException(exportedItems);
}
[Fact(Skip = "Pending Changes https://github.com/open-telemetry/opentelemetry-dotnet/issues/3495")]
[Fact]
public async Task DiagnosticSourceCustomCallbacksAreReceivedOnlyForSubscribedEvents()
{
int numberOfCustomCallbacks = 0;
@ -772,7 +772,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
Assert.Equal(1, numberOfExceptionCallbacks);
}
[Fact(Skip = "Pending Changes https://github.com/open-telemetry/opentelemetry-dotnet/issues/3495")]
[Fact]
public async Task DiagnosticSourceExceptionCallBackIsNotReceivedForExceptionsHandledInMiddleware()
{
int numberOfExceptionCallbacks = 0;
@ -823,6 +823,8 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
}
Assert.Equal(0, numberOfExceptionCallbacks);
await app.DisposeAsync();
}
public void Dispose()