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

Replace non-threadsafe HashSet with ConcurrentDictionary in RequestTrackingTelemetryModule.IsHandlerToFilter #1211

Merged
merged 2 commits into from Jun 4, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,9 @@
# Changelog


## vNext
- [Fix: Replaced non-threadsafe HashSet with ConcurrentDictionary in RequestTrackingTelemetryModule.IsHandlerToFilter](https://github.com/microsoft/ApplicationInsights-dotnet-server/pull/1211)

## Version 2.11.0-beta1
- [Defer populating RequestTelemetry properties.](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1173)

Expand Down
14 changes: 6 additions & 8 deletions Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs
Expand Up @@ -24,16 +24,14 @@ public class RequestTrackingTelemetryModule : ITelemetryModule
// if HttpApplicaiton.OnRequestExecute is available, we don't attempt to detect any correlation issues
private static bool correlationIssuesDetectionComplete = typeof(HttpApplication).GetMethod("OnExecuteRequestStep") != null;

/// <summary>Tracks if given type should be included in telemetry. ConcurrentDictionary is used as a concurrent hashset.</summary>
private readonly ConcurrentDictionary<Type, bool> includedHttpHandlerTypes = new ConcurrentDictionary<Type, bool>();

private TelemetryClient telemetryClient;
private TelemetryConfiguration telemetryConfiguration;
private bool initializationErrorReported;
private ChildRequestTrackingSuppressionModule childRequestTrackingSuppressionModule = null;

/// <summary>
/// Handler types that are not TransferHandlers will be included in request tracking.
/// </summary>
private HashSet<Type> requestHandlerTypesDoNotFilter = new HashSet<Type>();


/// <summary>
/// Gets or sets a value indicating whether child request suppression is enabled or disabled.
/// True by default.
Expand Down Expand Up @@ -371,7 +369,7 @@ private bool IsHandlerToFilter(IHttpHandler handler)
if (handler != null)
{
var handlerType = handler.GetType();
if (!this.requestHandlerTypesDoNotFilter.Contains(handlerType))
if (!this.includedHttpHandlerTypes.ContainsKey(handlerType))
{
var handlerName = handlerType.FullName;
foreach (var h in this.Handlers)
Expand All @@ -383,7 +381,7 @@ private bool IsHandlerToFilter(IHttpHandler handler)
}
}

this.requestHandlerTypesDoNotFilter.Add(handlerType);
this.includedHttpHandlerTypes.TryAdd(handlerType, true);
}
}

Expand Down