-
-
Notifications
You must be signed in to change notification settings - Fork 241
feat: Add BeforeSendFeedback callback to inspect, modify, or drop user feedback before it's sent #5361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jamescrosswell
merged 3 commits into
getsentry:main
from
vladbrincoveanu:feat/4092-before-send-feedback-y
Jul 10, 2026
Merged
feat: Add BeforeSendFeedback callback to inspect, modify, or drop user feedback before it's sent #5361
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1035,6 +1035,116 @@ public void CaptureFeedback_EventDropped_SendsClientReport() | |
| _fixture.ClientReportRecorder.Received(1).RecordDiscardedEvent(expectedReason, DataCategory.Feedback); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureFeedback_BeforeSendFeedbackSet_CallbackInvokedAndMutationApplied() | ||
| { | ||
| //Arrange | ||
| var feedback = new SentryFeedback("Everything is great!"); | ||
| SentryEvent received = null; | ||
| _fixture.SentryOptions.SetBeforeSendFeedback((@event, _) => | ||
| { | ||
| received = @event; | ||
| @event.SetTag("scrubbed", "true"); | ||
| return @event; | ||
| }); | ||
| var sut = _fixture.GetSut(); | ||
|
|
||
| Envelope envelope = null; | ||
| sut.Worker.When(w => w.EnqueueEnvelope(Arg.Any<Envelope>())) | ||
| .Do(callback => envelope = callback.Arg<Envelope>()); | ||
|
|
||
| //Act | ||
| var id = sut.CaptureFeedback(feedback, out var result); | ||
|
|
||
| //Assert | ||
| result.Should().Be(CaptureFeedbackResult.Success); | ||
| id.Should().NotBe(SentryId.Empty); | ||
| received.Should().NotBeNull(); | ||
| received.Contexts.Feedback.Should().NotBeNull(); | ||
| received.Contexts.Feedback!.Message.Should().Be("Everything is great!"); | ||
| var item = envelope.Items.First(x => x.TryGetType() == EnvelopeItem.TypeValueFeedback); | ||
| var @event = (SentryEvent)((JsonSerializable)item.Payload).Source; | ||
| @event.Tags.Should().Contain(new KeyValuePair<string, string>("scrubbed", "true")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureFeedback_BeforeSendFeedbackSet_ReceivesHintFromCaller() | ||
| { | ||
| //Arrange | ||
| var feedback = new SentryFeedback("Everything is great!"); | ||
| var hint = new SentryHint(); | ||
| var attachment = AttachmentHelper.FakeAttachment("scrub-me.txt"); | ||
| hint.Attachments.Add(attachment); | ||
| SentryHint receivedHint = null; | ||
| _fixture.SentryOptions.SetBeforeSendFeedback((@event, h) => | ||
| { | ||
| receivedHint = h; | ||
| return @event; | ||
| }); | ||
| var sut = _fixture.GetSut(); | ||
|
|
||
| //Act | ||
| var id = sut.CaptureFeedback(feedback, out var result, null, hint); | ||
|
|
||
| //Assert | ||
| result.Should().Be(CaptureFeedbackResult.Success); | ||
| id.Should().NotBe(SentryId.Empty); | ||
| receivedHint.Should().BeSameAs(hint); | ||
| receivedHint.Attachments.Should().Contain(attachment); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureFeedback_BeforeSendFeedbackReturnsNull_FeedbackDropped() | ||
| { | ||
| //Arrange | ||
| var feedback = new SentryFeedback("Everything is great!"); | ||
| _fixture.SentryOptions.SetBeforeSendFeedback((SentryEvent _) => null); | ||
| var sut = _fixture.GetSut(); | ||
|
|
||
| //Act | ||
| var id = sut.CaptureFeedback(feedback, out var result); | ||
|
|
||
| //Assert | ||
| result.Should().Be(CaptureFeedbackResult.DroppedByBeforeSendFeedback); | ||
| id.Should().Be(SentryId.Empty); | ||
| _ = sut.Worker.DidNotReceive().EnqueueEnvelope(Arg.Any<Envelope>()); | ||
| _fixture.ClientReportRecorder.Received(1).RecordDiscardedEvent(DiscardReason.BeforeSend, DataCategory.Feedback); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureFeedback_BeforeSendFeedbackThrows_FeedbackDropped() | ||
| { | ||
| //Arrange | ||
| var feedback = new SentryFeedback("Everything is great!"); | ||
| _fixture.SentryOptions.SetBeforeSendFeedback((SentryEvent _) => throw new InvalidOperationException("boom")); | ||
| var sut = _fixture.GetSut(); | ||
|
|
||
| //Act | ||
| var id = sut.CaptureFeedback(feedback, out var result); | ||
|
|
||
| //Assert | ||
| result.Should().Be(CaptureFeedbackResult.DroppedByBeforeSendFeedback); | ||
| id.Should().Be(SentryId.Empty); | ||
| _ = sut.Worker.DidNotReceive().EnqueueEnvelope(Arg.Any<Envelope>()); | ||
| _fixture.ClientReportRecorder.Received(1).RecordDiscardedEvent(DiscardReason.BeforeSend, DataCategory.Feedback); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureFeedback_EnqueueFails_ReturnsUnknownError() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems unrelated to this PR but harmless... |
||
| { | ||
| //Arrange | ||
| var feedback = new SentryFeedback("Everything is great!"); | ||
| _fixture.BackgroundWorker.EnqueueEnvelope(Arg.Any<Envelope>()).Returns(false); | ||
| var sut = _fixture.GetSut(); | ||
|
|
||
| //Act | ||
| var id = sut.CaptureFeedback(feedback, out var result); | ||
|
|
||
| //Assert | ||
| result.Should().Be(CaptureFeedbackResult.UnknownError); | ||
| id.Should().Be(SentryId.Empty); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureFeedback_WithHint_HasHintAttachment() | ||
| { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a question than a comment, but I'm not sure if we need this overload. Originally we added an overload on the BeforeSend event when we wanted to introduce a variant that accepted a SentryHint parameter without that being a breaking change... we never made a conscious decision that we wanted two overloads of the callback though.
If we only had a single version of the callback that accepted both a SentryEvent and a SentryHint argument, users could easily ignore the second argument.
On the other hand, if we do that now for this callback,
SetBeforeSendFeedbackis then the odd one out (inconsistent)... so probably not something we want to do in this PR but something we could consider for all of the BeforeSend* callbacks as a breaking change in the next major:@Flash0ver @vladbrincoveanu what are your thoughts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These overloads are just adapters. They just use the SentryHint version and their docs hide half the feature.
I agree, we can batch mark them as [Obsolete] for a next minor and remove them in the future major, so users gets some warnings first. This could be another good starter ticket, for cleanups.
3 concerns:
1 suggestion:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably more effort that it's worth... The overloads don't add too much noise.
The main reason for the Hint parameter was to make it possible to pass in attachments... which I don't think make sense for metrics/logs (neither support attachments).