Skip to content

SDK Crash Detection: Enable Dart/Flutter #66762

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

Closed
kahest opened this issue Mar 12, 2024 · 12 comments
Closed

SDK Crash Detection: Enable Dart/Flutter #66762

kahest opened this issue Mar 12, 2024 · 12 comments
Assignees
Labels
Platform: Dart Scope: Backend Automatically applied to PRs that change backend components

Comments

@kahest
Copy link
Member

kahest commented Mar 12, 2024

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
- [ ] https://github.com/getsentry/sentry/pull/71545
- [ ] https://github.com/getsentry/sentry-dart/pull/2072
- [ ] https://github.com/getsentry/sentry-options-automator/pull/1518
@kahest kahest added the Scope: Backend Automatically applied to PRs that change backend components label Mar 12, 2024
@github-project-automation github-project-automation bot moved this to Needs Discussion in [DEPRECATED] Mobile SDKs Apr 15, 2024
@kahest kahest moved this from Needs Discussion to Backlog in [DEPRECATED] Mobile SDKs Apr 15, 2024
@philipphofmann philipphofmann self-assigned this May 6, 2024
@philipphofmann philipphofmann moved this from Backlog to In Progress in [DEPRECATED] Mobile SDKs May 6, 2024
@philipphofmann
Copy link
Member

philipphofmann commented May 6, 2024

@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.

java_options = _get_options(sdk_name=SdkName.Java, has_organization_allowlist=True)
if java_options:
java_config = SDKCrashDetectionConfig(
sdk_name=SdkName.Java,
project_id=java_options["project_id"],
sample_rate=java_options["sample_rate"],
organization_allowlist=java_options["organization_allowlist"],
sdk_names=[
"sentry.java.android",
"sentry.java.android.capacitor",
"sentry.java.android.dotnet",
"sentry.java.android.flutter",
"sentry.java.android.kmp",
"sentry.java.android.react-native",
"sentry.java.android.timber",
"sentry.java.android.unity",
"sentry.java.android.unreal",
"sentry.java.jul",
"sentry.java.kmp",
"sentry.java.log4j2",
"sentry.java.logback",
"sentry.java.opentelemetry.agent",
"sentry.java.spring",
"sentry.java.spring-boot",
"sentry.java.spring-boot.jakarta",
"sentry.java.spring.jakarta",
],
# The sentry-java SDK sends SDK frames for uncaught exceptions since 7.0.0, which is required for detecting SDK crashes.
# 7.0.0 was released in Nov 2023, see https://github.com/getsentry/sentry-java/releases/tag/7.0.0
min_sdk_version="7.0.0",
system_library_path_patterns={
r"java.**",
r"javax.**",
r"android.**",
r"androidx.**",
r"com.android.internal.**",
r"kotlin.**",
r"dalvik.**",
},
sdk_frame_config=SDKFrameConfig(
function_patterns=set(),
path_patterns={
r"io.sentry.**",
},
path_replacer=KeepFieldPathReplacer(fields={"module", "filename"}),
),
sdk_crash_ignore_functions_matchers=set(),
)
configs.append(java_config)

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?

@buenaflor
Copy link
Contributor

buenaflor commented May 6, 2024

  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

@philipphofmann
Copy link
Member

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 (getsentry/sentry-java#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.

@buenaflor
Copy link
Contributor

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

@philipphofmann
Copy link
Member

@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?

@kahest
Copy link
Member Author

kahest commented May 8, 2024

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

@buenaflor
Copy link
Contributor

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

@buenaflor
Copy link
Contributor

buenaflor commented May 13, 2024

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
Copy link
Contributor

Sentry frames are now included in dart stacktraces as of 8.2.0

@philipphofmann
Copy link
Member

I'm going to use the same rules for system frames that we use for grouping

# Dart/Flutter stacktraces that are not in-app
family:javascript stack.abs_path:org-dartlang-sdk:///** -app -group
family:javascript module:**/packages/flutter/** -app

@philipphofmann
Copy link
Member

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
Copy link
Member

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

@github-project-automation github-project-automation bot moved this from In Progress to Done in [DEPRECATED] Mobile SDKs Jun 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Dart Scope: Backend Automatically applied to PRs that change backend components
Projects
Archived in project
Development

No branches or pull requests

3 participants