Skip to content

Commit

Permalink
Set snapshot to true (#2000)
Browse files Browse the repository at this point in the history
* set snapshot to true

* test

* test the inverse

* changelog

---------

Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com>
  • Loading branch information
ueman and buenaflor authored Apr 24, 2024
1 parent cfa25fc commit 47dd159
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Feature

- Set snapshot to `true` when Sentry attaches a stacktrace ([#2000](https://github.com/getsentry/sentry-dart/pull/2000))
- This may change grouping

### Fixes

- Timing metric aggregates metrics in the created span ([#1994](https://github.com/getsentry/sentry-dart/pull/1994))
Expand Down
3 changes: 1 addition & 2 deletions dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ class SentryExceptionFactory {
// hence we check again if stackTrace is null and if not, read the current stack trace
// but only if attachStacktrace is enabled
if (_options.attachStacktrace) {
// TODO: snapshot=true if stackTrace is null
// Requires a major breaking change because of grouping
if (stackTrace == null || stackTrace == StackTrace.empty) {
snapshot = true;
stackTrace = StackTrace.current;
}
}
Expand Down
21 changes: 20 additions & 1 deletion dart/test/sentry_exception_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ void main() {

expect(sentryException.value, isNull);
});

test(
'set snapshot to true when no stracktrace is present & attachStacktrace == true',
() {
final sentryException =
fixture.getSut(attachStacktrace: true).getSentryException(Object());

expect(sentryException.stackTrace!.snapshot, true);
});

test(
'set snapshot to false when no stracktrace is present & attachStacktrace == false',
() {
final sentryException =
fixture.getSut(attachStacktrace: false).getSentryException(Object());

expect(sentryException.stackTrace!.snapshot, true);
});
}

class CustomError extends Error {}
Expand Down Expand Up @@ -268,7 +286,8 @@ isolate_instructions: 7526344980, vm_instructions: 752633f000
class Fixture {
final options = SentryOptions(dsn: fakeDsn);

SentryExceptionFactory getSut() {
SentryExceptionFactory getSut({bool attachStacktrace = true}) {
options.attachStacktrace = true;
return SentryExceptionFactory(options);
}
}

0 comments on commit 47dd159

Please sign in to comment.