getsentry / sentry-dart

Sentry SDK for Dart and Flutter
https://sentry.io/for/flutter/
MIT License
747 stars 233 forks source link

beforeSend doesn't do anything #980

Closed tomtaila closed 2 years ago

tomtaila commented 2 years ago

Platform:

IDE:

split-debug-info and obfuscate (Flutter Android or iOS) or CanvasKit (Flutter Web):

Platform installed with:

Output of the command flutter doctor -v below:

 Flutter (Channel unknown, 3.0.1, on macOS 12.5 21G72 darwin-arm, locale en-US)
     • Flutter version 3.0.1 at /opt/homebrew/Caskroom/flutter/3.0.1/flutter
     • Upstream repository unknown
     • Framework revision fb57da5f94 (3 months ago), 2022-05-19 15:50:29 -0700
     • Engine revision caaafc5604
     • Dart version 2.17.1
     • DevTools version 2.12.2

 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
     • Android SDK at /Users/tanjiro/Library/Android/sdk
     • Platform android-33, build-tools 33.0.0
     • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
     • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
     • All Android licenses accepted.

 [✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
     • Xcode at /Applications/Xcode.app/Contents/Developer
     • CocoaPods version 1.11.3

 [✓] Chrome - develop for the web
     • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

 [✓] Android Studio (version 2021.2)
     • Android Studio at /Applications/Android Studio.app/Contents
     • Flutter plugin can be installed from:
       🔨 https://plugins.jetbrains.com/plugin/9212-flutter
     • Dart plugin can be installed from:
       🔨 https://plugins.jetbrains.com/plugin/6351-dart
     • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

 [✓] VS Code (version 1.70.0)
     • VS Code at /Applications/Visual Studio Code.app/Contents
     • Flutter extension version 3.46.0

 [✓] Connected device (3 available)
     • iPhone SE (3rd generation) (mobile) • D9EFAAFF-E94A-46EE-80FD-D9C496E7FC37 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
     • macOS (desktop)                     • macos                                • darwin-arm64   • macOS 12.5 21G72 darwin-arm
     • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 104.0.5112.79

 [✓] HTTP Host Availability
     • All required HTTP hosts are available

The output goes here...

The version of the SDK (See pubspec.lock): 6.9.0


I have the following issue:

beforeSend has no effect what-so-ever.

My current logic is:

 await SentryFlutter.init(
   (options) {
     options.tracesSampleRate = 0.1;
     options.beforeBreadcrumb = (breadcrumb, {hint}) {
       return breadcrumb?.removeSensitiveInfo();
     };
     options.beforeSend = (event, {hint}) {
       return event.copyWith(throwable: 'TEST THROWABLE');
     };
   },
   appRunner: () {
     BaseAuthClient();
     runApp(
       const app.App(),
     );
   },
 );

The description goes here ...

Steps to reproduce:

Actual result:

Expected result:

Note: I think the same is happening for beforeBreadcrumbs too.

marandaneto commented 2 years ago

The problem is that you are trying to copyWith the throwable, this is used (internally) before the event runs the beforeSend callback to prepare the event with all the data that the throwable holds, so it won't have any effect. In case you want to do something with the exception and stack trace in the throwable, you should use the copyWith with the exceptions property of the event. If you do for example, return event.copyWith(logger: 'its working');, it'd work.

marandaneto commented 2 years ago

For breadcrumbs there's indeed, a bug, being fixed here https://github.com/getsentry/sentry-dart/pull/982

tomtaila commented 1 year ago

Thank you @marandaneto