diff --git a/CHANGELOG.md b/CHANGELOG.md index c991d7c84..86bb6b7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Version 2.7.0-beta1 +- [Send UserActionable event about correlation issue with HTTP request with body when .NET 4.7.1 is not installed](https://github.com/Microsoft/ApplicationInsights-dotnet-server/pull/903) - [Added support to collect Perf Counters for .NET Core Apps if running inside Azure WebApps](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/889) - [Opt-in legacy correlation headers (x-ms-request-id and x-ms-request-root-id) extraction and injection](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/887) - [Fix: Correlation is not working for POST requests](https://github.com/Microsoft/ApplicationInsights-dotnet-server/pull/898) when .NET 4.7.1 runtime is installed. diff --git a/Src/Web/Web.Shared.Net/Implementation/WebEventSource.cs b/Src/Web/Web.Shared.Net/Implementation/WebEventSource.cs index 0270a8c56..84f2e8490 100644 --- a/Src/Web/Web.Shared.Net/Implementation/WebEventSource.cs +++ b/Src/Web/Web.Shared.Net/Implementation/WebEventSource.cs @@ -476,6 +476,17 @@ public void ActivityIsNull(string diagnosticsSourceEventName, string appDomainNa this.WriteEvent(48, diagnosticsSourceEventName, this.ApplicationName); } + [Event(49, + Keywords = Keywords.Diagnostics | Keywords.UserActionable, + Message = ".NET 4.7.1 is not installed, correlation for HTTP requests with body is not possible", + Level = EventLevel.Error)] + public void CorrelationIssueIsDetectedForRequestWithBody(string appDomainName = "Incorrect") + { + this.WriteEvent( + 49, + this.ApplicationName); + } + [NonEvent] private string GetApplicationName() { diff --git a/Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs b/Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs index 8e62bc370..1a0f6b64d 100644 --- a/Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs +++ b/Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs @@ -20,13 +20,14 @@ public class RequestTrackingTelemetryModule : ITelemetryModule { private const string IntermediateRequestHttpContextKey = "IntermediateRequest"; - private readonly IList handlersToFilter = new List(); + // if HttpApplicaiton.OnRequestExecute is available, we don't attempt to detect any correlation issues + private static bool correlationIssuesDetectionComplete = typeof(HttpApplication).GetMethod("OnExecuteRequestStep") != null; + private TelemetryClient telemetryClient; private TelemetryConfiguration telemetryConfiguration; private bool initializationErrorReported; - private bool correlationHeadersEnabled = true; private ChildRequestTrackingSuppressionModule childRequestTrackingSuppressionModule = null; - + /// /// Gets or sets a value indicating whether child request suppression is enabled or disabled. /// True by default. @@ -53,34 +54,17 @@ public class RequestTrackingTelemetryModule : ITelemetryModule /// See also . /// public int ChildRequestTrackingInternalDictionarySize { get; set; } - + /// /// Gets the list of handler types for which requests telemetry will not be collected /// if request was successful. /// - public IList Handlers - { - get - { - return this.handlersToFilter; - } - } + public IList Handlers { get; } = new List(); /// /// Gets or sets a value indicating whether the component correlation headers would be set on http responses. /// - public bool SetComponentCorrelationHttpHeaders - { - get - { - return this.correlationHeadersEnabled; - } - - set - { - this.correlationHeadersEnabled = value; - } - } + public bool SetComponentCorrelationHttpHeaders { get; set; } = true; /// /// Gets or sets the endpoint that is to be used to get the application insights resource's profile (appId etc.). @@ -219,6 +203,12 @@ public void OnEndRequest(HttpContext context) } this.telemetryClient.TrackRequest(requestTelemetry); + + if (!correlationIssuesDetectionComplete && context.Request.ContentLength > 0) + { + WebEventSource.Log.CorrelationIssueIsDetectedForRequestWithBody(); + correlationIssuesDetectionComplete = true; + } } else { @@ -394,7 +384,7 @@ private bool IsHandlerToFilter(IHttpHandler handler) return false; } - + /// /// can create a Child request to route extension-less requests to a controller. /// (ex: site/home -> site/HomeController.cs)