Skip to content

Logs & Breadcrumbs leaks #1660

Closed
Closed

Description

@Vandersteen

Please mark the type framework used:

  • ASP.NET Core

Please mark the type of the runtime used:

  • .NET Core
  • Version:

Please mark the NuGet packages used:

  • Sentry.Extensions.Logging
  • Sentry.AspNetCore
  • Version: 3.17.1

Is there a way to start a 'fresh' scope with the Sentry Sdk ?

We use sentry in WorkerServices etc. but logs / breadcrumb do leak over from Startup / other IHostedServices.

Example IHostedService:

public class Worker : BackgroundService
{
    private readonly IHub _hub;

    public Worker(IHub hub)
    {
        _hub = hub;
    }

    public async Task ExecuteAsync(CancellationToken token)
    {
        while (!token.IsCancellationRequested)
        {
            using (var scope = _hub.PushScope())
            {
                await DoSomeWork();
            }
        }
    }
}

Every issue that is reported from this Worker, also contains logs from Startup and other IHostedService (that we do not always have control over)

Is there a way to not 'Push' a scope but start from a 'fresh' scope instead ?

Activity

  1. added
    Question
    on May 22, 2022
  2. bruno-garcia commented on Jun 14, 2022

    @bruno-garcia
    Member

    Is this just about the breadcrumbs list having entries from before that scope? Or any other data from the scope isn't relevant?
    Because this could be a matter of PushScope having some argument to return an empty scope. Or Scope could have a Clear method. Or just the Breadcrumbs on the scope could have a clear method

  3. Vandersteen commented on Jun 14, 2022

    @Vandersteen
    Author

    Is this just about the breadcrumbs list having entries from before that scope?

    Yes

    Another example could be the following:

    Some Framework code we have no control over

    while(true)
    {
      var message = FetchNextMessage();
    
      _logger.LogInformation("Fetched message with id {id}", message.id);
      ProcessMessage(message);
      _logger.LogInformation("Processed message with id {id}", message.id);
    }
    

    Where you can implement a 'Processor'

    public class MyProcessor : IProcessor
    {
      public Task Process(Message message)
      {
         using var scope = _hub.PushScope();
         _logger.LogInformation("...");
       
        //Throw an exception here
        //Or send an event to sentry 
      }
    }
    

    The breadcrumbs slowly get filled with the framework code from previous messages (which we can't control)
    This can quickly lead to thousand / millions of (unrelated) breadcrumbs being sent with events (a leak if you like)

    So having something like a _hub.StartScope(); or _hub.NewScope(); or scope.Clear() would be very handy in this use case

  4. bruno-garcia commented on Jun 15, 2022

    @bruno-garcia
    Member

    @Vandersteen would you be willing to send a PR to add Clear?

  5. Vandersteen commented on Aug 30, 2022

    @Vandersteen
    Author

    @bruno-garcia I might be able to free some time, no promises thought.
    Could you point me in the right direction ?

  6. mattjohnsonpint commented on Dec 12, 2022

    @mattjohnsonpint
    Contributor

    FWIW, it appears that scope.Clear and scope.ClearBreadcrumbs are defined in the Unified API spec, so we should definitely add them.

    https://develop.sentry.dev/sdk/unified-api/#scope

  7. hheexx commented on Dec 28, 2022

    @hheexx

    Also please add SentryEvent.ClearBreadcrumbs() so we can clear breadcrumbs in BeforeSend.
    (i'm not sure if this is seperate or same)

  8. removed
    Question
    on Mar 30, 2023
  9. mattjohnsonpint commented on Mar 30, 2023

    @mattjohnsonpint
    Contributor

    Hi. Just for clarity, I've created two new issue to track this work:

    Closing this issue in favor of those. Thanks.

  10. mattjohnsonpint commented on Apr 14, 2023

    @mattjohnsonpint
    Contributor

    Scope.Clear has been released in 3.30.0.

    See example: in #2274

    Also, just to clarify options.IsGlobalMode should be false (which is the default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Feature

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions