Skip to content

Added CaptureFeedback overload with configureScope parameter #4073

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Added `CaptureFeedback` overload with `configureScope` parameter ([#4073](https://github.com/getsentry/sentry-dotnet/pull/4073))

### Fixes

- Sentry Java SDK dependencies are now detected and included in the Android bindings ([#4079](https://github.com/getsentry/sentry-dotnet/pull/4079))
Expand Down
14 changes: 14 additions & 0 deletions src/Sentry/Extensibility/DisabledHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ public bool CaptureEnvelope(Envelope envelope)
/// </summary>
public SentryId CaptureEvent(SentryEvent evt, Scope? scope = null, SentryHint? hint = null) => SentryId.Empty;

/// <summary>
/// No-Op.
/// </summary>
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope)
{
}

/// <summary>
/// No-Op.
/// </summary>
public void CaptureFeedback(SentryFeedback feedback, SentryHint? hint, Action<Scope> configureScope)
{
}

/// <summary>
/// No-Op.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/Sentry/Extensibility/HubAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ public SentryId CaptureEvent(SentryEvent evt, Scope? scope)
public SentryId CaptureEvent(SentryEvent evt, Scope? scope, SentryHint? hint = null)
=> SentrySdk.CaptureEvent(evt, scope, hint);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
[DebuggerStepThrough]
[EditorBrowsable(EditorBrowsableState.Never)]
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope)
=> SentrySdk.CaptureFeedback(feedback, configureScope);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
[DebuggerStepThrough]
[EditorBrowsable(EditorBrowsableState.Never)]
public void CaptureFeedback(SentryFeedback feedback, SentryHint? hint, Action<Scope> configureScope)
=> SentrySdk.CaptureFeedback(feedback, hint, configureScope);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/Sentry/IHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,19 @@ public TransactionContext ContinueTrace(
/// <param name="configureScope">The callback to configure the scope.</param>
/// <returns></returns>
public SentryId CaptureEvent(SentryEvent evt, SentryHint? hint, Action<Scope> configureScope);

/// <summary>
/// Captures feedback from the user.
/// </summary>
/// <param name="feedback">The feedback to send to Sentry.</param>
/// <param name="configureScope">Callback method to configure the scope.</param>
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope);

/// <summary>
/// Captures feedback from the user.
/// </summary>
/// <param name="feedback">The feedback to send to Sentry.</param>
/// <param name="hint">An optional hint providing high level context for the source of the event, including attachments</param>
/// <param name="configureScope">Callback method to configure the scope.</param>
public void CaptureFeedback(SentryFeedback feedback, SentryHint? hint, Action<Scope> configureScope);
}
34 changes: 32 additions & 2 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,45 @@ private SentryId CaptureEvent(SentryEvent evt, SentryHint? hint, Scope scope)
}
}

public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope) =>
CaptureFeedback(feedback, null, configureScope);

public void CaptureFeedback(SentryFeedback feedback, SentryHint? hint, Action<Scope> configureScope)
{
if (!IsEnabled)
{
return;
}

try
{
var clonedScope = CurrentScope.Clone();
configureScope(clonedScope);

CaptureFeedback(feedback, clonedScope, hint);
}
catch (Exception e)
{
_options.LogError(e, "Failure to capture feedback");
}
}

public void CaptureFeedback(SentryFeedback feedback, Scope? scope = null, SentryHint? hint = null)
{
if (!IsEnabled)
{
return;
}

scope ??= CurrentScope;
CurrentClient.CaptureFeedback(feedback, scope, hint);
try
{
scope ??= CurrentScope;
CurrentClient.CaptureFeedback(feedback, scope, hint);
}
catch (Exception e)
{
_options.LogError(e, "Failure to capture feedback");
}
}

#if MEMORY_DUMP_SUPPORTED
Expand Down
14 changes: 14 additions & 0 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,20 @@ public static SentryId CaptureMessage(string message, SentryLevel level = Sentry
public static SentryId CaptureMessage(string message, Action<Scope> configureScope, SentryLevel level = SentryLevel.Info)
=> CurrentHub.CaptureMessage(message, configureScope, level);

/// <summary>
/// Captures feedback from the user.
/// </summary>
[DebuggerStepThrough]
public static void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope)
=> CurrentHub.CaptureFeedback(feedback, configureScope);

