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
Prev Previous commit
Next Next commit
Added hint support for Transaction/Event processors
  • Loading branch information
jamescrosswell committed May 9, 2023
commit aa6d91e9828813d072a2a85dd57cf56f825bd51d
20 changes: 20 additions & 0 deletions src/Sentry/Extensibility/IContextualSentryEventProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Sentry.Extensibility;

/// <summary>
/// Process a SentryEvent during the prepare phase.
/// </summary>
public interface IContextualSentryEventProcessor: ISentryEventProcessor
{
/// <summary>
/// Process the <see cref="SentryEvent"/>
/// </summary>
/// <param name="event">The event to process</param>
/// <param name="hint">A <see cref="Hint"/> with context that may be useful prior to sending the event</param>
/// <return>The processed event or <c>null</c> if the event was dropped.</return>
/// <remarks>
/// The event returned can be the same instance received or a new one.
/// Returning null will stop the processing pipeline so that the event will neither be processed by
/// additional event processors or sent to Sentry.
/// </remarks>
SentryEvent? Process(SentryEvent @event, Hint hint);
}
19 changes: 19 additions & 0 deletions src/Sentry/Extensibility/IContextualSentryTransactionProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Sentry.Extensibility;

/// <summary>
/// Process a <see cref="Transaction"/> during the prepare phase.
/// </summary>
public interface IContextualSentryTransactionProcessor: ISentryTransactionProcessor
{
/// <summary>
/// Process the <see cref="Transaction"/>
/// </summary>
/// <param name="transaction">The Transaction to process</param>
/// <param name="hint">A <see cref="Hint"/> with context that may be useful prior to sending the transaction</param>
/// <remarks>
/// The transaction returned can be the same instance received or a new one.
/// Returning null will stop the processing pipeline.
/// Meaning the transaction should no longer be processed nor send.
/// </remarks>
Transaction? Process(Transaction transaction, Hint hint);
}
12 changes: 11 additions & 1 deletion src/Sentry/Extensibility/ISentryEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ public interface ISentryEventProcessor
/// Meaning the event should no longer be processed nor send.
/// </remarks>
SentryEvent? Process(SentryEvent @event);
}
}

internal static class ISentryEventProcessorExtensions
{
internal static SentryEvent? DoProcessEvent(this ISentryEventProcessor processor, SentryEvent @event, Hint hint)
{
return (processor is IContextualSentryEventProcessor contextualProcessor)
? contextualProcessor.Process(@event, hint)
: processor.Process(@event);
}
}
12 changes: 11 additions & 1 deletion src/Sentry/Extensibility/ISentryTransactionProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Sentry.Extensibility;
namespace Sentry.Extensibility;

/// <summary>
/// Process a <see cref="Transaction"/> during the prepare phase.
Expand All @@ -16,3 +16,13 @@ public interface ISentryTransactionProcessor
/// </remarks>
Transaction? Process(Transaction transaction);
}

