Skip to content

Commit be173fa

Browse files
ref: Add getCurrentStackTrace (#2072)
Add the wrapper method getCurrentStackTrace so the SDK crash detection can ignore it.
1 parent b8562d0 commit be173fa

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

dart/lib/src/sentry_client.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22
import 'dart:math';
33
import 'package:meta/meta.dart';
4+
import 'utils/stacktrace_utils.dart';
45
import 'metrics/metric.dart';
56
import 'metrics/metrics_aggregator.dart';
67
import 'sentry_baggage.dart';
@@ -235,7 +236,7 @@ class SentryClient {
235236
// therefore add it to the threads.
236237
// https://develop.sentry.dev/sdk/event-payloads/stacktrace/
237238
if (stackTrace != null || _options.attachStacktrace) {
238-
stackTrace ??= StackTrace.current;
239+
stackTrace ??= getCurrentStackTrace();
239240
final frames = _stackTraceFactory.getStackFrames(stackTrace);
240241

241242
if (frames.isNotEmpty) {

dart/lib/src/sentry_exception_factory.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'utils/stacktrace_utils.dart';
2+
13
import 'recursive_exception_cause_extractor.dart';
24
import 'protocol.dart';
35
import 'sentry_options.dart';
@@ -40,7 +42,7 @@ class SentryExceptionFactory {
4042
if (_options.attachStacktrace) {
4143
if (stackTrace == null || stackTrace == StackTrace.empty) {
4244
snapshot = true;
43-
stackTrace = StackTrace.current;
45+
stackTrace = getCurrentStackTrace();
4446
}
4547
}
4648

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:meta/meta.dart';
2+
3+
// A wrapper function around StackTrace.current so we can ignore it in the SDK
4+
// crash detection. Otherwise, the SDK crash detection would have to ignore the
5+
// method calling StackTrace.current, and it can't detect crashes in that
6+
// method.
7+
// You can read about the SDK crash detection here:
8+
// https://github.com/getsentry/sentry/blob/master/src/sentry/utils/sdk_crashes/README.rst
9+
@internal
10+
StackTrace getCurrentStackTrace() => StackTrace.current;

0 commit comments

Comments
 (0)