Skip to content

Conversation

@bitsandfoxes
Copy link
Contributor

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?

Sentry: (Warning) Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information 
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
Sentry.Unity.UnityLogger:Log(SentryLevel, String, Exception, Object[])
Sentry.SentrySdk:InitHub(SentryOptions)
Sentry.SentrySdk:Init(SentryOptions)
Sentry.Unity.SentryUnitySdk:Init(SentryUnityOptions)
Sentry.Unity.SentrySdk:Init(SentryUnityOptions)

Sentry: (Debug) DSN read from options: https://[email protected]/huehuehue 
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
Sentry.Unity.UnityLogger:Log(SentryLevel, String, Exception, Object[])
Sentry.Internal.SettingLocator:GetDsn()
Sentry.SentrySdk:InitHub(SentryOptions)
Sentry.SentrySdk:Init(SentryOptions)
Sentry.Unity.SentryUnitySdk:Init(SentryUnityOptions)
Sentry.Unity.SentrySdk:Init(SentryUnityOptions)

Sentry: (Debug) Initializing Hub for Dsn: 'https://[email protected]/huehuehue'. 
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
Sentry.Unity.UnityLogger:Log(SentryLevel, String, Exception, Object[])
Sentry.Internal.Hub:.ctor(SentryOptions, ISentryClient, ISessionManager, ISystemClock, IInternalScopeManager, RandomValuesFactory, IReplaySession, ISampleRandHelper, BackpressureMonitor)
Sentry.SentrySdk:InitHub(SentryOptions)
Sentry.SentrySdk:Init(SentryOptions)
Sentry.Unity.SentryUnitySdk:Init(SentryUnityOptions)
Sentry.Unity.SentrySdk:Init(SentryUnityOptions)

Sentry: (Warning) Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information 
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
Sentry.Unity.UnityLogger:Log(SentryLevel, String, Exception, Object[])
Sentry.SentryClient:.ctor(SentryOptions, IBackgroundWorker, RandomValuesFactory, ISessionManager, BackpressureMonitor)
Sentry.Internal.Hub:.ctor(SentryOptions, ISentryClient, ISessionManager, ISystemClock, IInternalScopeManager, RandomValuesFactory, IReplaySession, ISampleRandHelper, BackpressureMonitor)
Sentry.SentrySdk:InitHub(SentryOptions)
Sentry.SentrySdk:Init(SentryOptions)
Sentry.Unity.SentryUnitySdk:Init(SentryUnityOptions)
Sentry.Unity.SentrySdk:Init(SentryUnityOptions)

#skip-changelog

if (options.DiagnosticLogger is null)
{
options.SetupLogging(); // Only relevant if this client wasn't created as a result of calling Init
}
Copy link

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.

Fix in Cursor Fix in Web

Copy link
Member

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 = true and explicitly a DiagnosticLogger, we do not warn.
While still providing the fallback of creating a ConsoleDiagnosticLogger as well as emitting a warning for the case where the user set Debug = true but not a custom DiagnosticLogger.

Copy link
Member

@Flash0ver Flash0ver Nov 7, 2025

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
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (version6@19a8c1a). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants