From 80c7eeb5c6342ec0d5c2e6eb7d42f89a92f8350b Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 4 Sep 2025 21:08:20 +0200 Subject: [PATCH 1/7] Update --- packages/flutter/ffi-native.yaml | 1 + .../flutter/lib/src/native/c/binding.dart | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/packages/flutter/ffi-native.yaml b/packages/flutter/ffi-native.yaml index cdb28b223b..9527530c3b 100644 --- a/packages/flutter/ffi-native.yaml +++ b/packages/flutter/ffi-native.yaml @@ -19,6 +19,7 @@ functions: - sentry_options_set_dist - sentry_options_set_max_breadcrumbs - sentry_options_set_handler_path + - sentry_options_set_database_path - sentry_set_user - sentry_remove_user - sentry_add_breadcrumb diff --git a/packages/flutter/lib/src/native/c/binding.dart b/packages/flutter/lib/src/native/c/binding.dart index a2b62705ce..9b10e2ff76 100644 --- a/packages/flutter/lib/src/native/c/binding.dart +++ b/packages/flutter/lib/src/native/c/binding.dart @@ -640,6 +640,52 @@ class SentryNative { void Function( ffi.Pointer, ffi.Pointer)>(); + /// Sets the path to the Sentry Database Directory. + /// + /// Sentry will use this path to persist user consent, sessions, and other + /// artifacts in case of a crash. This will also be used by the crashpad backend + /// if it is configured. + /// + /// The directory is used for "cached" data, which needs to persist across + /// application restarts to ensure proper flagging of release-health sessions, + /// but might otherwise be safely purged regularly. + /// + /// It is roughly equivalent to the type of `AppData/Local` on Windows and + /// `XDG_CACHE_HOME` on Linux, and equivalent runtime directories on other + /// platforms. + /// + /// It is recommended that users set an explicit absolute path, depending + /// on their apps runtime directory. The path will be created if it does not + /// exist, and will be resolved to an absolute path inside of `sentry_init`. The + /// directory should not be shared with other application data/configuration, as + /// sentry-native will enumerate and possibly delete files in that directory. An + /// example might be `$XDG_CACHE_HOME/your-app/sentry` + /// + /// If no explicit path it set, sentry-native will default to `.sentry-native` in + /// the current working directory, with no specific platform-specific handling. + /// + /// `path` is assumed to be in platform-specific filesystem path encoding. + /// API Users on windows are encouraged to use + /// `sentry_options_set_database_pathw` instead. + void options_set_database_path( + ffi.Pointer opts, + ffi.Pointer path, + ) { + return _options_set_database_path( + opts, + path, + ); + } + + late final _options_set_database_pathPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, + ffi.Pointer)>>('sentry_options_set_database_path'); + late final _options_set_database_path = + _options_set_database_pathPtr.asFunction< + void Function( + ffi.Pointer, ffi.Pointer)>(); + /// Initializes the Sentry SDK with the specified options. /// /// This takes ownership of the options. After the options have been set From b314f0ca4ea57371857a952c48c0984f7159e5cc Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 4 Sep 2025 21:34:21 +0200 Subject: [PATCH 2/7] Update --- .../lib/src/native/c/sentry_native.dart | 4 ++++ .../sentry_native/sentry_native_test_ffi.dart | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/flutter/lib/src/native/c/sentry_native.dart b/packages/flutter/lib/src/native/c/sentry_native.dart index d1f99129bc..793d103a23 100644 --- a/packages/flutter/lib/src/native/c/sentry_native.dart +++ b/packages/flutter/lib/src/native/c/sentry_native.dart @@ -69,6 +69,10 @@ class SentryNative with SentryNativeSafeInvoker implements SentryNativeBinding { cOptions, options.enableAutoSessionTracking ? 1 : 0); native.options_set_dist(cOptions, c.str(options.dist)); native.options_set_max_breadcrumbs(cOptions, options.maxBreadcrumbs); + if (options.nativeDatabasePath != null) { + native.options_set_database_path( + cOptions, c.str(options.nativeDatabasePath)); + } if (options.proxy != null) { // sentry-native expects a single string and it doesn't support different types or authentication options.log(SentryLevel.warning, diff --git a/packages/flutter/test/sentry_native/sentry_native_test_ffi.dart b/packages/flutter/test/sentry_native/sentry_native_test_ffi.dart index c5d803c928..1954e7db13 100644 --- a/packages/flutter/test/sentry_native/sentry_native_test_ffi.dart +++ b/packages/flutter/test/sentry_native/sentry_native_test_ffi.dart @@ -139,6 +139,28 @@ void main() { await sut.init(MockHub()); }); + test('init creates native database path directory when configured', + () async { + final dbDir = Directory( + '${helper.nativeTestRoot}/db-${backend.actualValue.name}'); + if (dbDir.existsSync()) { + dbDir.deleteSync(recursive: true); + } + + options.nativeDatabasePath = dbDir.path; + + addTearDown(() { + if (dbDir.existsSync()) { + dbDir.deleteSync(recursive: true); + } + }); + addTearDown(sut.close); + + await sut.init(MockHub()); + + expect(dbDir.existsSync(), isTrue); + }); + test('app start', () { expect(sut.fetchNativeAppStart(), null); }); From b594a377463d4ceb9ee47fccc68cc3772d299369 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 4 Sep 2025 21:41:03 +0200 Subject: [PATCH 3/7] Update --- packages/dart/lib/src/sentry_options.dart | 70 ++++++++++--------- .../lib/src/sentry_flutter_options.dart | 16 +++++ 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/packages/dart/lib/src/sentry_options.dart b/packages/dart/lib/src/sentry_options.dart index 32090e0bc1..0e25979c95 100644 --- a/packages/dart/lib/src/sentry_options.dart +++ b/packages/dart/lib/src/sentry_options.dart @@ -349,8 +349,10 @@ class SentryOptions { double? get tracesSampleRate => _tracesSampleRate; set tracesSampleRate(double? tracesSampleRate) { - assert(tracesSampleRate == null || - (tracesSampleRate >= 0 && tracesSampleRate <= 1)); + assert( + tracesSampleRate == null || + (tracesSampleRate >= 0 && tracesSampleRate <= 1), + ); _tracesSampleRate = tracesSampleRate; } @@ -482,15 +484,20 @@ class SentryOptions { List.unmodifiable(_exceptionTypeIdentifiers); void addExceptionTypeIdentifierByIndex( - int index, ExceptionTypeIdentifier exceptionTypeIdentifier) { + int index, + ExceptionTypeIdentifier exceptionTypeIdentifier, + ) { _exceptionTypeIdentifiers.insert( - index, exceptionTypeIdentifier.withCache()); + index, + exceptionTypeIdentifier.withCache(), + ); } /// Adds an exception type identifier to the beginning of the list. /// This ensures it is processed first and takes precedence over existing identifiers. void prependExceptionTypeIdentifier( - ExceptionTypeIdentifier exceptionTypeIdentifier) { + ExceptionTypeIdentifier exceptionTypeIdentifier, + ) { addExceptionTypeIdentifierByIndex(0, exceptionTypeIdentifier); } @@ -606,8 +613,9 @@ class SentryOptions { late SentryExceptionFactory exceptionFactory = SentryExceptionFactory(this); @internal - late SentryStackTraceFactory stackTraceFactory = - SentryStackTraceFactory(this); + late SentryStackTraceFactory stackTraceFactory = SentryStackTraceFactory( + this, + ); @visibleForTesting void debugLog( @@ -639,31 +647,26 @@ void noOpLog( /// This function is called with an SDK specific event object and can return a modified event /// object or nothing to skip reporting the event -typedef BeforeSendCallback = FutureOr Function( - SentryEvent event, - Hint hint, -); +typedef BeforeSendCallback = + FutureOr Function(SentryEvent event, Hint hint); /// This function is called with an SDK specific transaction object and can return a modified transaction /// object or nothing to skip reporting the transaction -typedef BeforeSendTransactionCallback = FutureOr Function( - SentryTransaction transaction, - Hint hint, -); +typedef BeforeSendTransactionCallback = + FutureOr Function( + SentryTransaction transaction, + Hint hint, + ); /// This function is called with an SDK specific breadcrumb object before the breadcrumb is added /// to the scope. When nothing is returned from the function, the breadcrumb is dropped -typedef BeforeBreadcrumbCallback = Breadcrumb? Function( - Breadcrumb? breadcrumb, - Hint hint, -); +typedef BeforeBreadcrumbCallback = + Breadcrumb? Function(Breadcrumb? breadcrumb, Hint hint); /// This function is called right before a metric is about to be emitted. /// Can return true to emit the metric, or false to drop it. -typedef BeforeMetricCallback = bool Function( - String key, { - Map? tags, -}); +typedef BeforeMetricCallback = + bool Function(String key, {Map? tags}); /// This function is called right before a log is about to be sent. /// Can return a modified log or null to drop the log. @@ -673,13 +676,14 @@ typedef BeforeSendLogCallback = FutureOr Function(SentryLog log); typedef ClockProvider = DateTime Function(); /// Logger callback to log useful debugging information if debug is enabled -typedef SdkLogCallback = void Function( - SentryLevel level, - String message, { - String? logger, - Object? exception, - StackTrace? stackTrace, -}); - -typedef TracesSamplerCallback = double? Function( - SentrySamplingContext samplingContext); +typedef SdkLogCallback = + void Function( + SentryLevel level, + String message, { + String? logger, + Object? exception, + StackTrace? stackTrace, + }); + +typedef TracesSamplerCallback = + double? Function(SentrySamplingContext samplingContext); diff --git a/packages/flutter/lib/src/sentry_flutter_options.dart b/packages/flutter/lib/src/sentry_flutter_options.dart index b25ecdfd56..aea523a6cf 100644 --- a/packages/flutter/lib/src/sentry_flutter_options.dart +++ b/packages/flutter/lib/src/sentry_flutter_options.dart @@ -291,6 +291,22 @@ class SentryFlutterOptions extends SentryOptions { /// Screen content masking is enabled by default. final privacy = SentryPrivacyOptions(); + /// Sets the path to the Sentry Database Directory used in the Sentry Native SDK. + /// + /// **Default behavior**: When `null` (the default), the path defaults to + /// `.sentry-native` in the current working directory (CWD). + /// + /// **Important**: While using the default is convenient for development, we + /// strongly recommend providing an explicit database path for production + /// deployments to ensure predictable behavior. + /// + /// This option is only used on platforms that utilize the Sentry Native SDK directly, + /// specifically Desktop Linux and Windows. + /// + /// For more information, see: + /// https://docs.sentry.io/platforms/native/configuration/options/#database-path + String? nativeDatabasePath; + /// By using this, you are disabling native [Breadcrumb] tracking and instead /// you are just tracking [Breadcrumb]s which result from events available /// in the current Flutter environment. From d693d6bc592afa7abfb92743a85d64d3c968ee72 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 4 Sep 2025 21:47:30 +0200 Subject: [PATCH 4/7] Update --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32ea957b22..931d9fcc2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Add `options_set_native_database_path` option to set the database path for Sentry Native ([#3236](https://github.com/getsentry/sentry-dart/pull/3236)) + ## 9.7.0-beta.3 ### Fixes From ec8eb758d3c35413d2285c18a7297f97a13e70ab Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 4 Sep 2025 21:48:18 +0200 Subject: [PATCH 5/7] Update --- packages/dart/lib/src/sentry_options.dart | 70 +++++++++++------------ 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/packages/dart/lib/src/sentry_options.dart b/packages/dart/lib/src/sentry_options.dart index 0e25979c95..32090e0bc1 100644 --- a/packages/dart/lib/src/sentry_options.dart +++ b/packages/dart/lib/src/sentry_options.dart @@ -349,10 +349,8 @@ class SentryOptions { double? get tracesSampleRate => _tracesSampleRate; set tracesSampleRate(double? tracesSampleRate) { - assert( - tracesSampleRate == null || - (tracesSampleRate >= 0 && tracesSampleRate <= 1), - ); + assert(tracesSampleRate == null || + (tracesSampleRate >= 0 && tracesSampleRate <= 1)); _tracesSampleRate = tracesSampleRate; } @@ -484,20 +482,15 @@ class SentryOptions { List.unmodifiable(_exceptionTypeIdentifiers); void addExceptionTypeIdentifierByIndex( - int index, - ExceptionTypeIdentifier exceptionTypeIdentifier, - ) { + int index, ExceptionTypeIdentifier exceptionTypeIdentifier) { _exceptionTypeIdentifiers.insert( - index, - exceptionTypeIdentifier.withCache(), - ); + index, exceptionTypeIdentifier.withCache()); } /// Adds an exception type identifier to the beginning of the list. /// This ensures it is processed first and takes precedence over existing identifiers. void prependExceptionTypeIdentifier( - ExceptionTypeIdentifier exceptionTypeIdentifier, - ) { + ExceptionTypeIdentifier exceptionTypeIdentifier) { addExceptionTypeIdentifierByIndex(0, exceptionTypeIdentifier); } @@ -613,9 +606,8 @@ class SentryOptions { late SentryExceptionFactory exceptionFactory = SentryExceptionFactory(this); @internal - late SentryStackTraceFactory stackTraceFactory = SentryStackTraceFactory( - this, - ); + late SentryStackTraceFactory stackTraceFactory = + SentryStackTraceFactory(this); @visibleForTesting void debugLog( @@ -647,26 +639,31 @@ void noOpLog( /// This function is called with an SDK specific event object and can return a modified event /// object or nothing to skip reporting the event -typedef BeforeSendCallback = - FutureOr Function(SentryEvent event, Hint hint); +typedef BeforeSendCallback = FutureOr Function( + SentryEvent event, + Hint hint, +); /// This function is called with an SDK specific transaction object and can return a modified transaction /// object or nothing to skip reporting the transaction -typedef BeforeSendTransactionCallback = - FutureOr Function( - SentryTransaction transaction, - Hint hint, - ); +typedef BeforeSendTransactionCallback = FutureOr Function( + SentryTransaction transaction, + Hint hint, +); /// This function is called with an SDK specific breadcrumb object before the breadcrumb is added /// to the scope. When nothing is returned from the function, the breadcrumb is dropped -typedef BeforeBreadcrumbCallback = - Breadcrumb? Function(Breadcrumb? breadcrumb, Hint hint); +typedef BeforeBreadcrumbCallback = Breadcrumb? Function( + Breadcrumb? breadcrumb, + Hint hint, +); /// This function is called right before a metric is about to be emitted. /// Can return true to emit the metric, or false to drop it. -typedef BeforeMetricCallback = - bool Function(String key, {Map? tags}); +typedef BeforeMetricCallback = bool Function( + String key, { + Map? tags, +}); /// This function is called right before a log is about to be sent. /// Can return a modified log or null to drop the log. @@ -676,14 +673,13 @@ typedef BeforeSendLogCallback = FutureOr Function(SentryLog log); typedef ClockProvider = DateTime Function(); /// Logger callback to log useful debugging information if debug is enabled -typedef SdkLogCallback = - void Function( - SentryLevel level, - String message, { - String? logger, - Object? exception, - StackTrace? stackTrace, - }); - -typedef TracesSamplerCallback = - double? Function(SentrySamplingContext samplingContext); +typedef SdkLogCallback = void Function( + SentryLevel level, + String message, { + String? logger, + Object? exception, + StackTrace? stackTrace, +}); + +typedef TracesSamplerCallback = double? Function( + SentrySamplingContext samplingContext); From 32ae30ed965ad95218ea245d99987334e5fd4d72 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Fri, 5 Sep 2025 16:47:50 +0200 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 931d9fcc2b..291f37989a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Features -- Add `options_set_native_database_path` option to set the database path for Sentry Native ([#3236](https://github.com/getsentry/sentry-dart/pull/3236)) +- Add `nativeDatabasePath` option to `SentryFlutterOptions` to set the database path for Sentry Native ([#3236](https://github.com/getsentry/sentry-dart/pull/3236)) ## 9.7.0-beta.3 From 08cc418c52f957ddad0258c011ec155ea9308b3b Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Fri, 5 Sep 2025 16:49:29 +0200 Subject: [PATCH 7/7] Update sentry_flutter_options.dart --- .../lib/src/sentry_flutter_options.dart | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/flutter/lib/src/sentry_flutter_options.dart b/packages/flutter/lib/src/sentry_flutter_options.dart index aea523a6cf..0de7aebfe6 100644 --- a/packages/flutter/lib/src/sentry_flutter_options.dart +++ b/packages/flutter/lib/src/sentry_flutter_options.dart @@ -291,19 +291,27 @@ class SentryFlutterOptions extends SentryOptions { /// Screen content masking is enabled by default. final privacy = SentryPrivacyOptions(); - /// Sets the path to the Sentry Database Directory used in the Sentry Native SDK. + /// Specifies the file system path to the Sentry database directory + /// used by the Sentry Native SDK. /// - /// **Default behavior**: When `null` (the default), the path defaults to + /// ### Default + /// If `null` (the default), the database directory is created at /// `.sentry-native` in the current working directory (CWD). /// - /// **Important**: While using the default is convenient for development, we - /// strongly recommend providing an explicit database path for production - /// deployments to ensure predictable behavior. + /// ### Recommendation + /// While relying on the default path may be sufficient during development, + /// **it is strongly recommended** to provide an explicit path in production + /// environments. Doing so ensures consistent and predictable behavior across + /// deployments. /// - /// This option is only used on platforms that utilize the Sentry Native SDK directly, - /// specifically Desktop Linux and Windows. + /// ### Platform Support + /// This option only applies to platforms that integrate the Sentry Native SDK + /// directly: + /// - **Linux (Desktop)** + /// - **Windows (Desktop)** /// - /// For more information, see: + /// ### References + /// For additional details, see: /// https://docs.sentry.io/platforms/native/configuration/options/#database-path String? nativeDatabasePath;