Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add info for unhandled exception
  • Loading branch information
buenaflor committed Jul 8, 2024
commit 0bfb267eec721061597f06457fefda349f24422d
9 changes: 8 additions & 1 deletion dart/lib/src/sentry_envelope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ import 'sentry_user_feedback.dart';

/// Class representation of `Envelope` file.
class SentryEnvelope {
SentryEnvelope(this.header, this.items);
SentryEnvelope(this.header, this.items, {this.containsUnhandledException = false});

/// Header describing envelope content.
final SentryEnvelopeHeader header;

/// All items contained in the envelope.
final List<SentryEnvelopeItem> items;

/// Whether the envelope contains an unhandled exception.
/// This is used to determine if the native SDK should start a new session.
final bool containsUnhandledException;

/// Create a [SentryEnvelope] containing one [SentryEnvelopeItem] which holds the [SentryEvent] data.
factory SentryEnvelope.fromEvent(
SentryEvent event,
Expand All @@ -29,6 +33,8 @@ class SentryEnvelope {
SentryTraceContextHeader? traceContext,
List<SentryAttachment>? attachments,
}) {
final isUnhandledException =
event.exceptions?.first.mechanism?.handled == false;
return SentryEnvelope(
SentryEnvelopeHeader(
event.eventId,
Expand All @@ -41,6 +47,7 @@ class SentryEnvelope {
if (attachments != null)
...attachments.map((e) => SentryEnvelopeItem.fromAttachment(e))
],
containsUnhandledException: isUnhandledException,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
val args = call.arguments() as List<Any>? ?: listOf()
if (args.isNotEmpty()) {
val event = args.first() as ByteArray?
if (event != null && event.isNotEmpty()) {
val id = InternalSentrySdk.captureEnvelope(event)
val containsUnhandledException = args[1] as Boolean
if (event != null && event.isNotEmpty() && containsUnhandledException != null) {
val id = InternalSentrySdk.captureEnvelope(event, containsUnhandledException)
if (id != null) {
result.success("")
} else {
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/file_system_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FileSystemTransport implements Transport {
await envelope.envelopeStream(_options).forEach(envelopeData.addAll);
try {
// TODO avoid copy
await _native.captureEnvelope(Uint8List.fromList(envelopeData));
await _native.captureEnvelope(Uint8List.fromList(envelopeData), envelope.containsUnhandledException);
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/native/sentry_native_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class SentryNativeBinding {

Future<NativeAppStart?> fetchNativeAppStart();

Future<void> captureEnvelope(Uint8List envelopeData);
Future<void> captureEnvelope(Uint8List envelopeData, bool isUnhandledException);

Future<void> beginNativeFrames();

Expand Down
5 changes: 3 additions & 2 deletions flutter/lib/src/native/sentry_native_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ class SentryNativeChannel
}

@override
Future<void> captureEnvelope(Uint8List envelopeData) =>
_channel.invokeMethod('captureEnvelope', [envelopeData]);
Future<void> captureEnvelope(Uint8List envelopeData, bool containsUnhandledException) {
return _channel.invokeMethod('captureEnvelope', [envelopeData, containsUnhandledException]);
}

@override
Future<Map<String, dynamic>?> loadContexts() =>
Expand Down