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 Hints to BeforeSendTransaction
  • Loading branch information
jamescrosswell committed May 8, 2023
commit 0f701eb0dabae0f5b2606f5c2fdecb143b3ec8fc
7 changes: 7 additions & 0 deletions src/Sentry/Extensibility/DisabledHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ public void CaptureTransaction(Transaction transaction)
{
}

/// <summary>
/// No-Op.
/// </summary>
public void CaptureTransaction(Transaction transaction, Hint? hint)
{
}

/// <summary>
/// No-Op.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Sentry/Extensibility/HubAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ public SentryId CaptureException(Exception exception)
public void CaptureTransaction(Transaction transaction)
=> SentrySdk.CaptureTransaction(transaction);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
[DebuggerStepThrough]
[EditorBrowsable(EditorBrowsableState.Never)]
public void CaptureTransaction(Transaction transaction, Hint? hint)
=> SentrySdk.CaptureTransaction(transaction, hint);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/Sentry/ISentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public interface ISentryClient
[EditorBrowsable(EditorBrowsableState.Never)]
void CaptureTransaction(Transaction transaction);

/// <summary>
/// Captures a transaction.
/// </summary>
/// <remarks>
/// Note: this method is NOT meant to be called from user code!
/// Instead, call <see cref="ISpan.Finish()"/> on the transaction.
/// </remarks>
/// <param name="transaction">The transaction.</param>
/// <param name="hint">
/// A hint providing extra context.
/// This will be available in callbacks prior to processing the transaction.
/// </param>
[EditorBrowsable(EditorBrowsableState.Never)]
void CaptureTransaction(Transaction transaction, Hint? hint);

/// <summary>
/// Captures a session update.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ public void CaptureUserFeedback(UserFeedback userFeedback)
}
}

public void CaptureTransaction(Transaction transaction)
public void CaptureTransaction(Transaction transaction) => CaptureTransaction(transaction, null);

public void CaptureTransaction(Transaction transaction, Hint? hint)
{
// Note: The hub should capture transactions even if it is disabled.
// This allows transactions to be reported as failed when they encountered an unhandled exception,
Expand Down Expand Up @@ -431,7 +433,7 @@ public void CaptureTransaction(Transaction transaction)
}
}

currentScope.Value.CaptureTransaction(processedTransaction);
currentScope.Value.CaptureTransaction(processedTransaction, hint);
}
catch (Exception e)
{
Expand Down
13 changes: 8 additions & 5 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ public void CaptureUserFeedback(UserFeedback userFeedback)
}

/// <inheritdoc />
public void CaptureTransaction(Transaction transaction)
public void CaptureTransaction(Transaction transaction) => CaptureTransaction(transaction, null);

/// <inheritdoc />
public void CaptureTransaction(Transaction transaction, Hint? hint)
{
if (transaction.SpanId.Equals(SpanId.Empty))
{
Expand Down Expand Up @@ -136,7 +139,7 @@ public void CaptureTransaction(Transaction transaction)
return;
}

var processedTransaction = BeforeSendTransaction(transaction);
var processedTransaction = BeforeSendTransaction(transaction, hint ?? new Hint());
if (processedTransaction is null) // Rejected transaction
{
_options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.BeforeSend, DataCategory.Transaction);
Expand All @@ -147,9 +150,9 @@ public void CaptureTransaction(Transaction transaction)
CaptureEnvelope(Envelope.FromTransaction(processedTransaction));
}

