Skip to content

Conversation

@bitsandfoxes
Copy link
Contributor

Followup on #2496 and #2374

The SDK refrains from creating a new propagation context due to lifecycle events, see #2374

But it still does so on active scene change, leading to fragmentation of logs over the lifespan of the game.


if (!_options.AutoSessionTracking)
{
sentryOptions.LogDebug("AutoSessionTracking is disabled. Skipping {0}.", nameof(LifeCycleIntegration));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing log when Register actually skips registering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing log when Register actually skips registering. Following the pattern everywhere else in the SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing log when Register actually skips registering. Following the pattern everywhere else in the SDK.

Comment on lines -38 to -47

// Set up scene change handling if tracing is disabled or auto scene load traces are disabled
if (!isTracingEnabled || !unityOptions.AutoSceneLoadTraces)
{
_sceneManager.ActiveSceneChanged += (_, _) =>
{
options.DiagnosticLogger?.LogDebug("Active Scene changed. Creating new Trace.");
hub.ConfigureScope(scope => scope.SetPropagationContext(new SentryPropagationContext()));
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actually relevant change.

}
else if (options is SentryUnityOptions unityOptions)
{
options.LogDebug("Skipping registering '{0}'. Either 'TracesSampleRate' set to '0' or 'AutoStartupTraces' is set to 'false'", nameof(StartupTracingIntegration));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The code calls LogDebug() and LogWarning() directly on SentryOptions objects. These methods do not exist and will cause a runtime crash.
Severity: HIGH

Suggested Fix

Replace direct calls like options.LogDebug(...) with the correct pattern used elsewhere in the codebase: options.DiagnosticLogger?.LogDebug(...). This applies to all instances of LogDebug and LogWarning called directly on the options object.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/Sentry.Unity/Integrations/StartupTracingIntegration.cs#L46

Potential issue: The code in `StartupTracingIntegration`, `LifeCycleIntegration`, and
`SceneManagerTracingIntegration` incorrectly calls `options.LogDebug(...)` and
`options.LogWarning(...)`. These methods are not defined on the `SentryOptions` or
`SentryUnityOptions` classes. This will result in a `MissingMethodException` at runtime
when these logging statements are executed. For example, in `StartupTracingIntegration`,
the application will crash if `TracesSampleRate <= 0` or `AutoStartupTraces` is false.
Similar crashes will occur in other integrations under specific, common configuration
scenarios.

Did we get this right? 👍 / 👎 to inform future reviews.

@bitsandfoxes bitsandfoxes requested a review from a team January 26, 2026 17:17
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.

2 participants