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

Handle DSN changes

Open philipphofmann opened this issue 3 years ago • 2 comments

Description

Currently, when having session, app state, or envelopes stored on disk and the user changes the DSN to a new one, this data stays there forever. As the path for storing this data depends on the hash of the DSN see

https://github.com/getsentry/sentry-cocoa/blob/4125751b104bee6763236cf539d46aec78549926/Sources/Sentry/SentryFileManager.m#L48-L54

The SDK should delete this data and maybe also send cached envelopes to Sentry with the new DSN. Just deleting might be fine as this is an edge case.

Please align this behavior with Android.

philipphofmann avatar May 09 '22 10:05 philipphofmann

Be aware the user might have more than one app installed with different DSNs (on macOS for example). On iOS where it's sandboxed it's OK

bruno-garcia avatar May 09 '22 12:05 bruno-garcia

Please document the outcome here https://develop.sentry.dev/sdk/features/#buffer-to-disk.

philipphofmann avatar May 09 '22 12:05 philipphofmann

Question: the DSN can't be changed while the app is running, right? The options are immutable. So on app start up we'd need to remove the old stuff, when the DSN got changed. But at that point we don't have access to the old DSN any more.

Do we loop over all folders in [cachePath stringByAppendingPathComponent:@"io.sentry"], and delete everything that isn't [self.sentryPath stringByAppendingPathComponent:[options.parsedDsn getHash]]? Or do we store the DSN on disk to detect changes that way?

As an aside, why does the deleteAllFolders method delete these 2 things separately, when self.envelopesPath is a subfolder of self.sentryPath?

- (void)deleteAllFolders
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:self.envelopesPath error:nil];
    [fileManager removeItemAtPath:self.sentryPath error:nil];
}

Another, much simpler, option would be to just remove the [self.sentryPath stringByAppendingPathComponent:[options.parsedDsn getHash]] logic, at least on iOS? Every app is sandboxed, so normally there should always be only one hashed DSN subfolder in there. And if you do change the DSN, getting rid of that subfolder means the old stuff can still get sent, it will participate in deleteAllFolders, etc.

What do you think, @philipphofmann?

kevinrenskers avatar Oct 13 '22 07:10 kevinrenskers

You could have multiple hubs running at the same time with different DSNs. You could also close the SDK and start it again with a different DSN. So removing the hash doesn't work.

A very simple approach would be to once in a while delete any envelope items, no matter the DSN, being older than 90 days, as Sentry only retains data for 90 days, see https://sentry.io/security/#data-retention.

As an aside, why does the deleteAllFolders method delete these 2 things separately, when self.envelopesPath is a subfolder of self.sentryPath?

Feel free to improve this in a PR, please.

philipphofmann avatar Oct 13 '22 14:10 philipphofmann