private Transaction? BeforeSendTransaction(Transaction transaction)
private Transaction? BeforeSendTransaction(Transaction transaction, Hint hint)
{
if (_options.BeforeSendTransaction is null)
if (_options.BeforeSendTransactionInternal is null)
{
return transaction;
}
Expand All @@ -158,7 +161,7 @@ public void CaptureTransaction(Transaction transaction)

try
{
return _options.BeforeSendTransaction?.Invoke(transaction);
return _options.BeforeSendTransactionInternal?.Invoke(transaction, hint);
}
catch (Exception e)
{
Expand Down
28 changes: 27 additions & 1 deletion src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ public void SetBeforeSend(Func<SentryEvent, Hint, SentryEvent?> beforeSend)
_beforeSend = beforeSend;
}

private Func<Transaction, Hint, Transaction?>? _beforeSendTransaction;

internal Func<Transaction, Hint, Transaction?>? BeforeSendTransactionInternal => _beforeSendTransaction;

/// <summary>
/// A callback to invoke before sending a transaction to Sentry
/// </summary>
Expand All @@ -349,7 +353,29 @@ public void SetBeforeSend(Func<SentryEvent, Hint, SentryEvent?> beforeSend)
/// a chance to inspect and/or modify the transaction before it's sent. If the transaction
/// should not be sent at all, return null from the callback.
/// </remarks>
public Func<Transaction, Transaction?>? BeforeSendTransaction { get; set; }
[Obsolete("This property will be removed in a future version. Use SetBeforeSendTransaction instead.")]
public Func<Transaction, Transaction?>? BeforeSendTransaction {
get => null;
set => _beforeSendTransaction = value is null ? null : (e, _) => value(e);
}

/// <summary>
/// Configures a callback to invoke before sending a transaction to Sentry
/// </summary>
/// <param name="beforeSendTransaction">The callback</param>
public void SetBeforeSendTransaction(Func<Transaction, Transaction?> beforeSendTransaction)
{
_beforeSendTransaction = (e, _) => beforeSendTransaction(e);
}

/// <summary>
/// Configures a callback to invoke before sending a transaction to Sentry
/// </summary>
/// <param name="beforeSendTransaction">The callback</param>
public void SetBeforeSendTransaction(Func<Transaction, Hint, Transaction?> beforeSendTransaction)
{
_beforeSendTransaction = beforeSendTransaction;
}

private Func<Breadcrumb, Hint, Breadcrumb?>? _beforeBreadcrumb;

Expand Down
12 changes: 12 additions & 0 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,18 @@ public static void CaptureUserFeedback(SentryId eventId, string email, string co
public static void CaptureTransaction(Transaction transaction)
=> CurrentHub.CaptureTransaction(transaction);

/// <summary>
/// Captures a transaction.
/// </summary>
/// <remarks>
/// Note: this method is NOT meant to be called from user code!
/// Instead, call <see cref="ISpan.Finish()"/> on the transaction.
/// </remarks>
[DebuggerStepThrough]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void CaptureTransaction(Transaction transaction, Hint? hint)
=> CurrentHub.CaptureTransaction(transaction, hint);

/// <summary>
/// Captures a session update.
/// </summary>
Expand Down
12 changes: 8 additions & 4 deletions test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public async Task Transactions_are_grouped_by_route()
sentryClient.Received(2).CaptureTransaction(
Arg.Is<Transaction>(transaction =>
transaction.Name == "GET /person/{id}" &&
transaction.NameSource == TransactionNameSource.Route));
transaction.NameSource == TransactionNameSource.Route),
Arg.Any<Hint>()
);
}

[Fact]
Expand Down Expand Up @@ -150,7 +152,9 @@ public async Task Transaction_is_started_automatically_from_incoming_trace_heade
t.TraceId == SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8") &&
t.ParentSpanId == SpanId.Parse("1000000000000000") &&
t.IsSampled == false
));
),
Arg.Any<Hint>()
);
}

[Theory]
Expand Down Expand Up @@ -554,7 +558,7 @@ public async Task Transaction_TransactionNameProviderSetSet_TransactionNameSet()
var expectedName = "My custom name";

