Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
resolve PR comments
  • Loading branch information
Vishwesh Bankwar committed Jul 5, 2022
commit f2a8ddd14249703da386a24c9980ab87d02d8d76
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,9 @@ internal class AspNetCoreInstrumentation : IDisposable
{
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

private readonly Func<string, object, object, bool> isEnabled = (activityName, obj1, obj2) =>
{
if (activityName.Equals("Microsoft.AspNetCore.Hosting.HttpRequestIn"))
{
return false;
}

return true;
};

public AspNetCoreInstrumentation(HttpInListener httpInListener)
{
// For .NET7.0 activity will be created using activitySource.
// https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L327
// However, in case when activity creation returns null (due to sampling)
// the framework will fall back to creating activity anyways due to active diagnostic source listener
// To prevent this, isEnabled is implemented which will return false always
// so that the sampler's decision is respected.
if (HttpInListener.IsNet7OrGreater)
{
this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(httpInListener, this.isEnabled);
}
else
{
this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(httpInListener, null);
}

this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(httpInListener, null);
this.diagnosticSourceSubscriber.Subscribe();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override void OnStartActivity(Activity activity, object payload)
// By this time, samplers have already run and
// activity.IsAllDataRequested populated accordingly.

if (Sdk.SuppressInstrumentation || (IsNet7OrGreater && string.IsNullOrEmpty(activity.Source.Name)))
if (Sdk.SuppressInstrumentation)
{
return;
}
Expand Down Expand Up @@ -203,11 +203,6 @@ public override void OnStartActivity(Activity activity, object payload)

public override void OnStopActivity(Activity activity, object payload)
{
if (IsNet7OrGreater && string.IsNullOrEmpty(activity.Source.Name))
{
return;
}

if (activity.IsAllDataRequested)
{
_ = this.stopContextFetcher.TryFetch(payload, out HttpContext context);
Expand Down Expand Up @@ -275,11 +270,6 @@ public override void OnStopActivity(Activity activity, object payload)

public override void OnCustom(string name, Activity activity, object payload)
{
if (IsNet7OrGreater && string.IsNullOrEmpty(activity.Source.Name))
{
return;
}

if (name == "Microsoft.AspNetCore.Mvc.BeforeAction")
{
if (activity.IsAllDataRequested)
Expand Down Expand Up @@ -309,11 +299,6 @@ public override void OnCustom(string name, Activity activity, object payload)

public override void OnException(Activity activity, object payload)
{
if (IsNet7OrGreater && string.IsNullOrEmpty(activity.Source.Name))
{
return;
}

if (activity.IsAllDataRequested)
{
if (!this.stopExceptionFetcher.TryFetch(payload, out Exception exc) || exc == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ internal static TracerProviderBuilder AddAspNetCoreInstrumentation(
this TracerProviderBuilder builder,
AspNetCoreInstrumentation instrumentation)
{
// For .NET7.0 onwards activity will be created using activitySource.
// https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L327
// For .NET6.0 and below, we will continue to use legacy way.
if (HttpInListener.IsNet7OrGreater)
{
builder.AddSource(HttpInListener.FrameworkActivitySourceName);
Expand Down