-
-
Notifications
You must be signed in to change notification settings - Fork 225
CaptureFeedback now returns a SentryId #4613
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
jamescrosswell
wants to merge
11
commits into
version6
Choose a base branch
from
capture-feedback-return
base: version6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+275
−64
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1a76177
CaptureFeedback now returns a SentryId
jamescrosswell 98bf2f6
Changelog
jamescrosswell f58417b
Update ApiApprovalTests.Run.Net4_8.verified.txt
jamescrosswell 04e9a56
Fixed client disposal
jamescrosswell 0cda3df
Merge remote-tracking branch 'origin/capture-feedback-return' into ca…
jamescrosswell 3d5e218
Added CaptureFeedbackResult
jamescrosswell 22da5b6
Merge branch 'version6' into capture-feedback-return
jamescrosswell 7824b1c
Updated docs/changelog
jamescrosswell 5041de0
Format code
getsentry-bot 4f2c694
Update ApiApprovalTests.Run.Net4_8.verified.txt
jamescrosswell 9db3a36
Merge branch 'capture-feedback-return' of https://github.com/getsentr…
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
namespace Sentry; | ||
|
||
/// <summary> | ||
/// The result type of the <see cref="ISentryClient.CaptureFeedback"/> method | ||
/// </summary> | ||
public struct CaptureFeedbackResult | ||
{ | ||
/// <summary> | ||
/// Creates a successful feedback capture result with the specified event Id. | ||
/// </summary> | ||
/// <param name="eventId"></param> | ||
public CaptureFeedbackResult(SentryId eventId) | ||
{ | ||
if (eventId == SentryId.Empty) | ||
{ | ||
throw new ArgumentException("EventId cannot be empty", nameof(eventId)); | ||
} | ||
|
||
EventId = eventId; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a failed feedback capture result with the specified error reason. | ||
/// </summary> | ||
/// <param name="errorReason"></param> | ||
public CaptureFeedbackResult(CaptureFeedbackErrorReason errorReason) | ||
{ | ||
EventId = SentryId.Empty; | ||
ErrorReason = errorReason; | ||
} | ||
|
||
/// <summary> | ||
/// The Id of the captured feedback, if successful. <see cref="SentryId.Empty"/> if feedback capture fails. | ||
/// </summary> | ||
public SentryId EventId; | ||
|
||
/// <inheritdoc cref="CaptureFeedbackErrorReason"/> | ||
public CaptureFeedbackErrorReason? ErrorReason; | ||
|
||
/// <summary> | ||
/// Implicitly converts a <see cref="CaptureFeedbackErrorReason"/> to a <see cref="CaptureFeedbackResult"/> | ||
/// </summary> | ||
/// <param name="errorReason"></param> | ||
/// <returns></returns> | ||
public static implicit operator CaptureFeedbackResult(CaptureFeedbackErrorReason errorReason) => new(errorReason); | ||
|
||
/// <summary> | ||
/// Implicitly converts a non-empty <see cref="SentryId"/> to a <see cref="CaptureFeedbackResult"/> | ||
/// </summary> | ||
/// <returns></returns> | ||
public static implicit operator CaptureFeedbackResult(SentryId eventId) => new(eventId); | ||
|
||
/// <summary> | ||
/// Returns true if feedback capture was successful, false otherwise. | ||
/// </summary> | ||
public bool Succeededed => ErrorReason == null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
/// <summary> | ||
/// Used to specify the reason why feedback capture failed, in the event of a failure | ||
/// </summary> | ||
public enum CaptureFeedbackErrorReason | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// An unknown error occurred (enable debug mode and check the logs for details). | ||
/// </para> | ||
/// <para> | ||
/// Possible causes: | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <description>An exception from the configureScope callback</description> | ||
/// </item> | ||
/// <item> | ||
/// <description>A transmission error when sending the envelope</description> | ||
/// </item> | ||
/// <item> | ||
/// <description>An attempt to send feedback while the application is shutting down</description> | ||
/// </item> | ||
/// <item> | ||
/// <description>Something more mysterious...</description> | ||
/// </item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
UnknownError, | ||
/// <summary> | ||
/// Sentry is disabled (very likely an empty DSN was provided when initialising the SDK). | ||
/// </summary> | ||
DisabledHub, | ||
/// <summary> | ||
/// The <see cref="SentryFeedback.Message"/> message is empty. | ||
/// </summary> | ||
EmptyMessage, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ public class SentryClient : ISentryClient, IDisposable | |
private readonly ISessionManager _sessionManager; | ||
private readonly RandomValuesFactory _randomValuesFactory; | ||
private readonly Enricher _enricher; | ||
private volatile int _isDisposed = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Shall we use the |
||
|
||
internal IBackgroundWorker Worker { get; } | ||
|
||
|
@@ -85,12 +86,12 @@ public SentryId CaptureEvent(SentryEvent? @event, Scope? scope = null, SentryHin | |
} | ||
|
||
/// <inheritdoc /> | ||
public void CaptureFeedback(SentryFeedback feedback, Scope? scope = null, SentryHint? hint = null) | ||
public CaptureFeedbackResult CaptureFeedback(SentryFeedback feedback, Scope? scope = null, SentryHint? hint = null) | ||
{ | ||
if (string.IsNullOrEmpty(feedback.Message)) | ||
{ | ||
_options.LogWarning("Feedback dropped due to empty message."); | ||
return; | ||
return CaptureFeedbackErrorReason.EmptyMessage; | ||
} | ||
|
||
scope ??= new Scope(_options); | ||
|
@@ -116,7 +117,7 @@ public void CaptureFeedback(SentryFeedback feedback, Scope? scope = null, Sentry | |
|
||
var attachments = hint.Attachments.ToList(); | ||
var envelope = Envelope.FromFeedback(evt, _options.DiagnosticLogger, attachments, scope.SessionUpdate); | ||
CaptureEnvelope(envelope); | ||
return CaptureEnvelope(envelope) ? evt.EventId : CaptureFeedbackErrorReason.UnknownError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
|
@@ -438,6 +439,12 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope) | |
/// <inheritdoc cref="ISentryClient.CaptureEnvelope"/> | ||
public bool CaptureEnvelope(Envelope envelope) | ||
{ | ||
if (_isDisposed == 1) | ||
{ | ||
_options.LogWarning("Enqueue envelope failed. Client is disposed."); | ||
return false; | ||
} | ||
|
||
if (Worker.EnqueueEnvelope(envelope)) | ||
{ | ||
_options.LogInfo("Envelope queued up: '{0}'", envelope.TryGetEventId(_options.DiagnosticLogger)); | ||
|
@@ -456,6 +463,11 @@ public bool CaptureEnvelope(Envelope envelope) | |
/// </summary> | ||
public void Dispose() | ||
{ | ||
if (Interlocked.Exchange(ref _isDisposed, 1) == 1) | ||
{ | ||
return; | ||
} | ||
|
||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_options.LogDebug("Flushing SentryClient."); | ||
|
||
try | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought:
Nullable<T>
vs non-nullableI am a bit hesitant about a
Nullable<enum>
.I'm thinking about having an additional
0
value in the enum, likeDone
orSucceeded
.And calling the
enum
insteadCaptureFeedbackStatus
.Similar to