Skip to content

feat: Sync file attachments to native#5211

Merged
bitsandfoxes merged 13 commits intomainfrom
feat/sync-file-attachment
Mar 30, 2026
Merged

feat: Sync file attachments to native#5211
bitsandfoxes merged 13 commits intomainfrom
feat/sync-file-attachment

Conversation

@bitsandfoxes
Copy link
Copy Markdown
Contributor

📜 Description

Relies on getsentry/sentry-native#1584

Attachments added to the scope should get synced to sentry-native. I.e. a Unity games has

SentrySdk.ConfigureScope(scope => scope.AddAttachment("special-logfile.log");

and the game crashes, that attachment should be available in the resulting sentry event.

💡 Motivation and Context

Resolves #4758

💚 How did you test it?

Unit tests. Unity SDK will have e2e tests.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

This needs to be used and implemented in the hybrid SDKs.
Adding support to sync bytes as attachments.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 18, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Sync file attachments to native by bitsandfoxes in #5211

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 18, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against ab36430

@sentry
Copy link
Copy Markdown

sentry bot commented Mar 20, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.37.1 (1) release Install Build

Copy link
Copy Markdown
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

LGTM!

@bitsandfoxes bitsandfoxes marked this pull request as ready for review March 20, 2026 11:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 20, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 315.71 ms 381.33 ms 65.62 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
9ea89e8 308.06 ms 358.16 ms 50.10 ms
b193867 319.59 ms 403.09 ms 83.50 ms
dcc6bbf 382.58 ms 462.13 ms 79.54 ms
d501a7e 307.33 ms 341.94 ms 34.61 ms
22f4345 325.23 ms 454.66 ms 129.43 ms
33a08cc 267.08 ms 340.45 ms 73.37 ms
dba088c 321.78 ms 364.59 ms 42.82 ms
092f017 353.13 ms 433.84 ms 80.71 ms
d501a7e 314.55 ms 343.34 ms 28.79 ms
ce0a49e 532.00 ms 609.96 ms 77.96 ms

App size

Revision Plain With Sentry Diff
9ea89e8 1.58 MiB 2.28 MiB 716.23 KiB
b193867 1.58 MiB 2.19 MiB 620.00 KiB
dcc6bbf 1.58 MiB 2.12 MiB 553.10 KiB
d501a7e 0 B 0 B 0 B
22f4345 1.58 MiB 2.29 MiB 719.83 KiB
33a08cc 1.58 MiB 2.12 MiB 555.28 KiB
dba088c 1.58 MiB 2.13 MiB 558.99 KiB
092f017 0 B 0 B 0 B
d501a7e 0 B 0 B 0 B
ce0a49e 1.58 MiB 2.10 MiB 532.94 KiB

Previous results on branch: feat/sync-file-attachment

Startup times

Revision Plain With Sentry Diff
1db6b07 352.81 ms 421.24 ms 68.43 ms

App size

Revision Plain With Sentry Diff
1db6b07 0 B 0 B 0 B

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Silent data loss for byteProvider-based attachments
    • Added support for byteProvider-based attachments by invoking the callable on the background thread to resolve bytes before passing them to the native scope.

Create PR

Or push these changes by commenting:

@cursor push 4e0d3a19c6
Preview (4e0d3a19c6)
diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
--- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
+++ b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
@@ -170,6 +170,34 @@
       return;
     }
 
+    final java.util.concurrent.Callable<byte[]> byteProvider = attachment.getByteProvider();
+    if (byteProvider != null) {
+      final String filename = attachment.getFilename();
+      try {
+        options
+            .getExecutorService()
+            .submit(
+                () -> {
+                  try {
+                    final byte[] providedBytes = byteProvider.call();
+                    if (providedBytes != null) {
+                      nativeScope.addAttachmentBytes(providedBytes, filename);
+                    }
+                  } catch (Throwable e) {
+                    options
+                        .getLogger()
+                        .log(
+                            SentryLevel.ERROR,
+                            e,
+                            "Scope sync addAttachment failed to resolve byteProvider.");
+                  }
+                });
+      } catch (Throwable e) {
+        options.getLogger().log(SentryLevel.ERROR, e, "Scope sync addAttachment has an error.");
+      }
+      return;
+    }
+
     options
         .getLogger()
         .log(SentryLevel.DEBUG, "Scope sync addAttachment skips attachment without path or bytes.");

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@bitsandfoxes bitsandfoxes merged commit 79a0913 into main Mar 30, 2026
79 of 81 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/sync-file-attachment branch March 30, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attachments set in Java do not end up in NDK crashes

3 participants