-
-
Notifications
You must be signed in to change notification settings - Fork 226
chore: Setup logging only once #4706
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: version6
Are you sure you want to change the base?
Conversation
src/Sentry/SentryClient.cs
Outdated
| if (options.DiagnosticLogger is null) | ||
| { | ||
| options.SetupLogging(); // Only relevant if this client wasn't created as a result of calling Init | ||
| } |
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.
Bug: Logging guard blocks setup when diag logger exists
The guard condition prevents SetupLogging() from executing when DiagnosticLogger is already set. This breaks the logic when Debug is false, as SetupLogging() is responsible for setting DiagnosticLogger to null in that case. A logger set elsewhere will persist even when debugging is disabled.
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.
The "Init" / "UseSentry" / "AddSentry" path to initialize the Hub ... which is the most common scenario ... remains unchanged ... as it should.
But this common scenario is logging the "Debug is true && DiagnosticLogger is not null" case twice ... see dotnet run Sentry.Samples.Console.Basic --configuration Release.
Initializing and managing a SentryClient, e.g. when utilizing multiple DSNs, is an advanced scenario.
For these advanced scenarios, we could argue that
If the user has set
Debug = trueand explicitly aDiagnosticLogger, we do not warn.
While still providing the fallback of creating aConsoleDiagnosticLoggeras well as emitting a warning for the case where the user setDebug = truebut not a customDiagnosticLogger.
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.
However ... we would change the behavior of:
- User creates
SentryClient - with
Debug is false - with custom
DiagnosticLogger
where now the DiagnosticLogger is no longer set to null.
suggestion:
Let's change the code to only emit the warning from InitHub, but not from SentryClient,
while leaving the rest of the "SetupLogging" behavior for both cases unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## version6 #4706 +/- ##
===========================================
Coverage ? 73.23%
===========================================
Files ? 480
Lines ? 17423
Branches ? 3437
===========================================
Hits ? 12759
Misses ? 3815
Partials ? 849 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Resolves getsentry/sentry-unity#2248
Super minor but I had an issue open on the Unity SDK about it: We don't need to warn about setting up debug logging in production twice, right? Only once when actually setting the logger should suffice?
#skip-changelog