Skip to content

Commit

Permalink
Merge pull request #540 from MindscapeHQ/ph/fix-httpcontext-lost
Browse files Browse the repository at this point in the history
Build message before queuing it
  • Loading branch information
phillip-haydon authored Aug 13, 2024
2 parents b6fdd23 + 1629196 commit f2650f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGE-LOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Full Change Log for Raygun4Net.* packages

### v11.0.4
- Fix issue with `RaygunClientBase` where `SendInBackground` deferred building the message until late, losing HttpContext
- See: https://github.com/MindscapeHQ/raygun4net/pull/540

### v11.0.3
- Update `RaygunHttpModule` (Raygun4Net ASP.NET Framework) to use a singleton `RaygunClient` instance
- See: https://github.com/MindscapeHQ/raygun4net/pull/537
Expand Down
9 changes: 5 additions & 4 deletions Mindscape.Raygun4Net.NetCore.Common/RaygunClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,24 @@ public virtual async Task SendAsync(Exception exception, IList<string> tags, IDi
/// <param name="tags">A list of strings associated with the message.</param>
/// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param>
/// <param name="userInfo">Information about the user including the identity string.</param>
public virtual Task SendInBackground(Exception exception, IList<string> tags = null, IDictionary userCustomData = null, RaygunIdentifierMessage userInfo = null)
public virtual async Task SendInBackground(Exception exception, IList<string> tags = null, IDictionary userCustomData = null, RaygunIdentifierMessage userInfo = null)
{
if (CanSend(exception))
{
var exceptions = StripWrapperExceptions(exception);
foreach (var ex in exceptions)
{
if (!_backgroundMessageProcessor.Enqueue(async () => await BuildMessage(ex, tags, userCustomData, userInfo)))
// Have to do this up front as the IUserProvider may be dependent on contextual information from HttpContext
// which can get lost if the execution of the BuildMessage is done in a delegate.
var msg = await BuildMessage(ex, tags, userCustomData, userInfo);
if (!_backgroundMessageProcessor.Enqueue(msg))
{
Debug.WriteLine("Could not add message to background queue. Dropping exception: {0}", ex);
}
}

FlagAsSent(exception);
}

return Task.CompletedTask;
}

/// <summary>
Expand Down

0 comments on commit f2650f5

Please sign in to comment.