Skip to content

Crash: stacktrace_utils.dart in getCurrentStackTrace within sentry #2146

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
flodaniel opened this issue Jul 5, 2024 · 16 comments
Closed

Crash: stacktrace_utils.dart in getCurrentStackTrace within sentry #2146

flodaniel opened this issue Jul 5, 2024 · 16 comments

Comments

@flodaniel
Copy link

Platform

Flutter Mobile

Obfuscation

Enabled

Debug Info

Enabled

Doctor

[✓] Flutter (Channel stable, 3.22.1, on macOS 14.4.1 23E224 darwin-arm64, locale en-AT)
• Flutter version 3.22.1 on channel stable at /Users/floriandaniel/fvm/versions/3.22.1
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision a14f74ff3a (6 weeks ago), 2024-05-22 11:08:21 -0500
• Engine revision 55eae6864b
• Dart version 3.4.1
• DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/floriandaniel/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/floriandaniel/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15F31d
• CocoaPods version 1.15.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Community Edition (version 2023.2.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.90.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.90.0

Version

8.3.0

Steps to Reproduce

  1. Trying to report a PhoenixException from the phoenix_socket:0.6.4 package (so far only on iOS)
  2. Reported exception in sentry shows that it failed to get the stacktrace

Expected Result

I expect a proper stacktrace. It also looks like the beforeSend is then not called for the PhoenixException as I am actually trying to ignore those directly on the device.

Actual Result

Actual StackTrace:

PhoenixException: PhoenixException: socket closed
  File "stacktrace_utils.dart", line 10, in getCurrentStackTrace
  File "sentry_exception_factory.dart", line 45, in SentryExceptionFactory.getSentryException
  File "sentry_client.dart", line 201, in SentryClient._prepareEvent
  File "sentry_client.dart", line 95, in SentryClient.captureEvent
  File "hub.dart", line 173, in Hub.captureException
  File "<asynchronous suspension>"
  File "sentry_service.dart", line 69, in SentryService.recordError

Are you willing to submit a PR?

None

@krystofwoldrich
Copy link
Member

Hi @flodaniel,
thank you for the message,
the stack trace you are seeing is attached by the SDK in case the original exception, in this case PhoenixException does not contain its own stack trace.

Could you share you current implementation of the beforeSend and how do you capture the PhoenixException, does it contain stack trace?

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Jul 5, 2024
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 5, 2024
@getsantry getsantry bot moved this from Waiting for: Product Owner to Waiting for: Community in GitHub Issues with 👀 3 Jul 5, 2024
@krystofwoldrich krystofwoldrich moved this from Needs Discussion to Needs More Information in [DEPRECATED] Mobile SDKs Jul 5, 2024
@flodaniel
Copy link
Author

Thank you for the reply. I did not know that!
This is my shortened beforeSend method:

  static FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) {
    final throwable = event.throwable;
    /// here are actually much more checks for all kind of other exceptions

    /// used by knock as a socket connection
    if (throwable is PhoenixException) {
      return null;
    }

    return event;
  }

This is how I set up sentry. I am not using the appRunner due to #1943 (comment)

void main() async {
  await runZonedGuarded(() async {
    await SentryFlutter.init(
      (options) {
        options
          ..dsn = 'DNS'
          ..tracesSampleRate = 0.5
          ..profilesSampleRate = Endpoint.current.isProduction() ? 0.5 : 0
          ..environment = Endpoint.current.name
          ..beforeSend = SentryService.beforeSend;
      },
    );

    return runApp(
      AppInjector(),
    );
  }, (error, stackTrace) async {
    unawaited(SentryService().recordError(error, stackTrace: stackTrace));
  });
}

And this is my recordError method:

  Future<void> recordError(
    dynamic exception, {
    StackTrace? stackTrace,
    String? stringHint,
    Map<String, dynamic>? mapHint,
  }) async {

    await Sentry.captureException(
      exception,
      stackTrace: stackTrace,
      withScope: (scope) {
        if (stringHint != null) {
          scope.setContexts('Extra Data (string)', stringHint);
        }
        if (mapHint != null) {
          scope.setContexts('Extra Data (map)', mapHint);
        }
      },
    );
  }

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 5, 2024
@buenaflor
Copy link
Contributor

