Skip to content

Commit

Permalink
Enable options.debug when in debug mode (#2597)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored Jan 22, 2025
1 parent 80734dc commit 4f6634c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Enable `options.debug` when in debug mode ([#2597](https://github.com/getsentry/sentry-dart/pull/2597))

### Fixes

- Fix image flickering when using `SentryAssetBundle` ([#2577](https://github.com/getsentry/sentry-dart/pull/2577))
Expand All @@ -21,6 +25,7 @@

### Enhancements

- Enable `options.debug` when in debug mode ([#2597](https://github.com/getsentry/sentry-dart/pull/2597))
- Print a warning if the rate limit was reached ([#2595](https://github.com/getsentry/sentry-dart/pull/2595))
- Add replay masking config to tags and report SDKs versions ([#2592](https://github.com/getsentry/sentry-dart/pull/2592))

Expand Down
8 changes: 8 additions & 0 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class Sentry {
options.addIntegrationByIndex(0, IsolateErrorIntegration());
}

if (options.platformChecker.isDebugMode()) {
options.debug = true;
options.logger(
SentryLevel.debug,
'Debug mode is enabled: Application is running in a debug environment.',
);
}

if (options.enableDartSymbolication) {
options.addIntegration(LoadDartDebugImagesIntegration());
}
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SentryOptions {
List<Integration> get integrations => List.unmodifiable(_integrations);

/// Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging
/// information if something goes wrong. Default is disabled.
/// information if something goes wrong. Default is enabled in debug mode, otherwise it is disabled.
bool get debug => _debug;

set debug(bool newValue) {
Expand Down
45 changes: 45 additions & 0 deletions dart/test/sentry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:test/test.dart';
import 'fake_platform_checker.dart';
import 'mocks.dart';
import 'mocks/mock_integration.dart';
import 'mocks/mock_platform_checker.dart';
import 'mocks/mock_sentry_client.dart';
import 'test_utils.dart';

Expand Down Expand Up @@ -360,6 +361,50 @@ void main() {
),
);
});

test('should set options.debug to true when in debug mode', () async {
final options = defaultTestOptions();
options.platformChecker = MockPlatformChecker(isDebug: true);

expect(options.debug, isFalse);
await Sentry.init(
options: options,
(options) {
options.dsn = fakeDsn;
},
);
expect(options.debug, isTrue);
});

test('should respect user options.debug when in debug mode', () async {
final options = defaultTestOptions();
options.platformChecker = MockPlatformChecker(isDebug: true);

expect(options.debug, isFalse);
await Sentry.init(
options: options,
(options) {
options.dsn = fakeDsn;
options.debug = false;
},
);
expect(options.debug, isFalse);
});

test('should leave options.debug unchanged when not in debug mode',
() async {
final options = defaultTestOptions();
options.platformChecker = MockPlatformChecker(isDebug: false);

expect(options.debug, isFalse);
await Sentry.init(
options: options,
(options) {
options.dsn = fakeDsn;
},
);
expect(options.debug, isFalse);
});
});

test('should complete when appRunner is not called in runZonedGuarded',
Expand Down

0 comments on commit 4f6634c

Please sign in to comment.