Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/only send debug images referenced in the stacktrace for events #2329

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
49e2768
load only specific debug images
martinhaintz Oct 7, 2024
365e16a
adapt tests
martinhaintz Oct 7, 2024
bad0c67
Merge branch 'main' into feat/only-send-debug-images-referenced-in-th…
martinhaintz Oct 7, 2024
211be42
fix unittest
martinhaintz Oct 8, 2024
05952f9
add fallback to previous handling if no addresses are sent
martinhaintz Oct 8, 2024
8786ea7
switch from frame to instruction address
martinhaintz Oct 8, 2024
fa97c64
Merge branch 'feat/only-send-debug-images-referenced-in-the-stacktrac…
martinhaintz Oct 8, 2024
bd8befc
fix address conversion
martinhaintz Oct 10, 2024
77b877a
fix, also check for empty set
martinhaintz Oct 10, 2024
e153914
fix variable name
martinhaintz Oct 10, 2024
0fef294
improve performance
martinhaintz Oct 10, 2024
618f503
Update flutter/ios/Classes/SentryFlutterPluginApple.swift
martinhaintz Oct 11, 2024
e8592b5
Update flutter/ios/Classes/SentryFlutterPluginApple.swift
martinhaintz Oct 11, 2024
6df4617
Update flutter/ios/Classes/SentryFlutterPluginApple.swift
martinhaintz Oct 11, 2024
c36427b
Update flutter/lib/src/native/sentry_native_channel.dart
martinhaintz Oct 11, 2024
ec0e60d
Update flutter/lib/src/native/sentry_native_binding.dart
martinhaintz Oct 11, 2024
9530ca8
Update flutter/lib/src/integrations/load_image_list_integration.dart
martinhaintz Oct 11, 2024
f83b0fe
merge main
martinhaintz Oct 11, 2024
ad79f89
fix test
martinhaintz Oct 11, 2024
5f361b5
fix test
martinhaintz Oct 11, 2024
18890a0
Merge branch 'main' into feat/only-send-debug-images-referenced-in-th…
martinhaintz Oct 11, 2024
bb9e2c4
add changelog
martinhaintz Oct 11, 2024
2cc98f6
fix swift linting
martinhaintz Oct 11, 2024
a16277e
Merge branch 'main' into feat/only-send-debug-images-referenced-in-th…
martinhaintz Nov 13, 2024
1506113
use cached debug images
martinhaintz Nov 13, 2024
4870e02
fix swift linting
martinhaintz Nov 13, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

- Only send debug images referenced in the stacktrace for events ([#2329](https://github.com/getsentry/sentry-dart/pull/2329))
- Remove `sentry` frames if SDK falls back to current stack trace ([#2351](https://github.com/getsentry/sentry-dart/pull/2351))
- Flutter doesn't always provide stack traces for unhandled errors - this is normal Flutter behavior
- When no stack trace is provided (in Flutter errors, `captureException`, or `captureMessage`):
Expand Down
2 changes: 2 additions & 0 deletions flutter/ios/Classes/SentryFlutterPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
#import <FlutterMacOS/FlutterMacOS.h>
#endif

#import <Sentry/SentryDebugImageProvider.h>

@interface SentryFlutterPlugin : NSObject<FlutterPlugin>
@end
31 changes: 27 additions & 4 deletions flutter/ios/Classes/SentryFlutterPluginApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
loadContexts(result: result)

case "loadImageList":
loadImageList(result: result)
loadImageList(call, result: result)

case "initNativeSdk":
initNativeSdk(call, result: result)
Expand Down Expand Up @@ -277,9 +277,32 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
}
}

private func loadImageList(result: @escaping FlutterResult) {
let debugImages = PrivateSentrySDKOnly.getDebugImages() as [DebugMeta]
result(debugImages.map { $0.serialize() })
private func loadImageList(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
var debugImages: [DebugMeta] = []

if let arguments = call.arguments as? [String], !arguments.isEmpty {
var imagesAddresses: Set<String> = []

for argument in arguments {
let hexDigits = argument.replacingOccurrences(of: "0x", with: "")
if let instructionAddress = UInt64(hexDigits, radix: 16) {
let image = SentryDependencyContainer.sharedInstance().binaryImageCache.image(
byAddress: instructionAddress)
if let image = image {
let imageAddress = sentry_formatHexAddressUInt64(image.address)!
imagesAddresses.insert(imageAddress)
}
}
}
debugImages =
SentryDependencyContainer.sharedInstance().debugImageProvider
.getDebugImagesForImageAddressesFromCache(imageAddresses: imagesAddresses) as [DebugMeta]
}
if debugImages.isEmpty {
debugImages = PrivateSentrySDKOnly.getDebugImages() as [DebugMeta]
}

result(debugImages.map { $0.serialize() })
}

private func initNativeSdk(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand Down
11 changes: 9 additions & 2 deletions flutter/lib/src/native/sentry_native_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,15 @@
@override
Future<List<DebugImage>?> loadDebugImages(SentryStackTrace stackTrace) =>
tryCatchAsync('loadDebugImages', () async {
final images = await channel
.invokeListMethod<Map<dynamic, dynamic>>('loadImageList');
Set<String> instructionAddresses = {};
for (var frame in stackTrace.frames) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (var frame in stackTrace.frames) {
for (final frame in stackTrace.frames) {

if (frame.instructionAddr != null) {
instructionAddresses.add(frame.instructionAddr!);

Check warning on line 192 in flutter/lib/src/native/sentry_native_channel.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/native/sentry_native_channel.dart#L191-L192

Added lines #L191 - L192 were not covered by tests
}
}

final images = await channel.invokeListMethod<Map<dynamic, dynamic>>(
'loadImageList', instructionAddresses.toList());
return images
?.map((e) => e.cast<String, dynamic>())
.map(DebugImage.fromJson)
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/sentry_native_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void main() {
}
];

when(channel.invokeMethod('loadImageList'))
when(channel.invokeMethod('loadImageList', any))
.thenAnswer((invocation) async => json);

final data = await sut.loadDebugImages(SentryStackTrace(frames: []));
Expand Down
Loading