getsentry / sentry-dart

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

beforeBreadcrumb not called for automatic breadcrumbs #1903

Closed teunklijn closed 8 months ago

teunklijn commented 8 months ago

Platform

Flutter Mobile

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.16.3, on macOS 13.6.4 22G513 darwin-x64, locale nl-NL)
    • Flutter version 3.16.3 on channel stable at [redacted]
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0366e0a3f (3 months ago), 2023-12-05 19:46:39 -0800
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at [redacted]
    • Platform android-34, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2022.1)
    • 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
    • android-studio-dir = /Applications/Android Studio.app
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

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

[✓] Connected device (4 available)
    • Redacted

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Version

7.16.1

Steps to Reproduce

import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Breadcrumb? beforeBreadcrumb(Breadcrumb? crumb, {dynamic hint}) {
  print('before bc');
  return null;
}

void main() async {
  await SentryFlutter.init((options) {
    options
      ..dsn = '[DSN]'
      ..beforeBreadcrumb = beforeBreadcrumb
      ..useFlutterBreadcrumbTracking();
  }, appRunner: () {
    return runApp(const MyApp());
  });
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          try {
            throw Exception('This is only a test');
          } catch (e) {
            await Sentry.addBreadcrumb(Breadcrumb(message: 'This is my message', category: 'blah'));
            Sentry.captureException(e);
          }
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}

Expected Result

The resulting issue in Sentry when pressing the button doesn't contain any breadcrumbs.

Actual Result

The resulting issue in Sentry when pressing the button contains several breadcrumbs.

Scherm­afbeelding 2024-02-29 om 16 46 54

Are you willing to submit a PR?

No

buenaflor commented 8 months ago

hey! thx we'll have a look. just a hunch but it might be that these breadcrumbs are created from the native layer so the beforeBreadcrumb in the flutter layer won't have effect on that.

buenaflor commented 8 months ago

Closing this, this will be part of the next release