From 4f6634c800dfa84931d909123efa28c16b181109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Andra=C5=A1ec?= Date: Wed, 22 Jan 2025 17:19:21 +0100 Subject: [PATCH] Enable `options.debug` when in debug mode (#2597) --- CHANGELOG.md | 5 ++++ dart/lib/src/sentry.dart | 8 ++++++ dart/lib/src/sentry_options.dart | 2 +- dart/test/sentry_test.dart | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a8785722..97d22352a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) @@ -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)) diff --git a/dart/lib/src/sentry.dart b/dart/lib/src/sentry.dart index 91c511ebf..7b62938c9 100644 --- a/dart/lib/src/sentry.dart +++ b/dart/lib/src/sentry.dart @@ -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()); } diff --git a/dart/lib/src/sentry_options.dart b/dart/lib/src/sentry_options.dart index 90df95261..6a3d9f371 100644 --- a/dart/lib/src/sentry_options.dart +++ b/dart/lib/src/sentry_options.dart @@ -154,7 +154,7 @@ class SentryOptions { List 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) { diff --git a/dart/test/sentry_test.dart b/dart/test/sentry_test.dart index e0813b9ee..ab510095b 100644 --- a/dart/test/sentry_test.dart +++ b/dart/test/sentry_test.dart @@ -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'; @@ -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',