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
Fix remaining tests
  • Loading branch information
shirhatti committed Feb 23, 2021
commit d3ff48149fbbfb04a82bc5b98b59e3856eca84c4
34 changes: 21 additions & 13 deletions src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ public void BeginRequest(HttpContext httpContext, HostingApplication.Context con
}

var diagnosticListenerEnabled = _diagnosticListener.IsEnabled();
var diagnosticListenerActivityCreationEnabled = (diagnosticListenerEnabled && _diagnosticListener.IsEnabled(ActivityName, httpContext));
var loggingEnabled = _logger.IsEnabled(LogLevel.Critical);

// TODO: If loggingEnabled check to change to if ActivityPropogation options are enabled
if (loggingEnabled || (diagnosticListenerEnabled && _diagnosticListener.IsEnabled(ActivityName, httpContext)))
if (loggingEnabled || diagnosticListenerActivityCreationEnabled)
{
_dummyListener = new ActivityListener()
{
ShouldListenTo = activitySource => activitySource.Name.Equals(ActivitySourceName),
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.PropagationData
ShouldListenTo = activitySource => ReferenceEquals(activitySource, _activitySource),
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.PropagationData,
SampleUsingParentId = (ref ActivityCreationOptions<string> options) => ActivitySamplingResult.PropagationData
};
ActivitySource.AddActivityListener(_dummyListener);
}

context.Activity = StartActivity(httpContext, out var hasDiagnosticListener);
context.Activity = StartActivity(httpContext, diagnosticListenerActivityCreationEnabled, out var hasDiagnosticListener);
context.HasDiagnosticListener = hasDiagnosticListener;

if (diagnosticListenerEnabled)
Expand Down Expand Up @@ -261,12 +263,15 @@ private static void RecordRequestStartEventLog(HttpContext httpContext)
}

[MethodImpl(MethodImplOptions.NoInlining)]
private Activity? StartActivity(HttpContext httpContext, out bool hasDiagnosticListener)
private Activity? StartActivity(HttpContext httpContext, bool diagnosticListenerActivityCreationEnabled, out bool hasDiagnosticListener)
{
hasDiagnosticListener = false;
if (_diagnosticListener.IsEnabled(ActivityStartKey))
if (diagnosticListenerActivityCreationEnabled)
{
hasDiagnosticListener = true;
if (_diagnosticListener.IsEnabled(ActivityStartKey))
{
hasDiagnosticListener = true;
}
}

// Short-circuit to avoid doing an expensive header lookup
Expand Down Expand Up @@ -310,13 +315,16 @@ private static void RecordRequestStartEventLog(HttpContext httpContext)
}
}

// Review: Breaking change: We will no longer fire OnActivityImport before Activity.Start()
_diagnosticListener.OnActivityImport(activity, httpContext);

if (hasDiagnosticListener)
if (diagnosticListenerActivityCreationEnabled)
{
//Review: Do we need to explicity call this?
_diagnosticListener.Write(ActivityStartKey, httpContext);
// Review: Breaking change: We will no longer fire OnActivityImport before Activity.Start()
_diagnosticListener.OnActivityImport(activity, httpContext);

if (hasDiagnosticListener)
{
//Review: Do we need to explicity call this?
_diagnosticListener.Write(ActivityStartKey, httpContext);
}
}
}
return activity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ public void ActivityListenersAreCalled()
ActivityStarted = activity =>
{
Assert.Equal("0123456789abcdef", Activity.Current.ParentSpanId.ToHexString());
},
//ActivityStopped = activity => Assert..
}
};

ActivitySource.AddActivityListener(listener);
Expand Down