Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable options.debug when in debug mode #2597

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Add SentryReplayQuality setting (`options.experimental.replay.quality`) ([#2582](https://github.com/getsentry/sentry-dart/pull/2582))
- SPM Support ([#2280](https://github.com/getsentry/sentry-dart/pull/2280))

### Enhancements

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

### Fixes

- WASM compat for Drift ([#2580](https://github.com/getsentry/sentry-dart/pull/2580))
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