Skip to content

fix: Support adding attachments inside configuration callback - #573

Merged
limbonaut merged 12 commits into
mainfrom
limbonaut/fix/attachments-in-config-callback
Mar 6, 2026
Merged

fix: Support adding attachments inside configuration callback#573
limbonaut merged 12 commits into
mainfrom
limbonaut/fix/attachments-in-config-callback

Conversation

@limbonaut

@limbonaut limbonaut commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Support calling SentrySDK.add_attachment() and SentrySDK.clear_attachments() inside the configuration callback passed to SentrySDK.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.

Attachments added during configuration are stored temporarily in SentryOptions.custom_attachments and drained through each backend's add_attachment() after init succeeds. Also splits file_attachments into default_attachments (built-in, survive clear_attachments()) and custom_attachments (user-added during config), and centralizes the draining logic in SentrySDK::init().

limbonaut and others added 5 commits March 6, 2026 11:29
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>
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

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


Bug Fixes 🐛

  • Support adding attachments inside configuration callback by limbonaut in #573
  • Fix blank attachment names and harden attachment handling by limbonaut in #567

Internal Changes 🔧

  • (deps) Update Sentry Android to v8.34.1 by github-actions in #572
  • Remove unused native_attachment accessors from SentryAttachment by limbonaut in #566

🤖 This preview updates automatically when you update the PR.

limbonaut and others added 2 commits March 6, 2026 11:50
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
limbonaut marked this pull request as ready for review March 6, 2026 10:55
Co-Authored-By: Claude <noreply@anthropic.com>
@limbonaut
limbonaut force-pushed the limbonaut/fix/attachments-in-config-callback branch from b570e09 to a2412bd Compare March 6, 2026 11:01
Comment thread src/sentry/sentry_sdk.cpp
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>
Comment thread src/sentry/sentry_options.cpp
Comment thread src/sentry/native/native_sdk.cpp Outdated
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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread src/sentry/sentry_options.cpp
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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@limbonaut

limbonaut commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator Author

@limbonaut

Copy link
Copy Markdown
Collaborator Author

E2E tests passed.

@limbonaut
limbonaut merged commit 747dd24 into main Mar 6, 2026
63 checks passed
@limbonaut
limbonaut deleted the limbonaut/fix/attachments-in-config-callback branch March 6, 2026 14:08
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.

Investigate add_attachment() called within GDScript configuration callback

2 participants