Hi, which platform are you using

@flodaniel
Copy link
Author

Hi, which platform are you using

The described behavior is on iOS

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 5, 2024
@buenaflor buenaflor moved this from Needs More Information to Needs Investigation in [DEPRECATED] Mobile SDKs Jul 8, 2024
@buenaflor
Copy link
Contributor

If we don't have a stacktrace supplied we call StackTrace.current internally that's why it looks like it crashed in the Sentry SDK

@flodaniel
Copy link
Author

Can this call be wrapped in a try-catch? No matter what the beforeSend hook should allow me to drop or modify events even if the stacktrace is not available.
As it is right now it looks like the beforeSend is no longer called due to the crash.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 15, 2024
@buenaflor
Copy link
Contributor

buenaflor commented Jul 15, 2024

@flodaniel the stacktrace is misleading. the error is not crashing in stacktrace utils

see this PR on fixing this issue: #2152

Can this call be wrapped in a try-catch

that won't do anything, the error is PhoenixException: PhoenixException: socket closed and not the sentry sdk, we just have to provide the proper stacktrace

@flodaniel
Copy link
Author

Thanks for explaining.

That also means me dropping the PhoenixException in my beforeSend should already work? As shared in this comment above (#2146 (comment)) I am trying to ignore it, but I still see the PhoenixException in my sentry instance and I don't understand how a better stacktrace would change that.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 15, 2024
@buenaflor
Copy link
Contributor

Do you have a sure way to reproduce the PhoenixException?

you can try this

final exception = event.exceptions
    ?.firstWhereOrNull((element) => element.type == 'PhoenixException');
if (exception != null) {
  return null;
}

@flodaniel
Copy link
Author

Do you have a sure way to reproduce the PhoenixException?

Unfortunately no :( I will wait on the PR you linked which might help me to reproduce it somehow.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 15, 2024
@buenaflor
Copy link
Contributor

buenaflor commented Jul 15, 2024

could you share a screenshot of the event page? or you can send the event link to me to [email protected] if you don't want to share anything here.

@buenaflor buenaflor moved this from Needs Investigation to Needs More Information in [DEPRECATED] Mobile SDKs Jul 18, 2024
@buenaflor buenaflor moved this to Waiting for: Community in GitHub Issues with 👀 3 Jul 18, 2024
@buenaflor
Copy link
Contributor

hey we've release 8.5.0 which includes a fix to improve the stacktrace you mentioned

@buenaflor
Copy link
Contributor

Closing this now, please feel free to reopen if you still have any issues

@github-project-automation github-project-automation bot moved this from Needs More Information to Done in [DEPRECATED] Mobile SDKs Jul 25, 2024
@richanshah
Copy link

PlatformException: PlatformException(-1102, You do not have permission to access the requested resource., {index: 9}, null)
#0 getCurrentStackTrace (package:sentry/src/utils/stacktrace_utils.dart:10)
#1 SentryExceptionFactory.getSentryException (package:sentry/src/sentry_exception_factory.dart:44)
#2 SentryClient._prepareEvent (package:sentry/src/sentry_client.dart:235)
#3 SentryClient.captureEvent (package:sentry/src/sentry_client.dart:119)
#4 Hub.captureException (package:sentry/src/hub.dart:173)

PlatformException: PlatformException(-1102, You do not have permission to access the requested resource., {index: 9}, null)
#0 getCurrentStackTrace (package:sentry/src/utils/stacktrace_utils.dart:10)
#1 SentryExceptionFactory.getSentryException (package:sentry/src/sentry_exception_factory.dart:44)
#2 SentryClient._prepareEvent (package:sentry/src/sentry_client.dart:235)
#3 SentryClient.captureEvent (package:sentry/src/sentry_client.dart:119)
#4 Hub.captureException (package:sentry/src/hub.dart:173)

@buenaflor
Copy link
Contributor

buenaflor commented Nov 19, 2024

@richanshah please read this comment to see why this behaves in this way. We will remove the Sentry specific stack frames since this is misleading

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

No branches or pull requests

4 participants