-
-
Notifications
You must be signed in to change notification settings - Fork 62
feat: LifeCycleIntegration and changes to trace generation
#2374
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
Merged
bitsandfoxes
merged 33 commits into
feat/bump-version6
from
feat/structured-logging-followup1
Oct 30, 2025
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e75f147
Unseal
bitsandfoxes 7f88a98
Added structured logging capture to
bitsandfoxes e2ae095
Updated sample LogError message
bitsandfoxes 3da5fc9
Opt-in check for breadcrumb collection
bitsandfoxes 7834bc0
Added logging
bitsandfoxes 34823dc
Options
bitsandfoxes 73eb7ed
Wrapup for Logging
bitsandfoxes ee9dfc0
Fixed debounce logic
bitsandfoxes dc8a638
Interation on working base
bitsandfoxes 90b12a8
Added beforesend
bitsandfoxes ddc9605
Added logger to Unity SDK static API
bitsandfoxes e62733c
Updated CHANGELOG.md
bitsandfoxes 7f9950d
Don't access internal structured logger
bitsandfoxes 5facd76
Missed enable check and test
bitsandfoxes 5eaec84
Bump global.json
bitsandfoxes 590cf2e
Renamed scriptable options
bitsandfoxes 3218a7f
Bump underlying version6
bitsandfoxes 83f8538
Merge branch 'feat/bump-version6' into feat/structured-logging
bitsandfoxes 5e48eea
Merge branch 'feat/bump-version6' into feat/structured-logging
bitsandfoxes 6914ca9
Merge branch 'feat/bump-version6' into feat/structured-logging
bitsandfoxes fe9d609
Merge branch 'feat/bump-version6' into feat/structured-logging
bitsandfoxes 4d11606
Merge branch 'feat/bump-version6' into feat/structured-logging
bitsandfoxes 4dd1fd2
Unified life cycle things in LifeCycleIntegration
bitsandfoxes 78c80ad
Use the logger on the hub
bitsandfoxes 7493a59
Logmessage
bitsandfoxes 8c3f129
Cleanup
bitsandfoxes 6106033
Fixed no-logger-fallback
bitsandfoxes 4f44a3b
Merged Structured Logging
bitsandfoxes 97dbe03
Removed now obsolete test
bitsandfoxes 16852f0
Format code
getsentry-bot faffaf8
Updated CHANGELOG.md
bitsandfoxes 0534886
Merge branch 'feat/structured-logging-followup1' of https://github.co…
bitsandfoxes 026fb26
Merged feat/bump-version6
bitsandfoxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| using System; | ||
| using Sentry.Extensibility; | ||
| using Sentry.Integrations; | ||
|
|
||
| namespace Sentry.Unity.Integrations; | ||
|
|
||
| internal class LifeCycleIntegration : ISdkIntegration | ||
| { | ||
| private IHub? _hub; | ||
| private SentryUnityOptions _options = null!; // Set during register | ||
|
|
||
| private readonly SentryMonoBehaviour _sentryMonoBehaviour; | ||
| private readonly IApplication _application; | ||
|
|
||
| public LifeCycleIntegration(SentryMonoBehaviour sentryMonoBehaviour, IApplication? application = null) | ||
| { | ||
| _application = application ?? ApplicationAdapter.Instance; | ||
| _sentryMonoBehaviour = sentryMonoBehaviour; | ||
| } | ||
|
|
||
| public void Register(IHub hub, SentryOptions sentryOptions) | ||
| { | ||
| _hub = hub; | ||
| // This should never happen, but if it does... | ||
| _options = sentryOptions as SentryUnityOptions ?? throw new ArgumentException("Options is not of type 'SentryUnityOptions'."); | ||
|
|
||
| if (!_options.AutoSessionTracking) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _sentryMonoBehaviour.ApplicationResuming += () => | ||
| { | ||
| if (!hub.IsEnabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| hub.AddBreadcrumb(message: "App regained focus.", category: "app.lifecycle"); | ||
|
|
||
| _options.DiagnosticLogger?.LogDebug("Resuming session."); | ||
| hub.ResumeSession(); | ||
| }; | ||
| _sentryMonoBehaviour.ApplicationPausing += () => | ||
| { | ||
| if (!hub.IsEnabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| hub.AddBreadcrumb(message: "App lost focus.", category: "app.lifecycle"); | ||
|
|
||
| _options.DiagnosticLogger?.LogDebug("Pausing session."); | ||
| hub.PauseSession(); | ||
| }; | ||
|
|
||
| _application.Quitting += OnQuitting; | ||
| } | ||
|
|
||
| private void OnQuitting() | ||
| { | ||
| // Platform-specific behavior notes: | ||
| // - iOS: Applications are usually suspended and do not quit. If `Exit on Suspend` is enabled in Player Settings, | ||
| // the application will be terminated on suspend instead of calling this method. In that case, | ||
| // `OnApplicationPause` will be called instead. | ||
| // - Windows Store Apps/Windows Phone 8.1: No application quit event exists. Use OnApplicationFocus instead. | ||
| // - WebGL: OnApplicationQuit cannot be implemented due to browser tab closing behavior. | ||
|
|
||
| // Session handling on shutdown: | ||
| // This method is invoked even when an uncaught exception occurs (including crashes in native layers). | ||
| // We pause the session here rather than ending it to ensure the .NET SDK can properly detect crashes | ||
| // on the next startup (via the CrashedLastRun callback). The session will then be closed with the | ||
| // correct timestamp during initialization. | ||
| if (_options.AutoSessionTracking) | ||
| { | ||
| _hub?.PauseSession(); | ||
| } | ||
|
|
||
| _hub?.FlushAsync(_options.ShutdownTimeout).GetAwaiter().GetResult(); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Session Tracking Affects Event Flushing
The
OnQuittingevent handler, which flushes pending events, is only registered whenAutoSessionTrackingis enabled. This preventsFlushAsyncfrom being called on application shutdown if session tracking is disabled, potentially causing event loss.