Skip to content
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

fix: Missing contexts #1850

Merged
merged 3 commits into from
Oct 18, 2024
Merged

fix: Missing contexts #1850

merged 3 commits into from
Oct 18, 2024

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Oct 16, 2024

We moved the collection of MainThreadData out of the MonoBehaviour's Awake call in #1802
I'm actually not 100% why that worked in the first place. The Awake happens past the SceneLoad so the contexts should not have been available at that time either.

Why is it broken

  • The SDK initializes during RuntimeInitializeLoadType.SubsystemRegistration
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
  • The SDK registers the integrations on the options
  • The UnityScopeIntegration gets registered and populates the contexts
    PopulateSdk(scope.Sdk);
    PopulateApp(scope.Contexts.App);
    PopulateOperatingSystem(scope.Contexts.OperatingSystem);
    PopulateDevice(scope.Contexts.Device);
    PopulateGpu(scope.Contexts.Gpu);
    var unity = new Protocol.Unity();
    PopulateUnity(unity);
    scope.Contexts.Add(Protocol.Unity.Type, unity);
    PopulateTags(scope.SetTag);
    PopulateUser(scope);
    }
  • The MainThreadData has not been collected at this point because this happens during BeforeSceneLoad
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void CollectData() => CollectData(SentrySystemInfoAdapter.Instance);
  • The contexts are missing

How to fix it

Instead of relying on the Unity RuntimeInitialize we can just collect the contexts right before initialization

MainThreadData.CollectData(SentrySystemInfoAdapter.Instance);

Everything is nice and explicit.
Updated our smoketest so contexts won't go missing anymore.

@bitsandfoxes bitsandfoxes merged commit 322e6c6 into main Oct 18, 2024
5 checks passed
@bitsandfoxes bitsandfoxes deleted the fix/main-thread-data branch October 18, 2024 10:57
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