Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
556ba4c
Added SentryOptions.SetBeforeSend
jamescrosswell May 2, 2023
a713108
Added tests for new CaptureHint overloads taking a Hint parameter
jamescrosswell May 2, 2023
36699e8
Failed requests add a Hint for the HttpResponseMessage
jamescrosswell May 2, 2023
baed55b
Added BeforeBreadcrumb Hint support (for breadcrumbs on the scope only)
jamescrosswell May 3, 2023
836ac09
- Fixed ScopeExtensionTests
jamescrosswell May 4, 2023
7b4efa1
Added stub of Android platform code to enable builds to complete
jamescrosswell May 4, 2023
52e5a33
Sentry.Samples.Console.Customized now demonstrates using hints with b…
jamescrosswell May 4, 2023
baee2ca
Added missing XML docs on Hint constructors
jamescrosswell May 4, 2023
d3dae05
Updated MiddlewareLoggerIntegration tests to account for modified imp…
jamescrosswell May 4, 2023
fb6e9cf
Updated verified tests for CaptureTransaction_BeforeSendTransactionTh…
jamescrosswell May 4, 2023
d211548
Tail chasing Verify test errors
jamescrosswell May 4, 2023
6c9be76
Merge branch 'main' into feat/hint-before-send
mattjohnsonpint May 6, 2023
c1c2777
Update CHANGELOG.md
mattjohnsonpint May 6, 2023
eded3b6
Fix iOS compilation issue
mattjohnsonpint May 6, 2023
6d78761
Moved hint data from base Hint class to Items property, for clarity
jamescrosswell May 7, 2023
9142abf
Added XML docs for Hint.Items property
jamescrosswell May 7, 2023
8868e47
Updated Customized console sample to use new Hint
jamescrosswell May 7, 2023
0f701eb
- Added Hints to BeforeSendTransaction
jamescrosswell May 8, 2023
25b61f4
Attachments from the Scope get included in Hints before adding Bookma…
jamescrosswell May 9, 2023
aa6d91e
Added hint support for Transaction/Event processors
jamescrosswell May 9, 2023
aa3750f
Merge remote-tracking branch 'getsentry/main' into feat/hint-before-send
jamescrosswell May 9, 2023
860af91
- Renamed Contextual processors to ProcessorWithHint (more specific)
jamescrosswell May 9, 2023
f27a650
Merge remote-tracking branch 'origin/main' into feat/hint-before-send
jamescrosswell May 10, 2023
afb18bd
Merge branch 'main' into feat/hint-before-send
mattjohnsonpint May 15, 2023
d02f33a
Add overloads without hints
mattjohnsonpint May 15, 2023
e382114
Cleanup Hint. Just expose Attachments, not AddAttachments.
mattjohnsonpint May 15, 2023
c3fdad4
Update API snapshots
mattjohnsonpint May 15, 2023
13c70d6
Ensure hint modifications to attachments are sent
mattjohnsonpint May 15, 2023
af95623
Update CHANGELOG.md
mattjohnsonpint May 15, 2023
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
7 changes: 7 additions & 0 deletions src/Sentry/Protocol/Envelopes/Envelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ public static Envelope FromEvent(
{
foreach (var attachment in attachments)
{
// Safety check, in case the user forcefully added a null attachment.
if (attachment.IsNull())
{
logger?.LogWarning("Encountered a null attachment. Skipping.");
continue;
}

try
{
// We pull the stream out here so we can length check
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ private SentryId DoSendEvent(SentryEvent @event, Hint? hint, Scope? scope)
return SentryId.Empty;
}

return CaptureEnvelope(Envelope.FromEvent(processedEvent, _options.DiagnosticLogger, scope.Attachments, scope.SessionUpdate))
? processedEvent.EventId
: SentryId.Empty;
var attachments = hint.Attachments.ToList();
var envelope = Envelope.FromEvent(processedEvent, _options.DiagnosticLogger, attachments, scope.SessionUpdate);
return CaptureEnvelope(envelope) ? processedEvent.EventId : SentryId.Empty;
}

private IReadOnlyCollection<Exception>? ApplyExceptionFilters(Exception? exception)
Expand Down
88 changes: 86 additions & 2 deletions test/Sentry.Tests/SentryClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions.Execution;
using Sentry.Internal.Http;
using BackgroundWorker = Sentry.Internal.BackgroundWorker;

Expand Down Expand Up @@ -368,7 +367,7 @@ public void CaptureEvent_EventProcessor_Gets_ScopeAttachments()
processor.Process(Arg.Any<SentryEvent>(), Arg.Do<Hint>(h => hint = h)).Returns(new SentryEvent());
_fixture.SentryOptions.AddEventProcessor(processor);

Scope scope = new Scope(_fixture.SentryOptions);
var scope = new Scope(_fixture.SentryOptions);
scope.AddAttachment(AttachmentHelper.FakeAttachment("foo.txt"));

// Act
Expand All @@ -380,6 +379,91 @@ public void CaptureEvent_EventProcessor_Gets_ScopeAttachments()
hint.Attachments.Should().Contain(scope.Attachments);
}

[Fact]
public void CaptureEvent_Gets_ScopeAttachments()
{
// Arrange
var scope = new Scope(_fixture.SentryOptions);
scope.AddAttachment(AttachmentHelper.FakeAttachment("foo.txt"));
scope.AddAttachment(AttachmentHelper.FakeAttachment("bar.txt"));

var sut = _fixture.GetSut();

// Act
sut.CaptureEvent(new SentryEvent(), scope);

// Assert
sut.Worker.Received(1).EnqueueEnvelope(Arg.Is<Envelope>(envelope =>
envelope.Items.Count(item => item.TryGetType() == "attachment") == 2));
}

[Fact]
public void CaptureEvent_Gets_HintAttachments()
{
// Arrange
var scope = new Scope(_fixture.SentryOptions);
_fixture.SentryOptions.SetBeforeSend((e, h) => {
h.Attachments.Add(AttachmentHelper.FakeAttachment("foo.txt"));
h.Attachments.Add(AttachmentHelper.FakeAttachment("bar.txt"));
return e;
});

var sut = _fixture.GetSut();

// Act
sut.CaptureEvent(new SentryEvent(), scope);

// Assert
sut.Worker.Received(1).EnqueueEnvelope(Arg.Is<Envelope>(envelope =>
envelope.Items.Count(item => item.TryGetType() == "attachment") == 2));
}

[Fact]
public void CaptureEvent_Gets_ScopeAndHintAttachments()
{
// Arrange
var scope = new Scope(_fixture.SentryOptions);
scope.AddAttachment(AttachmentHelper.FakeAttachment("foo.txt"));
_fixture.SentryOptions.SetBeforeSend((e, h) => {
h.Attachments.Add(AttachmentHelper.FakeAttachment("bar.txt"));
return e;
});

var sut = _fixture.GetSut();

// Act
sut.CaptureEvent(new SentryEvent(), scope);

// Assert
sut.Worker.Received(1).EnqueueEnvelope(Arg.Is<Envelope>(envelope =>
envelope.Items.Count(item => item.TryGetType() == "attachment") == 2));
}

[Fact]
public void CaptureEvent_CanRemove_ScopetAttachment()
{
// Arrange
var scope = new Scope(_fixture.SentryOptions);
scope.AddAttachment(AttachmentHelper.FakeAttachment("foo.txt"));
scope.AddAttachment(AttachmentHelper.FakeAttachment("bar.txt"));
_fixture.SentryOptions.SetBeforeSend((e, h) =>
{
var attachment = h.Attachments.FirstOrDefault(a => a.FileName == "bar.txt");
h.Attachments.Remove(attachment);

return e;
});

var sut = _fixture.GetSut();

// Act
sut.CaptureEvent(new SentryEvent(), scope);

// Assert
sut.Worker.Received(1).EnqueueEnvelope(Arg.Is<Envelope>(envelope =>
envelope.Items.Count(item => item.TryGetType() == "attachment") == 1));
}

[Fact]
public void CaptureEvent_BeforeSend_ModifyEvent()
{
Expand Down