Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* Feat: Add logger name to `SentryLogger` and send errors in integrations to the registered logger (#641)

# 6.1.2

* Fix: Remove is Enum check to support older Dart versions (#635)
Expand Down
8 changes: 8 additions & 0 deletions dart/lib/src/default_integrations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class RunZonedGuardedIntegration extends Integration {
await _runner();
},
(exception, stackTrace) async {
options.logger(
SentryLevel.error,
'Uncaught zone error',
logger: 'sentry.runZonedGuarded',
exception: exception,
stackTrace: stackTrace,
);

// runZonedGuarded doesn't crash the App.
final mechanism = Mechanism(type: 'runZonedGuarded', handled: true);
final throwableMechanism = ThrowableMechanism(mechanism, exception);
Expand Down
9 changes: 8 additions & 1 deletion dart/lib/src/diagnostic_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ class DiagnosticLogger {
void log(
SentryLevel level,
String message, {
String? logger,
Object? exception,
StackTrace? stackTrace,
}) {
if (_isEnabled(level)) {
_logger(level, message, exception: exception, stackTrace: stackTrace);
_logger(
level,
message,
logger: logger,
exception: exception,
stackTrace: stackTrace,
);
}
}

Expand Down
20 changes: 17 additions & 3 deletions dart/lib/src/isolate_error_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,23 @@ Future<void> handleIsolateError(

// https://api.dartlang.org/stable/2.7.0/dart-isolate/Isolate/addErrorListener.html
// error is a list of 2 elements
if (error is List<dynamic> && error.length == 2) {
final dynamic throwable = error.first;
final dynamic stackTrace = error.last;
if (error is List && error.length == 2) {
/// The errors are sent back as two-element lists.
/// The first element is a `String` representation of the error, usually
/// created by calling `toString` on the error.
/// The second element is a `String` representation of an accompanying
/// stack trace, or `null` if no stack trace was provided.
/// To convert this back to a [StackTrace] object, use [StackTrace.fromString].
final String throwable = error.first;
final String? stackTrace = error.last;

options.logger(
SentryLevel.error,
'Uncaught isolate error',
logger: 'sentry.isolateError',
exception: throwable,
stackTrace: stackTrace == null ? null : StackTrace.fromString(stackTrace),
);

// Isolate errors don't crash the App.
final mechanism = Mechanism(type: 'isolateError', handled: true);
Expand Down
9 changes: 6 additions & 3 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import 'package:http/http.dart';
import 'diagnostic_logger.dart';
import 'environment/environment_variables.dart';
import 'event_processor.dart';
import 'http_client/sentry_http_client.dart';
import 'integration.dart';
import 'noop_client.dart';
import 'platform_checker.dart';
import 'protocol.dart';
import 'tracing.dart';
import 'transport/noop_transport.dart';
import 'transport/transport.dart';
import 'utils.dart';
import 'version.dart';
import 'platform_checker.dart';
import 'http_client/sentry_http_client.dart';

// TODO: Scope observers, enableScopeSync
// TODO: shutdownTimeout, flushTimeoutMillis
Expand Down Expand Up @@ -320,6 +320,7 @@ typedef ClockProvider = DateTime Function();
typedef SentryLogger = void Function(
SentryLevel level,
String message, {
String? logger,
Object? exception,
StackTrace? stackTrace,
});
Expand All @@ -331,6 +332,7 @@ typedef TracesSamplerCallback = double? Function(
void noOpLogger(
SentryLevel level,
String message, {
String? logger,
Object? exception,
StackTrace? stackTrace,
}) {}
Expand All @@ -339,13 +341,14 @@ void noOpLogger(
void dartLogger(
SentryLevel level,
String message, {
String? logger,
Object? exception,
StackTrace? stackTrace,
}) {
log(
'[${level.name}] $message',
level: level.toDartLogLevel(),
name: 'sentry',
name: logger ?? 'sentry',
time: getUtcDateTime(),
error: exception,
stackTrace: stackTrace,
Expand Down
6 changes: 3 additions & 3 deletions dart/test/default_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:sentry/sentry.dart';
import 'package:sentry/src/noop_sentry_span.dart';
import 'package:test/test.dart';

import 'mocks.dart';
import 'mocks/mock_hub.dart';
import 'mocks.dart';

void main() {
late Fixture fixture;
Expand Down Expand Up @@ -34,8 +34,8 @@ void main() {
test(
'Isolate error capture errors',
() async {
final throwable = StateError('error');
final stackTrace = StackTrace.current;
final throwable = StateError('error').toString();
final stackTrace = StackTrace.current.toString();
final error = [throwable, stackTrace];

// we could not find a way to trigger an error to the current Isolate
Expand Down
8 changes: 7 additions & 1 deletion flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ environment:
dependencies:
flutter:
sdk: flutter
sentry:
sentry_flutter:
path: ../
universal_platform: ^1.0.0-nullsafety
feedback: ^2.0.0
provider: ^6.0.0

dev_dependencies:
sentry_dart_plugin: ^1.0.0-alpha.4

dependency_overrides:
sentry:
path: ../../dart
sentry_flutter:
path: ../

flutter:
uses-material-design: true

Expand Down
11 changes: 10 additions & 1 deletion flutter/lib/src/default_integrations.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sentry/sentry.dart';

import 'sentry_flutter_options.dart';
import 'widgets_binding_observer.dart';

Expand Down Expand Up @@ -70,6 +71,14 @@ class FlutterErrorIntegration extends Integration<SentryFlutterOptions> {
if (library != null) 'library': library,
};

options.logger(
SentryLevel.error,
errorDetails.toStringShort(),
logger: 'sentry.flutterError',
exception: exception,
stackTrace: errorDetails.stack,
);

// FlutterError doesn't crash the App.
final mechanism = Mechanism(
type: 'FlutterError',
Expand Down