internal static class ISentryTransactionProcessorExtensions
{
internal static Transaction? DoProcessTransaction(this ISentryTransactionProcessor processor, Transaction transaction, Hint hint)
{
return (processor is IContextualSentryTransactionProcessor contextualProcessor)
? contextualProcessor.Process(transaction, hint)
: processor.Process(transaction);
}
}
2 changes: 1 addition & 1 deletion src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public void CaptureTransaction(Transaction transaction, Hint? hint)
{
foreach (var processor in scope.GetAllTransactionProcessors())
{
processedTransaction = processor.Process(transaction);
processedTransaction = processor.DoProcessTransaction(transaction, hint);
if (processedTransaction == null)
{
_options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, DataCategory.Transaction);
Expand Down
3 changes: 2 additions & 1 deletion src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ private SentryId DoSendEvent(SentryEvent @event, Hint? hint, Scope? scope)

foreach (var processor in scope.GetAllEventProcessors())
{
processedEvent = processor.Process(processedEvent);
processedEvent = processor.DoProcessEvent(processedEvent, hint);

if (processedEvent == null)
{
_options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, DataCategory.Error);
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/SentryOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,3 @@ internal static void SetupLogging(this SentryOptions options)
return options.TryGetDsnSpecificCacheDirectoryPath();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void UseSentry_OriginalEventExceptionProcessor_StillAvailable()

var sut = _fixture.GetSut();


_ = sut.UseSentry();

var missing = originalProviders.Except(_fixture.SentryAspNetCoreOptions.ExceptionProcessorsProviders);
Expand Down
8 changes: 4 additions & 4 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1255,13 +1255,13 @@ namespace Sentry.Extensibility
bool EnqueueEnvelope(Sentry.Protocol.Envelopes.Envelope envelope);
System.Threading.Tasks.Task FlushAsync(System.TimeSpan timeout);
}
public interface IContextualSentryEventProcessor
public interface IContextualSentryEventProcessor : Sentry.Extensibility.ISentryEventProcessor
{
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint? hint);
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint hint);
}
public interface IContextualSentryTransactionProcessor
public interface IContextualSentryTransactionProcessor : Sentry.Extensibility.ISentryTransactionProcessor
{
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint? hint);
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint hint);
}
public interface IDiagnosticLogger
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,13 +1256,13 @@ namespace Sentry.Extensibility
bool EnqueueEnvelope(Sentry.Protocol.Envelopes.Envelope envelope);
System.Threading.Tasks.Task FlushAsync(System.TimeSpan timeout);
}
public interface IContextualSentryEventProcessor
public interface IContextualSentryEventProcessor : Sentry.Extensibility.ISentryEventProcessor
{
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint? hint);
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint hint);
}
public interface IContextualSentryTransactionProcessor
public interface IContextualSentryTransactionProcessor : Sentry.Extensibility.ISentryTransactionProcessor
{
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint? hint);
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint hint);
}
public interface IDiagnosticLogger
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,13 +1256,13 @@ namespace Sentry.Extensibility
bool EnqueueEnvelope(Sentry.Protocol.Envelopes.Envelope envelope);
System.Threading.Tasks.Task FlushAsync(System.TimeSpan timeout);
}
public interface IContextualSentryEventProcessor
public interface IContextualSentryEventProcessor : Sentry.Extensibility.ISentryEventProcessor
{
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint? hint);
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint hint);
}
public interface IContextualSentryTransactionProcessor
public interface IContextualSentryTransactionProcessor : Sentry.Extensibility.ISentryTransactionProcessor
{
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint? hint);
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint hint);
}
public interface IDiagnosticLogger
{
Expand Down
8 changes: 4 additions & 4 deletions test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1254,13 +1254,13 @@ namespace Sentry.Extensibility
bool EnqueueEnvelope(Sentry.Protocol.Envelopes.Envelope envelope);
System.Threading.Tasks.Task FlushAsync(System.TimeSpan timeout);
}
public interface IContextualSentryEventProcessor
public interface IContextualSentryEventProcessor : Sentry.Extensibility.ISentryEventProcessor
{
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint? hint);
Sentry.SentryEvent? Process(Sentry.SentryEvent @event, Sentry.Hint hint);
}
public interface IContextualSentryTransactionProcessor
public interface IContextualSentryTransactionProcessor : Sentry.Extensibility.ISentryTransactionProcessor
{
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint? hint);
Sentry.Transaction? Process(Sentry.Transaction transaction, Sentry.Hint hint);
}
public interface IDiagnosticLogger
{
Expand Down
43 changes: 41 additions & 2 deletions test/Sentry.Tests/HubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ public void CaptureTransaction_HubEnabled(bool enabled)
}

[Fact]
public void CaptureTransaction_Provides_Hint_To_Client()
public void CaptureTransaction_Client_Gets_Hint()
{
// Arrange
var hub = _fixture.GetSut();
Expand All @@ -1144,7 +1144,7 @@ public void CaptureTransaction_Provides_Hint_To_Client()
}