var sentryClient = Substitute.For<ISentryClient>();
sentryClient.When(x => x.CaptureTransaction(Arg.Any<Transaction>()))
sentryClient.When(x => x.CaptureTransaction(Arg.Any<Transaction>(), Arg.Any<Hint>()))
.Do(callback => transaction = callback.Arg<Transaction>());
var options = new SentryAspNetCoreOptions
{
Expand Down Expand Up @@ -596,7 +600,7 @@ public async Task Transaction_TransactionNameProviderSetUnset_TransactionNameSet
Transaction transaction = null;

var sentryClient = Substitute.For<ISentryClient>();
sentryClient.When(x => x.CaptureTransaction(Arg.Any<Transaction>()))
sentryClient.When(x => x.CaptureTransaction(Arg.Any<Transaction>(), Arg.Any<Hint>()))
.Do(callback => transaction = callback.Arg<Transaction>());
var options = new SentryAspNetCoreOptions
{
Expand Down
9 changes: 9 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ namespace Sentry
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Hint? hint, Sentry.Scope? scope = null);
void CaptureSession(Sentry.SessionUpdate sessionUpdate);
void CaptureTransaction(Sentry.Transaction transaction);
void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint);
void CaptureUserFeedback(Sentry.UserFeedback userFeedback);
System.Threading.Tasks.Task FlushAsync(System.TimeSpan timeout);
}
Expand Down Expand Up @@ -478,6 +479,7 @@ namespace Sentry
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent? @event, Sentry.Hint? hint, Sentry.Scope? scope = null) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.Transaction transaction) { }
public void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public void CaptureUserFeedback(Sentry.UserFeedback userFeedback) { }
[System.Obsolete("Sentry client should not be explicitly disposed of. This method will be removed i" +
"n version 4.")]
Expand Down Expand Up @@ -591,6 +593,8 @@ namespace Sentry
public System.Func<Sentry.Breadcrumb, Sentry.Breadcrumb?>? BeforeBreadcrumb { get; set; }
[System.Obsolete("This property will be removed in a future version. Use SetBeforeSend instead.")]
public System.Func<Sentry.SentryEvent, Sentry.SentryEvent?>? BeforeSend { get; set; }
[System.Obsolete("This property will be removed in a future version. Use SetBeforeSendTransaction i" +
"nstead.")]
public System.Func<Sentry.Transaction, Sentry.Transaction?>? BeforeSendTransaction { get; set; }
public string? CacheDirectoryPath { get; set; }
public bool CaptureFailedRequests { get; set; }
Expand Down Expand Up @@ -647,6 +651,8 @@ namespace Sentry
public void SetBeforeBreadcrumb(System.Func<Sentry.Breadcrumb, Sentry.Hint, Sentry.Breadcrumb?> beforeBreadcrumb) { }
public void SetBeforeSend(System.Func<Sentry.SentryEvent, Sentry.SentryEvent?> beforeSend) { }
public void SetBeforeSend(System.Func<Sentry.SentryEvent, Sentry.Hint, Sentry.SentryEvent?> beforeSend) { }
public void SetBeforeSendTransaction(System.Func<Sentry.Transaction, Sentry.Transaction?> beforeSendTransaction) { }
public void SetBeforeSendTransaction(System.Func<Sentry.Transaction, Sentry.Hint, Sentry.Transaction?> beforeSendTransaction) { }
}
public static class SentryOptionsExtensions
{
Expand Down Expand Up @@ -712,6 +718,7 @@ namespace Sentry
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
public static void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public static void CaptureTransaction(Sentry.Transaction transaction) { }
public static void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public static void CaptureUserFeedback(Sentry.UserFeedback userFeedback) { }
public static void CaptureUserFeedback(Sentry.SentryId eventId, string email, string comments, string? name = null) { }
[System.Obsolete("WARNING: This method deliberately causes a crash, and should not be used in a rea" +
Expand Down Expand Up @@ -1189,6 +1196,7 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Hint? hint, Sentry.Scope? scope = null) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.Transaction transaction) { }
public void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public void CaptureUserFeedback(Sentry.UserFeedback userFeedback) { }
public void ConfigureScope(System.Action<Sentry.Scope> configureScope) { }
public System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope) { }
Expand Down Expand Up @@ -1227,6 +1235,7 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureException(System.Exception exception) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.Transaction transaction) { }
public void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public void CaptureUserFeedback(Sentry.UserFeedback sentryUserFeedback) { }
public void ConfigureScope(System.Action<Sentry.Scope> configureScope) { }
public System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ namespace Sentry
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Hint? hint, Sentry.Scope? scope = null);
void CaptureSession(Sentry.SessionUpdate sessionUpdate);
void CaptureTransaction(Sentry.Transaction transaction);
void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint);
void CaptureUserFeedback(Sentry.UserFeedback userFeedback);
System.Threading.Tasks.Task FlushAsync(System.TimeSpan timeout);
}
Expand Down Expand Up @@ -478,6 +479,7 @@ namespace Sentry
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent? @event, Sentry.Hint? hint, Sentry.Scope? scope = null) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.Transaction transaction) { }
public void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public void CaptureUserFeedback(Sentry.UserFeedback userFeedback) { }
[System.Obsolete("Sentry client should not be explicitly disposed of. This method will be removed i" +
"n version 4.")]
Expand Down Expand Up @@ -592,6 +594,8 @@ namespace Sentry
public System.Func<Sentry.Breadcrumb, Sentry.Breadcrumb?>? BeforeBreadcrumb { get; set; }
[System.Obsolete("This property will be removed in a future version. Use SetBeforeSend instead.")]
public System.Func<Sentry.SentryEvent, Sentry.SentryEvent?>? BeforeSend { get; set; }
[System.Obsolete("This property will be removed in a future version. Use SetBeforeSendTransaction i" +
"nstead.")]
public System.Func<Sentry.Transaction, Sentry.Transaction?>? BeforeSendTransaction { get; set; }
public string? CacheDirectoryPath { get; set; }
public bool CaptureFailedRequests { get; set; }
Expand Down Expand Up @@ -648,6 +652,8 @@ namespace Sentry
public void SetBeforeBreadcrumb(System.Func<Sentry.Breadcrumb, Sentry.Hint, Sentry.Breadcrumb?> beforeBreadcrumb) { }
public void SetBeforeSend(System.Func<Sentry.SentryEvent, Sentry.SentryEvent?> beforeSend) { }
public void SetBeforeSend(System.Func<Sentry.SentryEvent, Sentry.Hint, Sentry.SentryEvent?> beforeSend) { }
public void SetBeforeSendTransaction(System.Func<Sentry.Transaction, Sentry.Transaction?> beforeSendTransaction) { }
public void SetBeforeSendTransaction(System.Func<Sentry.Transaction, Sentry.Hint, Sentry.Transaction?> beforeSendTransaction) { }
}
public static class SentryOptionsExtensions
{
Expand Down Expand Up @@ -713,6 +719,7 @@ namespace Sentry
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
public static void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public static void CaptureTransaction(Sentry.Transaction transaction) { }
public static void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public static void CaptureUserFeedback(Sentry.UserFeedback userFeedback) { }
public static void CaptureUserFeedback(Sentry.SentryId eventId, string email, string comments, string? name = null) { }
[System.Obsolete("WARNING: This method deliberately causes a crash, and should not be used in a rea" +
Expand Down Expand Up @@ -1190,6 +1197,7 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Hint? hint, Sentry.Scope? scope = null) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.Transaction transaction) { }
public void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public void CaptureUserFeedback(Sentry.UserFeedback userFeedback) { }
public void ConfigureScope(System.Action<Sentry.Scope> configureScope) { }
public System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope) { }
Expand Down Expand Up @@ -1228,6 +1236,7 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureException(System.Exception exception) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.Transaction transaction) { }
public void CaptureTransaction(Sentry.Transaction transaction, Sentry.Hint? hint) { }
public void CaptureUserFeedback(Sentry.UserFeedback sentryUserFeedback) { }
public void ConfigureScope(System.Action<Sentry.Scope> configureScope) { }
public System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope) { }
Expand Down
Loading