Skip to content

Align how we enrich the event with device context on Hybrid SDKs #11

@marandaneto

Description

@marandaneto

The way how we enrich the event with device context on Hybrid SDKs varies depending on the OS.

iOS: The device context lives on the scope, so we call the native bridge, serialize the scope, return a Map and build the event with all the device context, all the device context is available in the beforeSend callback.
https://github.com/getsentry/sentry-dart/blob/912b9205691837abdd546c62844bc9568b908495/flutter/ios/Classes/SentryFlutterPluginApple.swift#L84-L132
Once the event is built, we call captureEnvelope https://github.com/getsentry/sentry-dart/blob/912b9205691837abdd546c62844bc9568b908495/flutter/ios/Classes/SentryFlutterPluginApple.swift#L340

Android: The Hybrid SDK writes the envelope into the disk and a File observer that lives in the Android SDK picks it up, deserializes, and enriches the event with the device context via Event processors, all the device context is not available in the beforeSend callback.
https://github.com/getsentry/sentry-dart/blob/912b9205691837abdd546c62844bc9568b908495/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt#L89

Both implementations have a trade-off but I believe we should follow the iOS way or find a better alternative.
For that, we'd need to change how the Android SDK enriches the event with device context.

What we want:
The device context should be visible in the beforeSend callback for Android and iOS, you should also be able to filter out the event.
We want to unify this behavior since this leads to different problems depending on the platform.

Ps: We cannot get rid of the File observer on Android due to sentry-native that cannot call the JNI bridge within the signal handler.

Hacks like this should go away.

### Android SDK
- [x] Move Session Health logic from `captureEvent` to `captureEnvelope` to keep the feature working for Hybrid SDKs
- [x] Provide a way to retrieve the scope data (pull based approach). Have a `ScopeUtils.serialize(scope)` class
- [ ] https://github.com/getsentry/sentry-java/pull/2814
- [x] For event enriching: For collections (e.g. breadcrumbs) stop trying to merge values (use hybrid hint)
- [x] Provide a way to retrieve the sdk name/version
- [x] Provide a way to retrieve dist + environment from options
### Hybrid SDKs
- [x] Retrieve above data
- [x] Use `HubAdapter.getInstance().captureEnvelope()` for capturing the envelope
- [x] Consider if moving to `captureEnvelope` is not breaking feature (event won't be in the native `beforeSend` anymore)
- [ ] https://github.com/getsentry/sentry-react-native/pull/3170
- [ ] https://github.com/getsentry/sentry-dart/issues/1556
- [ ] https://github.com/getsentry/sentry-capacitor/issues/263

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions