Skip to content

Commit

Permalink
ref: Add getCurrentStackTrace (#2072)
Browse files Browse the repository at this point in the history
Add the wrapper method getCurrentStackTrace so the SDK crash detection
can ignore it.
  • Loading branch information
philipphofmann authored May 28, 2024
1 parent b8562d0 commit be173fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'utils/stacktrace_utils.dart';

import 'recursive_exception_cause_extractor.dart';
import 'protocol.dart';
import 'sentry_options.dart';
Expand Down Expand Up @@ -40,7 +42,7 @@ class SentryExceptionFactory {
if (_options.attachStacktrace) {
if (stackTrace == null || stackTrace == StackTrace.empty) {
snapshot = true;
stackTrace = StackTrace.current;
stackTrace = getCurrentStackTrace();
}
}

Expand Down
10 changes: 10 additions & 0 deletions dart/lib/src/utils/stacktrace_utils.dart
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit be173fa

Please sign in to comment.