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
> ℹ️ **Note** > > This PR body was truncated due to platform limits. This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [Sentry.Maui](https://sentry.io/) ([source](https://github.com/getsentry/sentry-dotnet)) | `6.7.0` → `6.8.0` |  |  | --- ### Release Notes <details> <summary>getsentry/sentry-dotnet (Sentry.Maui)</summary> ### [`v6.8.0`](https://github.com/getsentry/sentry-dotnet/blob/HEAD/CHANGELOG.md#680) [Compare Source](getsentry/sentry-dotnet@6.7.0...6.8.0) ##### Features ✨ ##### Logs - feat(logs): add `log4net` integration by [@​Flash0ver](https://github.com/Flash0ver) in [#​5172](getsentry/sentry-dotnet#5172) - feat(logs): add `NLog` integration by [@​Flash0ver](https://github.com/Flash0ver) in [#​5176](getsentry/sentry-dotnet#5176) ##### Other - feat(serilog): support restrictedToMinimumLevel when configuring Serilog in code by [@​jamescrosswell](https://github.com/jamescrosswell) in [#​5181](getsentry/sentry-dotnet#5181) - Attachments can now be sent with transactions by setting `AddToTransactions` on `SentryAttachment` [#​5182](getsentry/sentry-dotnet#5182) by [@​jamescrosswell](https://github.com/jamescrosswell) in [#​5182](getsentry/sentry-dotnet#5182) - Added `SentrySdk.RecordTransaction` to record already-completed transactions and spans (e.g. replayed through a proxy) [#​5333](getsentry/sentry-dotnet#5333) by [@​jamescrosswell](https://github.com/jamescrosswell) in [#​5333](getsentry/sentry-dotnet#5333) - The `Environment` set on the `Scope` now gets synchronized to the native layers (`sentry-cocoa` and `sentry-native`) by [@​bitsandfoxes](https://github.com/bitsandfoxes) in [#​5365](getsentry/sentry-dotnet#5365) ##### Fixes 🐛 - fix: `SentrySpanProcessor` no longer leaks spans whose Activity never ends (e.g. aborted requests); the Activity is now held via a `WeakReference` so orphaned spans are pruned once it is garbage-collected. by [@​Ermabo](https://github.com/Ermabo) in [#​5393](getsentry/sentry-dotnet#5393) - The SDK was incorrectly ignoring server rate limits for errors, check-ins, and logs by [@​jamescrosswell](https://github.com/jamescrosswell) in [#​5412](getsentry/sentry-dotnet#5412) - fix: BackpressureMonitor.Dispose() no longer deadlocks on single-threaded targets by [@​jamescrosswell](https://git...

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