-
-
Notifications
You must be signed in to change notification settings - Fork 221
/
load_image_list_integration.dart
77 lines (64 loc) · 2.29 KB
/
load_image_list_integration.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sentry/sentry.dart';
import '../sentry_flutter_options.dart';
/// Loads the native debug image list for stack trace symbolication.
class LoadImageListIntegration extends Integration<SentryFlutterOptions> {
final MethodChannel _channel;
LoadImageListIntegration(this._channel);
@override
FutureOr<void> call(Hub hub, SentryFlutterOptions options) {
options.addEventProcessor(
_LoadImageListIntegrationEventProcessor(_channel, options),
);
options.sdk.addIntegration('loadImageListIntegration');
}
}
extension _NeedsSymbolication on SentryEvent {
bool needsSymbolication() {
if (this is SentryTransaction) return false;
final frames = exceptions?.first.stackTrace?.frames;
if (frames == null) return false;
return frames.any((frame) => 'native' == frame.platform);
}
}
class _LoadImageListIntegrationEventProcessor extends EventProcessor {
_LoadImageListIntegrationEventProcessor(this._channel, this._options);
final MethodChannel _channel;
final SentryFlutterOptions _options;
@override
FutureOr<SentryEvent?> apply(SentryEvent event, {hint}) async {
if (event.needsSymbolication()) {
try {
// we call on every event because the loaded image list is cached
// and it could be changed on the Native side.
final loadImageList = await _channel.invokeMethod('loadImageList');
final imageList = List<Map<dynamic, dynamic>>.from(
loadImageList is List ? loadImageList : [],
);
return copyWithDebugImages(event, imageList);
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
'loadImageList failed',
exception: exception,
stackTrace: stackTrace,
);
}
}
return event;
}
static SentryEvent copyWithDebugImages(
SentryEvent event, List<Object?> imageList) {
if (imageList.isEmpty) {
return event;
}
final newDebugImages = <DebugImage>[];
for (final obj in imageList) {
final jsonMap = Map<String, dynamic>.from(obj as Map<dynamic, dynamic>);
final image = DebugImage.fromJson(jsonMap);
newDebugImages.add(image);
}
return event.copyWith(debugMeta: DebugMeta(images: newDebugImages));
}
}