getsentry / sentry-dart

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

Not showing error message in sentry #2423

Open Maruf-Elsa opened 2 days ago

Maruf-Elsa commented 2 days ago

Platform

Flutter Mobile

Obfuscation

Enabled

Debug Info

Enabled

Doctor

[✓] Flutter (Channel stable, 3.24.0, on macOS 14.1.2 23B92 darwin-arm64, locale en-IN)
    • Flutter version 3.24.0 on channel stable at /Users/marufhassan/fvm/versions/3.24.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (4 months ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/marufhassan/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/marufhassan/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.3)
    • 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 17.0.6+0-17.0.6b829.9-10027231)

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

[✓] Connected device (4 available)            
    • sdk gphone64 arm64 (mobile)     • emulator-5554         • android-arm64  • Android 15 (API 35) (emulator)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.1.2 23B92 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.1.2 23B92 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 131.0.6778.70

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

• No issues found!

Version

8.9.0

Steps to Reproduce

  1. Created a function to hit logs for Sentry in a gesturedetector button.
                      LoggerManager().log(
                        LogLevel.error,
                        'Login_Failure2',
                        metadata: {
                          'logger_message':'Missing Token',
                          'setTagKey': AuthenticationChannelKeys.loggerMessage,
                          'setTagValue': 'Google Login',
                        },
                      );
import 'package:sentry_flutter/sentry_flutter.dart';

import 'logger.dart';

class SentryLogger implements Logger {
  @override
  void log(LogLevel level, String message, {Map<String, dynamic>? metadata}) {
    List<dynamic>? params;
    var sentryLevel = SentryLevel.info;

    switch (level) {
      case LogLevel.debug:
      case LogLevel.info:
        sentryLevel = SentryLevel.info;
        params = metadata?.values.toList();

      case LogLevel.warn:
        sentryLevel = SentryLevel.warning;

      case LogLevel.error:
        sentryLevel = SentryLevel.error;
    }

    Sentry.captureMessage(
      message,
      level: sentryLevel,
      params: params,
      withScope: (scope) {
        if (metadata != null) {
          metadata.forEach((key, value) {
            scope.setContexts(key, value);
          });
        }
      },
    );

    if (level == LogLevel.error &&
        metadata != null &&
        metadata.containsKey('exception')) {
      Sentry.captureException(metadata['exception']);
    } else if (level == LogLevel.error &&
        metadata != null &&
        metadata.containsKey('logger_message')) {
      Sentry.configureScope((scope) {
        if (metadata.containsKey('setTagKey') &&
            metadata.containsKey('setTagValue')) {
          scope.setTag(
            metadata['setTagKey'] as String,
            metadata['setTagValue'] as String,
          );
        }
      });
      Sentry.captureException(
        stackTrace: message,
        metadata['logger_message'],
      );
    }
  }

  @override
  void debug(String message, {Map<String, dynamic>? metadata}) =>
      log(LogLevel.debug, message, metadata: metadata);

  @override
  void info(String message, {Map<String, dynamic>? metadata}) =>
      log(LogLevel.info, message, metadata: metadata);

  @override
  void warn(String message, {Map<String, dynamic>? metadata}) =>
      log(LogLevel.warn, message, metadata: metadata);

  @override
  void error(String message, {Map<String, dynamic>? metadata}) =>
      log(LogLevel.error, message, metadata: metadata);
}
  1. After successful trigger we get the setTagKey & setTagValue in Sentry but for logger_message metadata we don't get the error message 'Missing Token' we get value as [Filtered] as shown in this pic - https://imgur.com/Yavd4lG
  2. In the Issues page we see another event created called with the error message Missing Token but for the event Login_Failure2 we don't get any error message (No error message). I have added the pic - https://imgur.com/7Q4nTaH
String 
unparsed in Login_Failure2

Expected Result

My expected result was seeing the event in Sentry with the error message 'Missing Token' instead of No error message - https://imgur.com/aM3XMpu

Actual Result

I am getting two different events, I want to recieve only 1 event - https://imgur.com/7Q4nTaH

Are you willing to submit a PR?

None

buenaflor commented 1 day ago

hey thank you for the issue, we'll have a look. is this an issue on both iOS and Android?

Maruf-Elsa commented 12 hours ago

Its happening in both Android and iOS @buenaflor