Skip to content

ref!: sentry_value-based attachments - #1974

Open
jpnurmi wants to merge 5 commits into
masterfrom
jpnurmi/ref/attachments
Open

ref!: sentry_value-based attachments#1974
jpnurmi wants to merge 5 commits into
masterfrom
jpnurmi/ref/attachments

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Caution

BREAKING CHANGE

Attachment APIs now use sentry_value_t and sentry_uuid_t instead of sentry_attachment_t *.

Scope data is moving to fine-grained read/write locking (#1877) to allow concurrent readers. A read-locked getter cannot safely return a borrowed sentry_attachment_t pointer because a writer may remove and free the attachment as soon as the read lock is released, crashing a potential concurrent reader.

Represent attachments and attachment collections as refcounted sentry_value_t objects. A getter can retain the value under the read lock and return an owned reference that remains valid after unlocking.

Configure attachments before insertion and freeze them once added. Use UUIDs for removal, and retain byte values while envelopes borrow their payload to avoid copying attachment data.

See also:

Resolves: #1945

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.23718% with 167 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.67%. Comparing base (0a31c85) to head (c15c22f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1974      +/-   ##
==========================================
+ Coverage   74.37%   74.67%   +0.30%     
==========================================
  Files         103      103              
  Lines       26817    27021     +204     
  Branches     4881     4911      +30     
==========================================
+ Hits        19946    20179     +233     
+ Misses       5531     5504      -27     
+ Partials     1340     1338       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from 4ecd0c8 to 7cfebae Compare August 11, 2026 20:01
@jpnurmi
jpnurmi changed the base branch from master to jpnurmi/fix/unwinder-arm32-ip August 12, 2026 06:31
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from 7cfebae to ed216c7 Compare August 12, 2026 06:33
Comment thread src/sentry_core.c
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_core.c
Comment thread src/backends/sentry_backend_native.c Outdated
Base automatically changed from jpnurmi/fix/unwinder-arm32-ip to master August 13, 2026 12:47
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from 77576ea to 8349c66 Compare August 17, 2026 07:51
Comment thread src/sentry_attachment.c Outdated
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from 8349c66 to c7f80db Compare August 17, 2026 09:40
Comment thread src/sentry_core.c
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from c7f80db to b901758 Compare August 17, 2026 10:37
Comment thread src/backends/sentry_backend_breakpad.cpp
@jpnurmi jpnurmi changed the title [WIP] ref!: sentry_value-based attachments ref!: sentry_value-based attachments Aug 18, 2026
Comment thread src/backends/sentry_backend_crashpad.cpp Outdated
Comment thread src/backends/sentry_backend_crashpad.cpp Outdated
Comment thread src/backends/sentry_backend_crashpad.cpp
Comment thread src/backends/sentry_backend_crashpad.cpp
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch 2 times, most recently from 4677c4e to 4c21efb Compare August 20, 2026 16:26
@jpnurmi
jpnurmi changed the base branch from master to jpnurmi/ref/attachments-prep August 20, 2026 16:30
Comment thread src/backends/sentry_backend_native.c
Base automatically changed from jpnurmi/ref/attachments-prep to master August 25, 2026 17:13
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from d521912 to 08e8f8c Compare August 26, 2026 09:09

@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.

Stale Bugbot comment from a previous run.

Comment thread src/backends/sentry_backend_crashpad.cpp Outdated
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from 08e8f8c to ef00839 Compare August 26, 2026 09:25
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch 2 times, most recently from f08ef65 to ed71879 Compare September 9, 2026 08:51
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from ed71879 to 12cec9b Compare September 9, 2026 10:31
@jpnurmi
jpnurmi removed this pull request from stack #2010 September 9, 2026 10:32
@jpnurmi
jpnurmi changed the base branch from master to jpnurmi/feat/attachments September 9, 2026 10:32
@jpnurmi
jpnurmi added this pull request to stack #2080 September 9, 2026 10:32
@jpnurmi
jpnurmi removed this pull request from stack #2080 September 9, 2026 11:37
@jpnurmi
jpnurmi added this pull request to stack #2081 September 9, 2026 11:37
Base automatically changed from jpnurmi/feat/attachments to master September 9, 2026 11:58
Allow callers with borrowed path strings to obtain the final path component
without allocating a sentry_path_t. This prepares value-based attachment
properties, which expose borrowed strings.
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/attachments branch from 12cec9b to 0772fd8 Compare September 9, 2026 11:59

@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.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 0772fd8. Configure here.

Comment thread src/sentry_attachment.c
Comment thread src/integrations/sentry_integration_wer.c
@jpnurmi jpnurmi changed the title [0.17] ref!: sentry_value-based attachments ref!: sentry_value-based attachments Sep 9, 2026
@jpnurmi
jpnurmi removed this pull request from stack #2081 September 9, 2026 19:44
@jpnurmi
jpnurmi added this pull request to stack #2082 September 9, 2026 19:54
@jpnurmi
jpnurmi removed this pull request from stack #2082 September 10, 2026 11:51
@jpnurmi
jpnurmi added this pull request to stack #2084 September 10, 2026 11:58
@limbonaut

Copy link
Copy Markdown
Collaborator

On it - might take a little bit 😅

@jpnurmi

jpnurmi commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

My apologies for the worst kind of PR, mixing up noisy mechanical churn with behavior changes. 😅

@limbonaut limbonaut left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, some good code here! I couldn't spot any target 🎯 to assassinate 🥷
Just nits and an issue flagged by an AI scan (a good catch I think).

Comment thread CHANGELOG.md

**Breaking / Important behavior changes**:

- Attachment APIs now use `sentry_value_t` and `sentry_uuid_t` instead of `sentry_attachment_t *` handles. Most attachment APIs, function names and arguments, are otherwise unchanged. ([#1974](https://github.com/getsentry/sentry-native/pull/1974))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we mention that attachment value is now consumed/frozen after adding?

Comment thread src/sentry_attachment.c
}
size_t size = sentry__attachment_get_size(attachment);
if (size > SENTRY_MAX_ATTACHMENT_SIZE) {
const char *filename = sentry__attachment_get_filename(attachment);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: repeated below - can just move out of the branch

Comment thread src/sentry_attachment.c
if (memcmp(existing_id.bytes, attachment_id->bytes,
sizeof(existing_id.bytes))
== 0) {
sentry_value_t removed = sentry_value_incref(existing);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this also unfreeze, since the add-path freezes it? I may not grasp the whole picture here.

return;
}
sentry_path_t *path
= make_attachment_path(options->run->run_path, attachment);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clanker flagged an issue with WER and large attachments, introduced in this PR. Check it out:

P2: Preserve WER file registration for byte attachments larger than 64 KiB

With SENTRY_BACKEND=native and SENTRY_INTEGRATION_WER=ON, this change causes byte attachments larger than 64 KiB to stop being registered with Windows Error Reporting (WER).

For example, after SDK initialization:

static char diagnostic_data[128 * 1024];

sentry_attach_bytes(
    diagnostic_data, sizeof(diagnostic_data), "diagnostics.bin");

Previously, the native backend wrote these bytes to disk and stored the resulting path on the attachment. When the scope notified WER, it could discover that path and call WerRegisterFile.

The new implementation still writes the file, but keeps its path local to the backend. The registration sequence now becomes:

  1. sentry_add_attachment() calls the backend before inserting the attachment into the scope and notifying its observers.

  2. native_backend_add_attachment() derives <run>/<attachment UUID>/<filename> and writes the bytes there, without storing that path on the attachment.

  3. wer_attachment_path() still reads only the attachment’s "path" property, which is absent for byte attachments.

  4. wer_add_attachment() falls back to memory registration, guarded by:

    if (buf && buf_len > 0 && buf_len <= WER_MAX_MEM_BLOCK_SIZE)

    WER_MAX_MEM_BLOCK_SIZE is 64 KiB, so the 128 KiB attachment is silently skipped.

The size limit already existed. The regression is that native byte attachments now reach that limit instead of being registered as files.

A base-versus-PR reproduction produced:

Attachment size Base PR
64 KiB File registered Memory registered
64 KiB + 1 byte File registered Nothing registered
128 KiB File registered Nothing registered

The reproduction exercised the SDK attachment flow and extracted backend/WER callback code, with Windows API calls mocked on Linux. Actual Windows crash-report collection was not tested.

Could we expose the backend’s materialized attachment path to WER through an internal lookup helper or backend callback? WER could then register the successfully written file and retain the corresponding registration state for removal.

Simply restoring a "path" assignment would not cover attachments already frozen by insertion into another scope. A backend lookup preserves attachment immutability.

Please also cover registration above 64 KiB, matching unregistration, and failed file writes.

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.

ref(attachments): rework to be sentry_value_t-based

2 participants