/// <summary>
/// Captures feedback from the user.
/// </summary>
[DebuggerStepThrough]
public static void CaptureFeedback(SentryFeedback feedback, SentryHint? hint, Action<Scope> configureScope)
=> CurrentHub.CaptureFeedback(feedback, hint, configureScope);

/// <summary>
/// Captures feedback from the user.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ namespace Sentry
void BindException(System.Exception exception, Sentry.ISpan span);
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope);
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope);
void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
Sentry.TransactionContext ContinueTrace(Sentry.SentryTraceHeader? traceHeader, Sentry.BaggageHeader? baggageHeader, string? name = null, string? operation = null);
Sentry.TransactionContext ContinueTrace(string? traceHeader, string? baggageHeader, string? name = null, string? operation = null);
void EndSession(Sentry.SessionEndStatus status = 0);
Expand Down Expand Up @@ -823,7 +825,9 @@ namespace Sentry
public static Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public static Sentry.SentryId CaptureException(System.Exception exception) { }
public static Sentry.SentryId CaptureException(System.Exception exception, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(string message, string? contactEmail = null, string? name = null, string? replayId = null, string? url = null, Sentry.SentryId? associatedEventId = default, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public static Sentry.SentryId CaptureMessage(string message, Sentry.SentryLevel level = 1) { }
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
Expand Down Expand Up @@ -1333,7 +1337,9 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
Expand Down Expand Up @@ -1379,7 +1385,9 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope, Sentry.SentryHint? hint = null) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public Sentry.SentryId CaptureException(System.Exception exception) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ namespace Sentry
void BindException(System.Exception exception, Sentry.ISpan span);
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope);
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope);
void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
Sentry.TransactionContext ContinueTrace(Sentry.SentryTraceHeader? traceHeader, Sentry.BaggageHeader? baggageHeader, string? name = null, string? operation = null);
Sentry.TransactionContext ContinueTrace(string? traceHeader, string? baggageHeader, string? name = null, string? operation = null);
void EndSession(Sentry.SessionEndStatus status = 0);
Expand Down Expand Up @@ -823,7 +825,9 @@ namespace Sentry
public static Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public static Sentry.SentryId CaptureException(System.Exception exception) { }
public static Sentry.SentryId CaptureException(System.Exception exception, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(string message, string? contactEmail = null, string? name = null, string? replayId = null, string? url = null, Sentry.SentryId? associatedEventId = default, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public static Sentry.SentryId CaptureMessage(string message, Sentry.SentryLevel level = 1) { }
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
Expand Down Expand Up @@ -1333,7 +1337,9 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
Expand Down Expand Up @@ -1379,7 +1385,9 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope, Sentry.SentryHint? hint = null) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public Sentry.SentryId CaptureException(System.Exception exception) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
Expand Down
8 changes: 8 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ namespace Sentry
void BindException(System.Exception exception, Sentry.ISpan span);
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope);
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope);
void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
Sentry.TransactionContext ContinueTrace(Sentry.SentryTraceHeader? traceHeader, Sentry.BaggageHeader? baggageHeader, string? name = null, string? operation = null);
Sentry.TransactionContext ContinueTrace(string? traceHeader, string? baggageHeader, string? name = null, string? operation = null);
void EndSession(Sentry.SessionEndStatus status = 0);
Expand Down Expand Up @@ -804,7 +806,9 @@ namespace Sentry
public static Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public static Sentry.SentryId CaptureException(System.Exception exception) { }
public static Sentry.SentryId CaptureException(System.Exception exception, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public static void CaptureFeedback(string message, string? contactEmail = null, string? name = null, string? replayId = null, string? url = null, Sentry.SentryId? associatedEventId = default, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public static Sentry.SentryId CaptureMessage(string message, Sentry.SentryLevel level = 1) { }
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
Expand Down Expand Up @@ -1314,7 +1318,9 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
Expand Down Expand Up @@ -1360,7 +1366,9 @@ namespace Sentry.Extensibility
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope, Sentry.SentryHint? hint = null) { }
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public Sentry.SentryId CaptureException(System.Exception exception) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
Expand Down
Loading