Skip to content

feat: Add AddToTransactions to SentryAttachment#5182

Merged
jamescrosswell merged 12 commits into
mainfrom
feature/add-attachment-add-to-transactions
Jul 17, 2026
Merged

feat: Add AddToTransactions to SentryAttachment#5182
jamescrosswell merged 12 commits into
mainfrom
feature/add-attachment-add-to-transactions

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds AddToTransactions boolean property to SentryAttachment (defaults to false)
  • New constructor overload: SentryAttachment(type, content, fileName, contentType, addToTransactions)
  • Envelope.FromTransaction now accepts optional attachments parameter and includes those with AddToTransactions = true
  • SentryClient.CaptureTransaction filters attachments to only pass AddToTransactions = true ones to the envelope

Implements #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 AddToTransactions on SentryAttachment #5182

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>
@jamescrosswell
jamescrosswell requested a review from Flash0ver as a code owner May 4, 2026 04:11
@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.54%. Comparing base (7b09863) to head (2496a53).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry.Maui/Internal/ScreenshotAttachment.cs 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell
jamescrosswell marked this pull request as draft May 4, 2026 05:25
Comment thread src/Sentry/Protocol/Envelopes/Envelope.cs
jamescrosswell and others added 3 commits May 5, 2026 16:29
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>
@jamescrosswell
jamescrosswell marked this pull request as ready for review May 7, 2026 04:54
@jamescrosswell jamescrosswell linked an issue May 18, 2026 that may be closed by this pull request
Comment thread src/Sentry/Protocol/Envelopes/Envelope.cs Outdated
Comment thread src/Sentry/Protocol/Envelopes/Envelope.cs
Comment thread src/Sentry/Protocol/Envelopes/Envelope.cs
Comment thread src/Sentry/SentryAttachment.cs
Comment thread test/Sentry.Tests/SentryClientTests.cs Outdated
Comment thread src/Sentry/SentryAttachment.cs
Comment thread src/Sentry/SentryClient.cs Outdated
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>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 13, 2026

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

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.

Comment thread src/Sentry/SentryClient.cs Outdated
jamescrosswell and others added 2 commits July 13, 2026 14:28
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>
Comment thread src/Sentry/SentryClient.cs Outdated
jamescrosswell and others added 2 commits July 13, 2026 14:37
…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>
@jamescrosswell
jamescrosswell requested a review from Flash0ver July 13, 2026 05:01
@dingsdax
dingsdax requested review from bitsandfoxes and dingsdax and removed request for Flash0ver July 15, 2026 23:17
Comment thread src/Sentry/SentryClient.cs
@dingsdax
dingsdax self-requested a review July 15, 2026 23:35

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

I guess this should get some changelog/docs updates too, implementation looks good, one comment about hint being possibly null

@jamescrosswell

Copy link
Copy Markdown
Collaborator Author

I guess this should get some changelog/docs updates too, implementation looks good, one comment about hint being possibly null

Added an explicit ### Changelog Entry to the PR description (get's used by craft when publishing) and also linked to some draft docs (to be completed/reviewed separately).

See my reply re the question about Hint nullability.

@jamescrosswell
jamescrosswell requested a review from dingsdax July 16, 2026 04:00

@bitsandfoxes bitsandfoxes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Comment thread src/Sentry/Protocol/Envelopes/Envelope.cs
Comment thread src/Sentry.Maui/Internal/ScreenshotAttachment.cs Outdated
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>
@jamescrosswell
jamescrosswell merged commit f02bc53 into main Jul 17, 2026
52 checks passed
@jamescrosswell
jamescrosswell deleted the feature/add-attachment-add-to-transactions branch July 17, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collapse Envelope.FromTransaction overloads into a single method with optional parameters Add addToTransactions to Attachment

4 participants