Skip to content

Commit

Permalink
Log when we detect LegacyAspNetSynchronizationContext (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Jul 26, 2023
1 parent 69fa0f7 commit 4dd9b04
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Specialized;
using System.Linq;
using System.Security.Claims;
using System.Threading;
using System.Web;
using Elastic.Apm.Api;
using Elastic.Apm.AspNetFullFramework.Extensions;
Expand Down Expand Up @@ -118,6 +119,17 @@ private void OnBeginRequest(object sender, EventArgs e)
{
_logger.Debug()?.Log("Incoming request processing started - starting trace...");

try
{
var usingLegacySynchronizationContext = SynchronizationContext.Current?.GetType().Name == "LegacyAspNetSynchronizationContext";
if (usingLegacySynchronizationContext)
_logger.Warning()?.Log("ASP.NET is using LegacyAspNetSynchronizationContext and might not behave well for asynchronous code");
}
catch
{
// ignored
}

try
{
ProcessBeginRequest(sender);
Expand Down

0 comments on commit 4dd9b04

Please sign in to comment.