Skip to content

[Android] Crash with EnableBeforeSend enabled #3465

Closed
@akravch

Description

Package

Sentry

.NET Flavor

.NET

.NET Version

8.0.6

OS

Android

SDK Version

4.8.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Create an Android app and install Sentry NuGet package

  2. Configure Sentry so that EnableBeforeSend is enabled and BeforeSend callback is set to something:

    SentrySdk.Init(options =>
    {
        options.Dsn = "https://****.ingest.us.sentry.io/****";
        options.Native.EnableBeforeSend = true;
        options.SetBeforeSend(@event => @event);
    }
  3. Crash the app with a native crash, e.g. using SentrySdk.CauseCrash(CrashType.Native)

  4. Restart the app

Expected Result

BeforeSend callback is fired, the crash is sent, the app works normally.

Actual Result

Crash with the following stack trace:

System.FormatException: One of the identified items was in an invalid format.
   at System.Text.Json.JsonElement.GetInt16()
   at Sentry.Protocol.Device.FromJson(JsonElement json)
   at Sentry.SentryContexts.FromJson(JsonElement json)
   at Sentry.Internal.Extensions.MiscExtensions.Pipe[JsonElement,SentryContexts](JsonElement input, Func`2 pipe)
   at Sentry.SentryEvent.FromJson(JsonElement json, Exception exception)
   at Sentry.Android.Extensions.SentryEventExtensions.ToSentryEvent(SentryEvent sentryEvent, SentryOptions javaOptions)
   at Sentry.Android.Callbacks.BeforeSendCallback.Execute(SentryEvent e, Hint h)
   at Sentry.JavaSdk.SentryOptions.IBeforeSendCallbackInvoker.n_Execute_Lio_sentry_SentryEvent_Lio_sentry_Hint_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0, IntPtr native_p1)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_L(_JniMarshal_PPLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 231

The reason is that the battery_level field is saved with a floating point, but the SDK expects short during deserialization:

{
    "device": {
        "manufacturer": "samsung",
        "brand": "samsung",
        "family": "SM-G991B",
        "model": "SM-G991B",
        "model_id": "UP1A.231005.007",
        "archs": [
            "arm64-v8a",
            "armeabi-v7a",
            "armeabi"
        ],
        "battery_level": 67.0,
        "charging": true,
        "orientation": "portrait",
        "simulator": false,
        "memory_size": 7550787584,
        "storage_size": 114057785344,
        "free_storage": 98203328512,
        "screen_width_pixels": 1080,
        "screen_height_pixels": 2176,
        "screen_density": 3.0,
        "screen_dpi": 480,
        "boot_time": "2024-07-05T13:10:13.757Z",
        "timezone": "Europe/Warsaw",
        "id": "e24d244e-0be7-4bdb-a744-bd7419c14eec",
        "language": "en",
        "battery_temperature": 30.6,
        "locale": "en_US",
        "processor_count": 8,
        "processor_frequency": 2912.0
    },
    "os": {
        "name": "Android",
        "version": "14",
        "build": "UP1A.231005.007.G991BXXS9FXBD",
        "kernel_version": "5.4.242-27760517-abG991BXXS9FXBD",
        "rooted": false
    },
    "os_linux": {
        "name": "Linux",
        "version": "5.4.242",
        "build": "27760517-abG991BXXS9FXBD"
    }
}

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions