Skip to content

Initial scope sync for native integrations #2923

Open

Description

@vaind

Native integrations should sync the contexts when they're started. Currently, this is not possible because contexts are only filled in when a first managed event is being processed.

See https://github.com/getsentry/sentry-dotnet/blob/217c11cea611a5f26e4a1abfbb7df37f34695722/src/Sentry/Platforms/Native/SentrySdk.cs#L24_L37

  • native
  • cocoa
  • android

Activity

  1. bitsandfoxes commented on Sep 6, 2024

    @bitsandfoxes
    Contributor

    If I get that right, the .NET SDK is holding off on it as to avoid any unnecessary work? But in case of a native event it's too late to provide the missing context.

  2. moved this to Blocked in GDXon Feb 21, 2025
  3. added
    .NET
    and removed on Mar 24, 2026
  4. jamescrosswell commented on May 19, 2026

    @jamescrosswell
    Collaborator

    We could add an option PreloadEventContext or something like that... folks that want this could opt in.

  5. jamescrosswell commented on Oct 6, 2026

    @jamescrosswell
    Collaborator

    A plan for this, now that #5671 has added ScopeDefaults on version7.

    What changed. ScopeDefaults computes the OS, runtime and device boot-time contexts once, in SentrySdk.Init, so they exist before the first managed event. Sending them to the native SDKs at init no longer costs anything extra, so an opt-in option shouldn't be needed.

    What to send. Only what the native SDKs can't collect themselves. Cocoa and Android already gather richer OS and device data, and sending ours would overwrite it. That's the same problem fixed in review on #5671, where a partial Xbox OS context picked up the host's macOS version. That probably leaves the .NET runtime context, but each SDK needs checking:

    • native: does sentry-native add its own os context?
    • cocoa
    • android

    How. IScopeObserver has no context member, and it's public because Unity's ScopeObserver implements it, so adding one would be breaking. Instead, the built-in observers can implement a small internal interface. SentrySdk.InitHub calls it once after native init, next to the existing default-tags push:

    • native: sentry_set_context
    • cocoa: setContextValue on the scope
    • android: setContexts on the Java scope

    These values are the same for the whole process, so they're safe on a native SDK's single global scope, even in server apps that have a scope per request. The concern raised in #5052 for attachments doesn't apply.

    Testing. Unit tests with a substitute observer, and ideally the iOS and Android crash integration tests checking that a native crash carries the .NET runtime context.

    This is additive, so it isn't needed for 7.0 and can ship in any 7.x release.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETImprovement

    Projects

    • Status
      Blocked

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions