Skip to content

Add option to ASP.NET Core to flush events after response complete #288

Description

@bruno-garcia

This feature will resolve issue #126. See this comment for details.

Add an option to SentryAspNetCoreOptions named FlushOnCompletedRequest of type bool and a FlushTimeout with default value of Timestamp.FromSeconds(2).

Inside SentryMiddleware, check for this flag in the options and if opt in, add to context.Response.OnCompletd like the snippet from @madmox in #126:

context.Response.OnCompleted(async () =>
{
      await sentryClient.FlushAsync(timeout: _options.FlushTimeout);
});

await this._next(context);

Tests are required to assert FlushAsync isn't called by default and when the flag is set to false. And otherwise it is called with the default Timeout. Modifying the timeout should affect the parameter passed to FlushAsync.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions