Skip to content

Commit 39e58f0

Browse files
Added CaptureFeedback overload with configureScope parameter (#4073)
1 parent 5df6c7b commit 39e58f0

File tree

13 files changed

+128
-3
lines changed

13 files changed

+128
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Added `CaptureFeedback` overload with `configureScope` parameter ([#4073](https://github.com/getsentry/sentry-dotnet/pull/4073))
78
- Custom SessionReplay masks in MAUI Android apps ([#4121](https://github.com/getsentry/sentry-dotnet/pull/4121))
89

910
### Fixes

samples/Sentry.Samples.AspNetCore.Mvc/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public async Task<IActionResult> SubmitFeedback(FeedbackModel feedback)
202202
hint.AddAttachment(memoryStream.ToArray(), feedback.Screenshot.FileName, AttachmentType.Default, "image/png");
203203
}
204204

205-
SentrySdk.CaptureFeedback(sentryFeedback, null, hint);
205+
SentrySdk.CaptureFeedback(sentryFeedback, hint: hint);
206206
ViewBag.Message = "Feedback submitted successfully!";
207207
return View("Index");
208208
}

src/Sentry/Extensibility/DisabledHub.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ public bool CaptureEnvelope(Envelope envelope)
147147
/// </summary>
148148
public SentryId CaptureEvent(SentryEvent evt, Scope? scope = null, SentryHint? hint = null) => SentryId.Empty;
149149

150+
/// <summary>
151+
/// No-Op.
152+
/// </summary>
153+
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope, SentryHint? hint = null)
154+
{
155+
}
156+
150157
/// <summary>
151158
/// No-Op.
152159
/// </summary>

src/Sentry/Extensibility/HubAdapter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ public SentryId CaptureEvent(SentryEvent evt, Scope? scope)
222222
public SentryId CaptureEvent(SentryEvent evt, Scope? scope, SentryHint? hint = null)
223223
=> SentrySdk.CaptureEvent(evt, scope, hint);
224224

225+
/// <summary>
226+
/// Forwards the call to <see cref="SentrySdk"/>.
227+
/// </summary>
228+
[DebuggerStepThrough]
229+
[EditorBrowsable(EditorBrowsableState.Never)]
230+
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope, SentryHint? hint = null)
231+
=> SentrySdk.CaptureFeedback(feedback, configureScope, hint);
232+
225233
/// <summary>
226234
/// Forwards the call to <see cref="SentrySdk"/>.
227235
/// </summary>

src/Sentry/IHub.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,12 @@ public TransactionContext ContinueTrace(
116116
/// <param name="configureScope">The callback to configure the scope.</param>
117117
/// <returns></returns>
118118
public SentryId CaptureEvent(SentryEvent evt, SentryHint? hint, Action<Scope> configureScope);
119+
120+
/// <summary>
121+
/// Captures feedback from the user.
122+
/// </summary>
123+
/// <param name="feedback">The feedback to send to Sentry.</param>
124+
/// <param name="configureScope">Callback method to configure the scope.</param>
125+
/// <param name="hint">An optional hint providing high level context for the source of the event, including attachments</param>
126+
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope, SentryHint? hint = null);
119127
}

src/Sentry/Internal/Hub.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,42 @@ private SentryId CaptureEvent(SentryEvent evt, SentryHint? hint, Scope scope)
506506
}
507507
}
508508

509+
public void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope, SentryHint? hint = null)
510+
{
511+
if (!IsEnabled)
512+
{
513+
return;
514+
}
515+
516+
try
517+
{
518+
var clonedScope = CurrentScope.Clone();
519+
configureScope(clonedScope);
520+
521+
CaptureFeedback(feedback, clonedScope, hint);
522+
}
523+
catch (Exception e)
524+
{
525+
_options.LogError(e, "Failure to capture feedback");
526+
}
527+
}
528+
509529
public void CaptureFeedback(SentryFeedback feedback, Scope? scope = null, SentryHint? hint = null)
510530
{
511531
if (!IsEnabled)
512532
{
513533
return;
514534
}
515535

516-
scope ??= CurrentScope;
517-
CurrentClient.CaptureFeedback(feedback, scope, hint);
536+
try
537+
{
538+
scope ??= CurrentScope;
539+
CurrentClient.CaptureFeedback(feedback, scope, hint);
540+
}
541+
catch (Exception e)
542+
{
543+
_options.LogError(e, "Failure to capture feedback");
544+
}
518545
}
519546

520547
#if MEMORY_DUMP_SUPPORTED

src/Sentry/SentrySdk.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,13 @@ public static SentryId CaptureMessage(string message, SentryLevel level = Sentry
481481
public static SentryId CaptureMessage(string message, Action<Scope> configureScope, SentryLevel level = SentryLevel.Info)
482482
=> CurrentHub.CaptureMessage(message, configureScope, level);
483483

484+
/// <summary>
485+
/// Captures feedback from the user.
486+
/// </summary>
487+
[DebuggerStepThrough]
488+
public static void CaptureFeedback(SentryFeedback feedback, Action<Scope> configureScope, SentryHint? hint = null)
489+
=> CurrentHub.CaptureFeedback(feedback, configureScope, hint);
490+
484491
/// <summary>
485492
/// Captures feedback from the user.
486493
/// </summary>

test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ namespace Sentry
212212
void BindException(System.Exception exception, Sentry.ISpan span);
213213
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope);
214214
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
215+
void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null);
215216
Sentry.TransactionContext ContinueTrace(Sentry.SentryTraceHeader? traceHeader, Sentry.BaggageHeader? baggageHeader, string? name = null, string? operation = null);
216217
Sentry.TransactionContext ContinueTrace(string? traceHeader, string? baggageHeader, string? name = null, string? operation = null);
217218
void EndSession(Sentry.SessionEndStatus status = 0);
@@ -824,6 +825,7 @@ namespace Sentry
824825
public static Sentry.SentryId CaptureException(System.Exception exception) { }
825826
public static Sentry.SentryId CaptureException(System.Exception exception, System.Action<Sentry.Scope> configureScope) { }
826827
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
828+
public static void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
827829
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) { }
828830
public static Sentry.SentryId CaptureMessage(string message, Sentry.SentryLevel level = 1) { }
829831
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
@@ -1334,6 +1336,7 @@ namespace Sentry.Extensibility
13341336
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
13351337
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
13361338
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
1339+
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
13371340
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
13381341
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
13391342
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
@@ -1380,6 +1383,7 @@ namespace Sentry.Extensibility
13801383
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
13811384
public Sentry.SentryId CaptureException(System.Exception exception) { }
13821385
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
1386+
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
13831387
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
13841388
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
13851389
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ namespace Sentry
212212
void BindException(System.Exception exception, Sentry.ISpan span);
213213
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope);
214214
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
215+
void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null);
215216
Sentry.TransactionContext ContinueTrace(Sentry.SentryTraceHeader? traceHeader, Sentry.BaggageHeader? baggageHeader, string? name = null, string? operation = null);
216217
Sentry.TransactionContext ContinueTrace(string? traceHeader, string? baggageHeader, string? name = null, string? operation = null);
217218
void EndSession(Sentry.SessionEndStatus status = 0);
@@ -824,6 +825,7 @@ namespace Sentry
824825
public static Sentry.SentryId CaptureException(System.Exception exception) { }
825826
public static Sentry.SentryId CaptureException(System.Exception exception, System.Action<Sentry.Scope> configureScope) { }
826827
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
828+
public static void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
827829
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) { }
828830
public static Sentry.SentryId CaptureMessage(string message, Sentry.SentryLevel level = 1) { }
829831
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
@@ -1334,6 +1336,7 @@ namespace Sentry.Extensibility
13341336
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
13351337
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
13361338
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
1339+
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
13371340
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
13381341
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
13391342
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
@@ -1380,6 +1383,7 @@ namespace Sentry.Extensibility
13801383
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
13811384
public Sentry.SentryId CaptureException(System.Exception exception) { }
13821385
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
1386+
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
13831387
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
13841388
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
13851389
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }

test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ namespace Sentry
200200
void BindException(System.Exception exception, Sentry.ISpan span);
201201
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, System.Action<Sentry.Scope> configureScope);
202202
Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope);
203+
void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null);
203204
Sentry.TransactionContext ContinueTrace(Sentry.SentryTraceHeader? traceHeader, Sentry.BaggageHeader? baggageHeader, string? name = null, string? operation = null);
204205
Sentry.TransactionContext ContinueTrace(string? traceHeader, string? baggageHeader, string? name = null, string? operation = null);
205206
void EndSession(Sentry.SessionEndStatus status = 0);
@@ -805,6 +806,7 @@ namespace Sentry
805806
public static Sentry.SentryId CaptureException(System.Exception exception) { }
806807
public static Sentry.SentryId CaptureException(System.Exception exception, System.Action<Sentry.Scope> configureScope) { }
807808
public static void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
809+
public static void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
808810
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) { }
809811
public static Sentry.SentryId CaptureMessage(string message, Sentry.SentryLevel level = 1) { }
810812
public static Sentry.SentryId CaptureMessage(string message, System.Action<Sentry.Scope> configureScope, Sentry.SentryLevel level = 1) { }
@@ -1315,6 +1317,7 @@ namespace Sentry.Extensibility
13151317
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
13161318
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
13171319
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
1320+
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
13181321
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
13191322
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
13201323
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }
@@ -1361,6 +1364,7 @@ namespace Sentry.Extensibility
13611364
public Sentry.SentryId CaptureEvent(Sentry.SentryEvent evt, Sentry.SentryHint? hint, System.Action<Sentry.Scope> configureScope) { }
13621365
public Sentry.SentryId CaptureException(System.Exception exception) { }
13631366
public void CaptureFeedback(Sentry.SentryFeedback feedback, Sentry.Scope? scope = null, Sentry.SentryHint? hint = null) { }
1367+
public void CaptureFeedback(Sentry.SentryFeedback feedback, System.Action<Sentry.Scope> configureScope, Sentry.SentryHint? hint = null) { }
13641368
public void CaptureSession(Sentry.SessionUpdate sessionUpdate) { }
13651369
public void CaptureTransaction(Sentry.SentryTransaction transaction) { }
13661370
public void CaptureTransaction(Sentry.SentryTransaction transaction, Sentry.Scope? scope, Sentry.SentryHint? hint) { }

0 commit comments

Comments
 (0)