diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index 59610993ad..a1f20ded61 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:math'; import 'package:meta/meta.dart'; +import 'utils/stacktrace_utils.dart'; import 'metrics/metric.dart'; import 'metrics/metrics_aggregator.dart'; import 'sentry_baggage.dart'; @@ -235,7 +236,7 @@ class SentryClient { // therefore add it to the threads. // https://develop.sentry.dev/sdk/event-payloads/stacktrace/ if (stackTrace != null || _options.attachStacktrace) { - stackTrace ??= StackTrace.current; + stackTrace ??= getCurrentStackTrace(); final frames = _stackTraceFactory.getStackFrames(stackTrace); if (frames.isNotEmpty) { diff --git a/dart/lib/src/sentry_exception_factory.dart b/dart/lib/src/sentry_exception_factory.dart index 0e4eb25cc3..a8e1a80498 100644 --- a/dart/lib/src/sentry_exception_factory.dart +++ b/dart/lib/src/sentry_exception_factory.dart @@ -1,3 +1,5 @@ +import 'utils/stacktrace_utils.dart'; + import 'recursive_exception_cause_extractor.dart'; import 'protocol.dart'; import 'sentry_options.dart'; @@ -40,7 +42,7 @@ class SentryExceptionFactory { if (_options.attachStacktrace) { if (stackTrace == null || stackTrace == StackTrace.empty) { snapshot = true; - stackTrace = StackTrace.current; + stackTrace = getCurrentStackTrace(); } } diff --git a/dart/lib/src/utils/stacktrace_utils.dart b/dart/lib/src/utils/stacktrace_utils.dart new file mode 100644 index 0000000000..acc1cccf44 --- /dev/null +++ b/dart/lib/src/utils/stacktrace_utils.dart @@ -0,0 +1,10 @@ +import 'package:meta/meta.dart'; + +// A wrapper function around StackTrace.current so we can ignore it in the SDK +// crash detection. Otherwise, the SDK crash detection would have to ignore the +// method calling StackTrace.current, and it can't detect crashes in that +// method. +// You can read about the SDK crash detection here: +// https://github.com/getsentry/sentry/blob/master/src/sentry/utils/sdk_crashes/README.rst +@internal +StackTrace getCurrentStackTrace() => StackTrace.current;