Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- The SDK now logs a `Warning` instead of an `Error` when being ratelimited ([#4927](https://github.com/getsentry/sentry-dotnet/pull/4927))
- Common tags such as `Environment` and `Release` are now correctly applied to CaptureFeedback events ([#4942](https://github.com/getsentry/sentry-dotnet/pull/4942))

## 6.2.0-alpha.0

Expand Down
1 change: 1 addition & 0 deletions src/Sentry/Internal/DataCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Sentry.Internal;
public static DataCategory Attachment = new("attachment");
public static DataCategory Default = new("default");
public static DataCategory Error = new("error");
public static DataCategory Feedback = new("feedback");
public static DataCategory Internal = new("internal");
public static DataCategory Security = new("security");
public static DataCategory Session = new("session");
Expand Down
5 changes: 3 additions & 2 deletions src/Sentry/Internal/SentryEventHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace Sentry.Internal;

internal static class SentryEventHelper
{
public static SentryEvent? ProcessEvent(SentryEvent? evt, IEnumerable<ISentryEventProcessor> processors, SentryHint? hint, SentryOptions options)
public static SentryEvent? ProcessEvent(SentryEvent? evt, IEnumerable<ISentryEventProcessor> processors,
SentryHint? hint, SentryOptions options, DataCategory dataCategory)
{
if (evt == null)
{
Expand All @@ -19,7 +20,7 @@ internal static class SentryEventHelper
processedEvent = processor.DoProcessEvent(processedEvent, effectiveHint);
if (processedEvent == null)
{
options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, DataCategory.Error);
options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, dataCategory);
options.LogInfo("Event dropped by processor {0}", processor.GetType().Name);
break;
}
Expand Down
15 changes: 12 additions & 3 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,20 @@ public SentryId CaptureFeedback(SentryFeedback feedback, out CaptureFeedbackResu
evt.Level = scope.Level;
}

if (SentryEventHelper.ProcessEvent(evt, scope.GetAllEventProcessors(), hint, _options, DataCategory.Feedback)
is not { } processedEvent)
{
_options.LogWarning("Feedback dropped by event processor");
result = CaptureFeedbackResult.UnknownError;
return SentryId.Empty; // Dropped by an event processor
}

var attachments = hint.Attachments.ToList();
var envelope = Envelope.FromFeedback(evt, _options.DiagnosticLogger, attachments, scope.SessionUpdate);
var envelope = Envelope.FromFeedback(processedEvent, _options.DiagnosticLogger, attachments, scope.SessionUpdate);
if (CaptureEnvelope(envelope))
{
result = CaptureFeedbackResult.Success;
return evt.EventId;
return processedEvent.EventId;
}
result = CaptureFeedbackResult.UnknownError;
return SentryId.Empty;
Expand Down Expand Up @@ -345,7 +353,8 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope)
}
}

if (SentryEventHelper.ProcessEvent(@event, scope.GetAllEventProcessors(), hint, _options) is not { } processedEvent)
if (SentryEventHelper.ProcessEvent(@event, scope.GetAllEventProcessors(), hint, _options, DataCategory.Error)
is not { } processedEvent)
{
return SentryId.Empty; // Dropped by an event processor
}
Expand Down
51 changes: 51 additions & 0 deletions test/Sentry.Tests/SentryClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,57 @@ public void CaptureFeedback_WithScope_ScopeCopiedToEvent()
Assert.Equal(scope.Breadcrumbs, @event.Breadcrumbs);
}

[Fact]
public void CaptureFeedback_EventProcessorApplied()
{
//Arrange
var feedback = new SentryFeedback("Everything is great!");
var eventProcessor = Substitute.For<ISentryEventProcessor>();
eventProcessor.Process(Arg.Any<SentryEvent>()).Returns(e =>
{
var evt = (SentryEvent)e[0];
evt.Environment = "testing 123";
return evt;
});
_fixture.SentryOptions.AddEventProcessor(eventProcessor);
var sut = _fixture.GetSut();

Envelope envelope = null;
sut.Worker.When(w => w.EnqueueEnvelope(Arg.Any<Envelope>()))
.Do(callback => envelope = callback.Arg<Envelope>());

//Act
var result = sut.CaptureFeedback(feedback);

//Assert
result.Should().NotBe(SentryId.Empty);
_ = sut.Worker.Received(1).EnqueueEnvelope(Arg.Any<Envelope>());
envelope.Should().NotBeNull();
envelope.Items.Should().Contain(item => item.TryGetType() == EnvelopeItem.TypeValueFeedback);
var item = envelope.Items.First(x => x.TryGetType() == EnvelopeItem.TypeValueFeedback);
var @event = (SentryEvent)((JsonSerializable)item.Payload).Source;
@event.Environment.Should().Be("testing 123");
}

[Fact]
public void CaptureFeedback_EventDropped_SendsClientReport()
{
//Arrange
var feedback = new SentryFeedback("Everything is great!");
var eventProcessor = Substitute.For<ISentryEventProcessor>();
eventProcessor.Process(Arg.Any<SentryEvent>()).Returns(_ => null);
_fixture.SentryOptions.AddEventProcessor(eventProcessor);
var sut = _fixture.GetSut();

//Act
var result = sut.CaptureFeedback(feedback);

//Assert
result.Should().Be(SentryId.Empty);
var expectedReason = DiscardReason.EventProcessor;
_fixture.ClientReportRecorder.Received(1).RecordDiscardedEvent(expectedReason, DataCategory.Feedback);
}

[Fact]
public void CaptureFeedback_WithHint_HasHintAttachment()
{
Expand Down
Loading