fix: Support adding attachments inside configuration callback - #573
Merged
Conversation
SentrySDK.add_attachment() called inside the init() configuration callback was silently lost because the internal SDK wasn't initialized yet. Now, during the callback window, attachments are redirected to options storage and registered with the platform SDK during init. Split attachment storage in SentryOptions into default_attachments (built-in: log, screenshot, view hierarchy — survive clear) and custom_attachments (user-added during callback — ephemeral, consumed at init). On clear_attachments(), only default attachments are restored. Co-Authored-By: Claude <noreply@anthropic.com>
Reuse add_attachment() after platform SDK init for custom attachments, same pattern as NativeSDK. This correctly handles both file-path and bytes attachments instead of only file-path. Co-Authored-By: Claude <noreply@anthropic.com>
…S SDK Bytes attachments added inside the configuration callback were silently dropped on the web platform. The init method appended them to the file_attachments vector instead of routing through add_attachment(), which dispatches file vs bytes attachments correctly. Co-Authored-By: Claude <noreply@anthropic.com>
Default attachments are always file-based (log, screenshot, view hierarchy). Reject bytes attachments with an error to catch misuse early. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Move custom attachment drain to after js_bridge init call, fixing bytes attachments being sent before the bridge is ready. Also normalize comments across all backends and add changelog entry. Co-Authored-By: Claude <noreply@anthropic.com>
limbonaut
marked this pull request as ready for review
March 6, 2026 10:55
Co-Authored-By: Claude <noreply@anthropic.com>
limbonaut
force-pushed
the
limbonaut/fix/attachments-in-config-callback
branch
from
March 6, 2026 11:01
b570e09 to
a2412bd
Compare
Route clear_attachments() through options.clear_custom_attachments() when called inside the configuration callback, consistent with how add_attachment() already handles the is_configuring state. Previously, clear_attachments() would fall through to DisabledSDK (a no-op), leaving previously added custom attachments intact. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the custom-attachment draining logic (iterate, add_attachment, clear) from all four backend init() methods into SentrySDK::init(), right after internal_sdk->init() succeeds. This eliminates identical copy-pasted blocks in NativeSDK, AndroidSDK, CocoaSDK, and JavaScriptSDK, reducing the risk of future inconsistencies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Previously, add_default_attachment would dereference the Ref to check get_path() without first verifying it's non-null, risking a crash. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
limbonaut
requested review from
JoshuaMoelans,
bitsandfoxes,
jpnurmi,
mujacica and
tustanivsky
March 6, 2026 11:52
jpnurmi
approved these changes
Mar 6, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6 tasks
Collaborator
Author
Collaborator
Author
|
E2E tests passed. |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support calling
SentrySDK.add_attachment()andSentrySDK.clear_attachments()inside the configuration callback passed toSentrySDK.init(). Previously this would fail because the SDK backend isn't initialized yet when the callback runs. This used to work on Apple platforms, but not on native giving a false impression if you develop on macOS.add_attachment()called within GDScript configuration callback #570Attachments added during configuration are stored temporarily in
SentryOptions.custom_attachmentsand drained through each backend'sadd_attachment()after init succeeds. Also splitsfile_attachmentsintodefault_attachments(built-in, surviveclear_attachments()) andcustom_attachments(user-added during config), and centralizes the draining logic inSentrySDK::init().