sentry-dart icon indicating copy to clipboard operation
sentry-dart copied to clipboard

Add a way to remove an attachment from the scope

Open ueman opened this issue 3 years ago • 4 comments
trafficstars

There should be a way to remove an attachment, which was previously added, from the scope. This prevents that the same attachment is sent for multiple crash reports. It's also the last missing piece needed for finishing https://github.com/getsentry/sentry-dart/pull/576

ueman avatar Jan 21 '22 19:01 ueman

That depends on https://github.com/getsentry/sentry-dart/issues/510 by the way. Discussed solutions are making it available on beforeSend via hints or adding a boolean to the add attachment method, sendOnlyOnce or a new method called removeAttachment(...), we're going to discuss it.

marandaneto avatar Jan 25 '22 09:01 marandaneto

If the goal is to capture a single event with an attachment the solution is to capture an event with a local scope.

brustolin avatar Apr 21 '22 12:04 brustolin

@ueman does https://docs.sentry.io/platforms/dart/enriching-events/scopes/#local-scopes help to add an attachment to a single scope?

marandaneto avatar Apr 22 '22 07:04 marandaneto

I think so. That would make it possible to do

Sentry.captureException(
    exception,
    withScope: (scope) {
        scope.addAttachment(ScreenshotAttachment());
    },
);

ueman avatar Apr 22 '22 07:04 ueman

#1136 is going to unblock this via hints

marandaneto avatar Dec 04 '22 18:12 marandaneto

You can do https://github.com/getsentry/sentry-dart/issues/711#issuecomment-1106119591 or https://github.com/getsentry/sentry-dart/blob/fa16e53b4bb6d070a637610acb48612b82700d3c/dart/lib/src/scope.dart#L211-L213

marandaneto avatar Jan 26 '23 12:01 marandaneto