Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Add more context into ActivityIsNull logging #800

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 27 additions & 23 deletions Src/DependencyCollector/Shared/HttpCoreDiagnosticSourceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,24 @@ public void Dispose()
/// </summary>
internal void OnException(Exception exception, HttpRequestMessage request)
{
// Even though we have the IsEnabled filter, to reject ApplicationInsights URLs before any events are fired,
// Exceptions are special and fired even if request instrumentation is disabled.
if (this.applicationInsightsUrlFilter.IsApplicationInsightsUrl(request.RequestUri))
{
return;
}

Activity currentActivity = Activity.Current;
if (currentActivity == null)
{
DependencyCollectorEventSource.Log.CurrentActivityIsNull();
DependencyCollectorEventSource.Log.CurrentActivityIsNull(HttpExceptionEventName);
return;
}

DependencyCollectorEventSource.Log.HttpCoreDiagnosticSourceListenerException(currentActivity.Id);

// Even though we have the IsEnabled filter, to reject ApplicationInsights URLs before any events are fired,
// Exceptions are special and fired even if request instrumentation is disabled.
if (!this.applicationInsightsUrlFilter.IsApplicationInsightsUrl(request.RequestUri))
{
this.pendingExceptions.TryAdd(currentActivity.Id, exception);
this.client.TrackException(exception);
}
this.pendingExceptions.TryAdd(currentActivity.Id, exception);
this.client.TrackException(exception);
}

//// netcoreapp 2.0 event
Expand All @@ -276,21 +278,23 @@ internal void OnException(Exception exception, HttpRequestMessage request)
/// </summary>
internal void OnActivityStart(HttpRequestMessage request)
{
// Even though we have the IsEnabled filter to reject ApplicationInsights URLs before any events are fired, if there
// are multiple subscribers and one subscriber returns true to IsEnabled then all subscribers will receive the event.
if (this.applicationInsightsUrlFilter.IsApplicationInsightsUrl(request.RequestUri))
{
return;
}

var currentActivity = Activity.Current;
if (currentActivity == null)
{
DependencyCollectorEventSource.Log.CurrentActivityIsNull();
DependencyCollectorEventSource.Log.CurrentActivityIsNull(HttpOutStartEventName);
return;
}

DependencyCollectorEventSource.Log.HttpCoreDiagnosticSourceListenerStart(currentActivity.Id);

// Even though we have the IsEnabled filter to reject ApplicationInsights URLs before any events are fired, if there
// are multiple subscribers and one subscriber returns true to IsEnabled then all subscribers will receive the event.
if (!this.applicationInsightsUrlFilter.IsApplicationInsightsUrl(request.RequestUri))
{
this.InjectRequestHeaders(request, this.configuration.InstrumentationKey);
}
this.InjectRequestHeaders(request, this.configuration.InstrumentationKey);
}

//// netcoreapp 2.0 event
Expand All @@ -300,22 +304,22 @@ internal void OnActivityStart(HttpRequestMessage request)
/// </summary>
internal void OnActivityStop(HttpResponseMessage response, HttpRequestMessage request, TaskStatus requestTaskStatus)
{
Activity currentActivity = Activity.Current;
if (currentActivity == null)
// Even though we have the IsEnabled filter to reject ApplicationInsights URLs before any events are fired, if there
// are multiple subscribers and one subscriber returns true to IsEnabled then all subscribers will receive the event.
if (this.applicationInsightsUrlFilter.IsApplicationInsightsUrl(request.RequestUri))
{
DependencyCollectorEventSource.Log.CurrentActivityIsNull();
return;
}

DependencyCollectorEventSource.Log.HttpCoreDiagnosticSourceListenerStop(currentActivity.Id);

// Even though we have the IsEnabled filter to reject ApplicationInsights URLs before any events are fired, if there
// are multiple subscribers and one subscriber returns true to IsEnabled then all subscribers will receive the event.
if (this.applicationInsightsUrlFilter.IsApplicationInsightsUrl(request.RequestUri))
Activity currentActivity = Activity.Current;
if (currentActivity == null)
{
DependencyCollectorEventSource.Log.CurrentActivityIsNull(HttpOutStopEventName);
return;
}

DependencyCollectorEventSource.Log.HttpCoreDiagnosticSourceListenerStop(currentActivity.Id);

Uri requestUri = request.RequestUri;
var resourceName = request.Method.Method + " " + requestUri.AbsolutePath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ public void EndAsyncExceptionCallbackCalled(string id, string appDomainName = "I

[Event(
23,
Message = "Current Activity is null",
Message = "Current Activity is null for event = '{0}'",
Level = EventLevel.Error)]
public void CurrentActivityIsNull(string appDomainName = "Incorrect")
public void CurrentActivityIsNull(string diagnosticsSourceEventName, string appDomainName = "Incorrect")
{
this.WriteEvent(23, this.ApplicationName);
this.WriteEvent(23, diagnosticsSourceEventName, this.ApplicationName);
}

[Event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ internal IndividualDiagnosticSourceListener(DiagnosticListener diagnosticListene

public void OnNext(KeyValuePair<string, object> evnt)
{
Activity currentActivity = Activity.Current;
if (currentActivity == null)
{
DependencyCollectorEventSource.Log.CurrentActivityIsNull();
return;
}

// while we provide IsEnabled callback during subscription, it does not gurantee events will not be fired
// In case of multiple subscribers, it's enough for one to reply true to IsEnabled.
// I.e. check for if activity is not disabled and particular handler wants to receive the event.
if (this.telemetryDiagnosticSourceListener.IsActivityEnabled(evnt.Key, this.Context) && this.eventHandler.IsEventEnabled(evnt.Key, null, null))
{
Activity currentActivity = Activity.Current;
if (currentActivity == null)
{
DependencyCollectorEventSource.Log.CurrentActivityIsNull(evnt.Key);
return;
}

DependencyCollectorEventSource.Log.TelemetryDiagnosticSourceListenerEvent(evnt.Key, currentActivity.Id);

try
Expand Down