[Fact]
public void CaptureTransaction_Hint_Gets_Attachments()
public void CaptureTransaction_Client_Gets_ScopeAttachments()
{
// Arrange
var hub = _fixture.GetSut();
Expand All @@ -1171,6 +1171,45 @@ public void CaptureTransaction_Hint_Gets_Attachments()
hint.Attachments.Should().Contain(attachments);
}

[Fact]
public void CaptureTransaction_EventProcessor_Gets_Hint()
{
// Arrange
var processor = Substitute.For<IContextualSentryTransactionProcessor>();
processor.Process(Arg.Any<Transaction>(), Arg.Any<Hint>()).Returns(new Transaction("name", "operation"));
_fixture.Options.AddTransactionProcessor(processor);

// Act
var hub = _fixture.GetSut();
var transaction = hub.StartTransaction("test", "test");
transaction.Finish();

// Assert
processor.Received(1).Process(Arg.Any<Transaction>(), Arg.Any<Hint>());
}

[Fact]
public void CaptureTransaction_EventProcessor_Gets_ScopeAttachments()
{
// Arrange
var processor = Substitute.For<IContextualSentryTransactionProcessor>();
Hint hint = null;
processor.Process(Arg.Any<Transaction>(), Arg.Do<Hint>(h => hint = h)).Returns(new Transaction("name", "operation"));
_fixture.Options.AddTransactionProcessor(processor);

List<Attachment> attachments = new List<Attachment> { AttachmentHelper.FakeAttachment("foo.txt") };
var hub = _fixture.GetSut();
hub.ConfigureScope(s => s.AddAttachment(attachments[0]));

// Act
var transaction = hub.StartTransaction("test", "test");
transaction.Finish();

// Assert
hint.Should().NotBeNull();
hint.Attachments.Should().Contain(attachments);
}

#if ANDROID && CI_BUILD
// TODO: Test is flaky in CI
[SkippableTheory(typeof(NSubstitute.Exceptions.ReceivedCallsException))]
Expand Down
42 changes: 40 additions & 2 deletions test/Sentry.Tests/SentryClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FluentAssertions.Execution;
using Sentry.Internal.Http;
using BackgroundWorker = Sentry.Internal.BackgroundWorker;

Expand Down Expand Up @@ -320,7 +321,7 @@ public void CaptureEvent_BeforeSend_GetsHint()
}

[Fact]
public void CaptureEvent_Add_ScopeAttachments_To_Hint()
public void CaptureEvent_BeforeSend_Gets_ScopeAttachments()
{
// Arrange
Hint hint = null;
Expand All @@ -343,7 +344,44 @@ public void CaptureEvent_Add_ScopeAttachments_To_Hint()
}

[Fact]
public void CaptureEvent_BeforeEvent_ModifyEvent()
public void CaptureEvent_EventProcessor_Gets_Hint()
{
// Arrange
var processor = Substitute.For<IContextualSentryEventProcessor>();
processor.Process(Arg.Any<SentryEvent>(), Arg.Any<Hint>()).Returns(new SentryEvent());
_fixture.SentryOptions.AddEventProcessor(processor);

// Act
var sut = _fixture.GetSut();
_ = sut.CaptureEvent(new SentryEvent());

// Assert
processor.Received(1).Process(Arg.Any<SentryEvent>(), Arg.Any<Hint>());
}

[Fact]
public void CaptureEvent_EventProcessor_Gets_ScopeAttachments()
{
// Arrange
var processor = Substitute.For<IContextualSentryEventProcessor>();
Hint hint = null;
processor.Process(Arg.Any<SentryEvent>(), Arg.Do<Hint>(h => hint = h)).Returns(new SentryEvent());
_fixture.SentryOptions.AddEventProcessor(processor);

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

// Act
var sut = _fixture.GetSut();
_ = sut.CaptureEvent(new SentryEvent(), scope);

// Assert
hint.Should().NotBeNull();
hint.Attachments.Should().Contain(scope.Attachments);
}

[Fact]
public void CaptureEvent_BeforeSend_ModifyEvent()
{
SentryEvent received = null;
_fixture.SentryOptions.SetBeforeSend((e, _) => received = e);
Expand Down