-
-
Notifications
You must be signed in to change notification settings - Fork 356
refactor: Add factory for SentryClient to dependency container #5315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,7 +237,8 @@ | |
startInvocations++; | ||
startTimestamp = [SentryDependencyContainer.sharedInstance.dateProvider date]; | ||
|
||
SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; | ||
SentryClient *newClient = | ||
[SentryDependencyContainer.sharedInstance getClientWithOptions:options]; | ||
Comment on lines
+240
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
is this an actual SDK requirement, or just due to the fact that we don't want to change the current public API in our implementation to avoid a major rev? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the topic of what we're solving for here, I would be interested to know as well. AFAIUI this PR would help solve part of the file-backed data for watchdog events. Why do we need multiple instances of SentryFileManager for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's part of the unified API, which we deprecated some time ago, because we're merging the hub and the scope. Once we do the next major we can revisit if we want to keep the client public. There are some use cases for initializing your own client, which I can't recall from the top of my head. Most users on Cocoa interact with the static API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To summarize what we are trying to fix:
For reference, if instances are properly managed in a dependency container the entire integration can be delegate to testable and mockable factories. This technical documentation of Swinject might be helpful in seeing the advantages: https://github.com/Swinject/Swinject/tree/master/Documentation |
||
[newClient.fileManager moveAppStateToPreviousAppState]; | ||
[newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h
: The way the synchronization currently works in the SentryFileManager, we must ensure only having one SentryFileManager instance per DSN, as you already pointed out in the PR description. Otherwise, we end up with race conditions when accessing the files.I think your idea of keeping weak references using the DSN with the key and the file manager as a value could work.