Skip to content

Commit 4e0d3a1

Browse files
committed
fix(android-ndk): Support byteProvider-based attachments in NdkScopeObserver
Previously, attachments created with a byteProvider (e.g., via Attachment.fromByteProvider() or fromScreenshot()) were silently skipped because both getPathname() and getBytes() return null for these attachments. This caused data loss for native crash reports. This fix adds support for byteProvider-based attachments by invoking the callable on the background thread (via executor service) to resolve the bytes before passing them to the native scope.
1 parent ab36430 commit 4e0d3a1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,34 @@ public void addAttachment(final @NotNull Attachment attachment) {
170170
return;
171171
}
172172

173+
final java.util.concurrent.Callable<byte[]> byteProvider = attachment.getByteProvider();
174+
if (byteProvider != null) {
175+
final String filename = attachment.getFilename();
176+
try {
177+
options
178+
.getExecutorService()
179+
.submit(
180+
() -> {
181+
try {
182+
final byte[] providedBytes = byteProvider.call();
183+
if (providedBytes != null) {
184+
nativeScope.addAttachmentBytes(providedBytes, filename);
185+
}
186+
} catch (Throwable e) {
187+
options
188+
.getLogger()
189+
.log(
190+
SentryLevel.ERROR,
191+
e,
192+
"Scope sync addAttachment failed to resolve byteProvider.");
193+
}
194+
});
195+
} catch (Throwable e) {
196+
options.getLogger().log(SentryLevel.ERROR, e, "Scope sync addAttachment has an error.");
197+
}
198+
return;
199+
}
200+
173201
options
174202
.getLogger()
175203
.log(SentryLevel.DEBUG, "Scope sync addAttachment skips attachment without path or bytes.");

0 commit comments

Comments
 (0)