feat: Add AddToTransactions to SentryAttachment#5182
Conversation
Adds an `AddToTransactions` boolean property to `SentryAttachment` (default `false`) that controls whether attachments are included in transaction envelopes. Previously attachments were never sent with transactions; now those with `AddToTransactions = true` are included. Closes #750 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5182 +/- ##
==========================================
+ Coverage 74.23% 74.54% +0.31%
==========================================
Files 509 512 +3
Lines 18412 18652 +240
Branches 3604 3655 +51
==========================================
+ Hits 13668 13904 +236
- Misses 3870 3874 +4
Partials 874 874 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Replace the optional-parameter signature with two explicit overloads: - original single-arg overload delegates to the new one (binary compat) - new overload takes logger + attachments without defaults Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The two focused tests (true includes, false excludes) already cover the filtering logic completely. The mixed-attachments test added no additional coverage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds an overloaded ViewHierarchyAttachment constructor accepting addToTransactions and forwards it to the base type, and plumbs the flag through the internal ScreenshotAttachment constructor. Addresses the PR review question about offering the flag consistently on derived attachment types. Co-Authored-By: Claude Opus 4.8 <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.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a8edc5d. Configure here.
Adds a test asserting that a null element in the attachments collection is skipped (not added as an envelope item) and that a warning is logged. Addresses the PR review coverage nitpick. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds an optional addToTransactions parameter to the test helper and uses it to shorten the AddToTransactionsTrue test, keeping it consistent with the AddToTransactionsFalse test. Addresses the PR review suggestion. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…t-add-to-transactions # Conflicts: # test/Sentry.Tests/SentryClientTests.cs
hint.Attachments is a mutable public collection, so it can contain a null entry. Filtering it with Where(a => a.AddToTransactions) dereferenced each element and threw a NullReferenceException, dropping the whole transaction before Envelope.FromTransaction could skip the null. The event and feedback paths already defer null handling to the envelope's IsNull guard; mirror that by letting null entries flow through the client-side filter instead of dereferencing them. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dingsdax
left a comment
There was a problem hiding this comment.
I guess this should get some changelog/docs updates too, implementation looks good, one comment about hint being possibly null
Added an explicit See my reply re the question about Hint nullability. |
Revert the addToTransactions plumbing on ScreenshotAttachment. The parameter had been added only to the private constructor, so nothing could set it. ScreenshotAttachment is internal and its content is always a JPEG screenshot, so there's no consumer for the flag; keeping it added dead surface area. Also drop the now-redundant private constructor and have the public constructor delegate straight to the base type. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the two FromTransaction overloads with a single method whose logger and attachments parameters default to null, matching the sibling FromEvent and FromFeedback factory methods. The parameterless-tail overload was only used in tests; all call sites bind to the collapsed method unchanged. This removes the FromTransaction(SentryTransaction) overload, which is a binary-breaking change for precompiled consumers. Closes #5397 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Summary
AddToTransactionsboolean property toSentryAttachment(defaults tofalse)SentryAttachment(type, content, fileName, contentType, addToTransactions)Envelope.FromTransactionnow accepts optionalattachmentsparameter and includes those withAddToTransactions = trueSentryClient.CaptureTransactionfilters attachments to only passAddToTransactions = trueones to the envelopeImplements #750. See also the Java reference implementation and the SDK spec.
Note
We didn't add this for Maui Screenshots since those get added automatically/internally by the Sentry SDK and only for Events and Feedback (never for transactions - which makes sense - we don't want to capture a screenshot every time a transaction is finished).
Docs
Changelog Entry
Attachments can now be sent with transactions by setting
AddToTransactionsonSentryAttachment#5182