diff --git a/dart/lib/src/hub.dart b/dart/lib/src/hub.dart index a5b9ce6ce9..3e19cd7c00 100644 --- a/dart/lib/src/hub.dart +++ b/dart/lib/src/hub.dart @@ -81,13 +81,15 @@ class Hub { ); } else { final item = _peek(); - final scope = await _cloneAndRunWithScope(item.scope, withScope); + var scope = await _cloneAndRunWithScope(item.scope, withScope); try { if (_options.isTracingEnabled()) { event = _assignTraceContext(event); } + scope = await _applyOptionsBeforeCaptureWithScope(scope, event); + sentryId = await item.client.captureEvent( event, stackTrace: stackTrace, @@ -129,7 +131,7 @@ class Hub { ); } else { final item = _peek(); - final scope = await _cloneAndRunWithScope(item.scope, withScope); + var scope = await _cloneAndRunWithScope(item.scope, withScope); try { var event = SentryEvent( @@ -141,6 +143,8 @@ class Hub { event = _assignTraceContext(event); } + scope = await _applyOptionsBeforeCaptureWithScope(scope, event); + sentryId = await item.client.captureEvent( event, stackTrace: stackTrace, @@ -185,7 +189,8 @@ class Hub { ); } else { final item = _peek(); - final scope = await _cloneAndRunWithScope(item.scope, withScope); + var scope = await _cloneAndRunWithScope(item.scope, withScope); + scope = await _applyOptionsBeforeCaptureWithScope(scope, null); try { sentryId = await item.client.captureMessage( @@ -248,6 +253,15 @@ class Hub { return scope; } + Future _applyOptionsBeforeCaptureWithScope( + Scope scope, SentryEvent? event) { + return _cloneAndRunWithScope( + scope, + _options.beforeCaptureWithScope == null + ? null + : (scope) => _options.beforeCaptureWithScope!(scope, event)); + } + /// Adds a breacrumb to the current Scope Future addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async { if (!_isEnabled) { diff --git a/dart/lib/src/sentry_options.dart b/dart/lib/src/sentry_options.dart index 8bf6c06774..e0923f5f01 100644 --- a/dart/lib/src/sentry_options.dart +++ b/dart/lib/src/sentry_options.dart @@ -267,6 +267,9 @@ class SentryOptions { /// to be sent to Sentry. TracesSamplerCallback? tracesSampler; + /// callback before capturing exceptions or events + BeforeCaptureWithScopeCallback? beforeCaptureWithScope; + /// Send statistics to sentry when the client drops events. bool sendClientReports = true; @@ -376,6 +379,8 @@ typedef SentryLogger = void Function( typedef TracesSamplerCallback = double? Function( SentrySamplingContext samplingContext); +typedef BeforeCaptureWithScopeCallback = void Function(Scope, SentryEvent?); + /// A NoOp logger that does nothing void noOpLogger( SentryLevel level,