Skip to content

feat(android): use debug image loading by address api #2706

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

Merged
merged 19 commits into from
Feb 19, 2025
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@

- Disable `ScreenshotIntegration`, `WidgetsBindingIntegration` and `SentryWidget` in multi-view apps #2366 ([#2366](https://github.com/getsentry/sentry-dart/pull/2366))

### Enhancements

- Use `loadDebugImagesForAddresses` API for Android ([#2706](https://github.com/getsentry/sentry-dart/pull/2706))
- This reduces the envelope size and data transferred across method channels
- If debug images received by `loadDebugImagesForAddresses` are empty, the SDK loads all debug images as fallback

### Fixes

- Reference to `SentryWidgetsFlutterBinding` in warning message in `FramesTrackingIntegration` ([#2704](https://github.com/getsentry/sentry-dart/pull/2704))
- Replay video interuption if a `navigation` breadcrumb is missing `to` route info ([#2720](https://github.com/getsentry/sentry-dart/pull/2720))
- Replay video interruption if a `navigation` breadcrumb is missing `to` route info ([#2720](https://github.com/getsentry/sentry-dart/pull/2720))

### Deprecations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SentryFlutterPlugin :
when (call.method) {
"initNativeSdk" -> initNativeSdk(call, result)
"captureEnvelope" -> captureEnvelope(call, result)
"loadImageList" -> loadImageList(result)
"loadImageList" -> loadImageList(call, result)
"closeNativeSdk" -> closeNativeSdk(result)
"fetchNativeAppStart" -> fetchNativeAppStart(result)
"beginNativeFrames" -> beginNativeFrames(result)
Expand Down Expand Up @@ -483,31 +483,43 @@ class SentryFlutterPlugin :
result.error("3", "Envelope is null or empty", null)
}

private fun loadImageList(result: Result) {
private fun loadImageList(
call: MethodCall,
result: Result,
) {
val options = HubAdapter.getInstance().options as SentryAndroidOptions

val newDebugImages = mutableListOf<Map<String, Any?>>()
val debugImages: List<DebugImage>? = options.debugImagesLoader.loadDebugImages()

debugImages?.let {
it.forEach { image ->
val item = mutableMapOf<String, Any?>()

item["image_addr"] = image.imageAddr
item["image_size"] = image.imageSize
item["code_file"] = image.codeFile
item["type"] = image.type
item["debug_id"] = image.debugId
item["code_id"] = image.codeId
item["debug_file"] = image.debugFile

newDebugImages.add(item)
val addresses = call.arguments() as List<String>? ?: listOf()
val debugImages =
if (addresses.isEmpty()) {
options.debugImagesLoader
.loadDebugImages()
?.toList()
.serialize()
} else {
options.debugImagesLoader
.loadDebugImagesForAddresses(addresses.toSet())
?.ifEmpty { options.debugImagesLoader.loadDebugImages() }
?.toList()
.serialize()
}
}

result.success(newDebugImages)
result.success(debugImages)
}

private fun List<DebugImage>?.serialize() = this?.map { it.serialize() }

private fun DebugImage.serialize() =
mapOf(
"image_addr" to imageAddr,
"image_size" to imageSize,
"code_file" to codeFile,
"type" to type,
"debug_id" to debugId,
"code_id" to codeId,
"debug_file" to debugFile,
)

private fun closeNativeSdk(result: Result) {
HubAdapter.getInstance().close()
framesTracker?.stop()
Expand Down
31 changes: 31 additions & 0 deletions flutter/example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,37 @@ void main() {
await transaction.finish();
});

testWidgets('setup sentry and test loading debug image', (tester) async {
await restoreFlutterOnErrorAfter(() async {
await setupSentryAndApp(tester);
});

// By default it should load all debug images
final allDebugImages = await SentryFlutter.native
?.loadDebugImages(SentryStackTrace(frames: const []));
// Typically loading all images results in a larger numbers
expect(allDebugImages!.length > 100, isTrue);

// We can take any other random image for testing
final expectedImage = allDebugImages.first;
expect(expectedImage.imageAddr, isNotNull);
final imageAddr =
int.parse(expectedImage.imageAddr!.replaceAll('0x', ''), radix: 16);

// Use the base image address and increase by offset
// so the instructionAddress will be within the range of the image address
final imageOffset = (expectedImage.imageSize! / 2).toInt();
final instructionAddr = '0x${(imageAddr + imageOffset).toRadixString(16)}';
final sentryFrame = SentryStackFrame(instructionAddr: instructionAddr);

final debugImageByStacktrace = await SentryFlutter.native
?.loadDebugImages(SentryStackTrace(frames: [sentryFrame]));
expect(debugImageByStacktrace!.length, 1);
expect(debugImageByStacktrace.first.imageAddr, isNotNull);
expect(debugImageByStacktrace.first.imageAddr, isNotEmpty);
expect(debugImageByStacktrace.first.imageAddr, expectedImage.imageAddr);
});

group('e2e', () {
var output = find.byKey(const Key('output'));
late Fixture fixture;
Expand Down
Loading