sentry icon indicating copy to clipboard operation
sentry copied to clipboard

SDK Crash Detection: Enable Dart/Flutter

Open kahest opened this issue 1 year ago • 11 comments

Enable the SDK crash detection for the sentry-dart SDK.

### Tasks
- [ ] https://github.com/getsentry/sentry-dart/pull/2050
- [ ] https://github.com/getsentry/sentry/pull/71233
- [ ] https://github.com/getsentry/sentry/pull/71318
- [ ] https://github.com/getsentry/sentry-options-automator/pull/1464
- [ ] https://github.com/getsentry/sentry-options-automator/pull/1465

kahest avatar Mar 12 '24 11:03 kahest

@buenaflor, I need your input, please. If you need a refresher on what SDK crash detection is, read this.

I plan to enable the SDK crash detection for the Dart SDK. To do this, I need to create a configuration similar to what we already have for the Java SDK.

https://github.com/getsentry/sentry/blob/3e90887a3632585b048f607668e20927321a39a0/src/sentry/utils/sdk_crashes/sdk_crash_detection_config.py#L154-L202

This is how the configuration would roughly look:

dart_config = SDKCrashDetectionConfig(
    # ...
    sdk_names=["sentry.dart", "sentry.dart.flutter"],
    # 7.9.0 was released in July 2023, see https://github.com/getsentry/sentry-dart/releases/tag/7.9.0
    min_sdk_version="7.9.0",
    system_library_path_patterns={
        r"third_party/dart/sdk/**",  # Dart
        r"/opt/flutter/packages/flutter/**",  # Flutter
    },
    sdk_frame_config=SDKFrameConfig(
        function_patterns=set(),
        path_patterns={
            r"**/sentry-**",
        },
        path_replacer=KeepAfterPatternMatchPathReplacer(
            patterns={
                r"\/sentry-.*",
            },
            fallback_path="sentry",
        ),
    ),
    sdk_crash_ignore_functions_matchers=set(),
)

@buenaflor, please answer the following questions:

  1. Does the Dart SDK have more SDK names? If yes, which ones?
  2. Which system_library_path_patterns should I add? This is for keeping system library or system binary frames in the stacktrace for SDK crashes?
  3. If I'm not mistaken, all Sentry Dart SDK frames have sentry- in their abs_path followed by the version number of the SDK? Is there a better reliable way to detect Sentry Dart SDK frames?
  4. Regarding sdk_crash_ignore_functions_matchers: For Cocoa we have a test function causing a crash we want to ignore. Does the Sentry Dart SDK have something similar?

philipphofmann avatar May 06 '24 07:05 philipphofmann

  1. afaik the names include:sentry.dart, sentry.dart.flutter, sentry.dart.browser
  2. Judging by some of the abs_paths: package:flutter/src/gestures/tap.dart, dart:ui/platform_dispatcher.dart, something like r"flutter/**" and r"dart:**", but I'm not too sure about the syntax. As for web errors it seems a bit more complicated since there is no obvious system library path, e.g this web stacktrace, for example http://localhost:53744/binding.dart
  3. The abs path usually looks like package:sentry** or package:sentry_flutter** I'm wondering though how we can detect sdk frames at all since we remove them: https://github.com/getsentry/sentry-dart/blob/6575860857eb9784ce13785f3a2eeade01013808/dart/lib/src/sentry_stack_trace_factory.dart#L44
  4. No we don't

buenaflor avatar May 06 '24 13:05 buenaflor

I'm wondering though how we can detect sdk frames at all since we remove them: https://github.com/getsentry/sentry-dart/blob/6575860857eb9784ce13785f3a2eeade01013808/dart/lib/src/sentry_stack_trace_factory.dart#L44

@buenaflor, upsi, that's a blocker. Can we start sending them? On Java, we send SDK frames in case of a crash (https://github.com/getsentry/sentry-java/pull/3021), but it's better to do this in the next major because it can affect grouping. Otherwise, the SDK crash detection won't work.

philipphofmann avatar May 06 '24 14:05 philipphofmann

Hmm is it still feasible to do it in the current major? we've released v8 but it's still pretty new. otherwise we can add this to v9 but tbh I'm not sure when the next major for dart would be released

buenaflor avatar May 06 '24 15:05 buenaflor

@buenaflor, strictly speaking, no, we shouldn't do this without a major, but as these frames aren't inApp in most cases they shouldn't impact grouping. @kahest what do you think?

philipphofmann avatar May 07 '24 11:05 philipphofmann

I'm wondering why we removed them in the first place. In general I'm ok with doing this in 8.2.0 if we are sufficiently confident that it doesn't affect grouping, especially since v8 is still very new

kahest avatar May 08 '24 10:05 kahest

Just traced back the change at it has been there since 2020. I'll check how it affects grouping

buenaflor avatar May 08 '24 11:05 buenaflor

inApp in most cases they shouldn't impact grouping

This seems to be the case here as well, I tried it out and it still is grouped with the same error without the sentry frame. So I think we're good to go in removing it without a major

Example: https://sentry-sdks.sentry.io/issues/4722238716/events/d70d73150b2a401e9b56755f968cc1de/?project=5428562&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=next-event&statsPeriod=1h&stream_index=0

buenaflor avatar May 13 '24 10:05 buenaflor

Sentry frames are now included in dart stacktraces as of 8.2.0

buenaflor avatar May 14 '24 12:05 buenaflor

I'm going to use the same rules for system frames that we use for grouping https://github.com/getsentry/sentry/blob/c4c4c9f4e8de9662c6fcb6ea123b8ab4cd34d133/src/sentry/grouping/enhancer/enhancement-configs/newstyle%402023-01-11.txt#L83-L85

philipphofmann avatar May 16 '24 08:05 philipphofmann

We can't make it work for Flutter Browser because the stacktrace paths don't include enough information to reliably detect where frames come from, but I think that's acceptable.

{
    "function": "<fn>",
    "filename": "main.dart",
    "abs_path": "http://localhost:53617/main.dart",
},
{
    "function": "setTag",
    "filename": "sentry_tracer.dart",
    "abs_path": "http://localhost:53617/sentry_tracer.dart",
},
{
    "function": "_get]",
    "filename": "js_array.dart",
    "abs_path": "http://localhost:53617/js_array.dart",
},
{
    "function": "throw_",
    "filename": "errors.dart",
    "abs_path": "http://localhost:53617/errors.dart",
}

philipphofmann avatar May 21 '24 09:05 philipphofmann

We're sampling at 100% now https://github.com/getsentry/sentry-options-automator/pull/1518. We can close this.

philipphofmann avatar Jun 04 '24 07:06 philipphofmann