-
-
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
5
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.
+93
−62
Open
Changes from all commits
Commits
Show all changes
5 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 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
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; | ||||||
|
||||||
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 SentryId CaptureFeedback(SentryFeedback feedback, Scope? scope = null, SentryHint? hint = null) | ||||||
{ | ||||||
if (string.IsNullOrEmpty(feedback.Message)) | ||||||
{ | ||||||
_options.LogWarning("Feedback dropped due to empty message."); | ||||||
return; | ||||||
return SentryId.Empty; | ||||||
} | ||||||
|
||||||
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 : SentryId.Empty; | ||||||
} | ||||||
|
||||||
/// <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: disposed client"); | ||||||
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.
Suggested change
|
||||||
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
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.
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.
Arguably this could be called
TryCaptureFeedback
now but I don't think that's consistent with the other SDKs (or theCaptureEvent
method)... so for consistency I've left it as is.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.
I was also wondering about the other
SentryId
-returningCapture*
-methods 🤔Both other
SentryId
-returningCapture*
-methodsSentryId CaptureEvent
SentryId CaptureCheckIn
do return
SentryId.Empty
when unsuccessful.If I get that right, then
bool Try*
-methods should communicate the "main-exceptional" flow when returningfalse
, not every reason for completing unsuccessfully.E.g.
Dictionary<TKey, TValue>.TryAdd
only returnsfalse
when "An item with the same key has already been added.". But it still throws ifnull
is passed as a key.What would be the "main-error" that
TryCaptureFeedback
would communicate?TryCaptureEvent
would also have multiple failure casesSetBeforeSend
Hmm ... we could return something like a "CaptureEventStatus"
struct
orenum
.Similar to BCL methods returning OperationStatus when it comes to buffers.
Or am I dramatically overthinking this?
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.
Also ... I guess we're a bit inconsistent with
void
vsbool
, too:void CaptureTransaction
void CaptureSession
Could (or should) these be
bool
-returning as well?Uh oh!
There was an error while loading. Please reload this page.
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.
I think @bitsandfoxes wanted a SentryId on this, since it's not just SDK user facing but SDK user's user facing... so the SDK user could actually want to report success/failure of this method to the app user.
That's probably not the case for
CaptureTransaction
orCaptureSession
. The SDK user is highly unlikely to do anything with any hypothetical return value for those functions. They're really just best effort.This is probably the main one:
sentry-dotnet/src/Sentry/SentryClient.cs
Lines 91 to 95 in 0cda3df
DisabledHub
is possible, if an empty string was used for the DSN when initialising the SDK.I think failure to enqueue the envelope would only happen if we'd disposed of the SentryClient (which would only happen when shutting down the app)... so a vanishingly small chance of that happening when the app is capturing user feedback (and no chance to do anything with that error code if/when it did happen).
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.
I'd argue to not name it
Try*
but instead that the static API is mostly intended as fire & forget. The return values are not intended to be used to control the flow or have the option to recover from a failure.Consider the following
CaptureEvent
If they need the ID for some reason they should have it, but prepending the capture methods with a
Try*
implies some sort of recovery mechanism to me that does not exist.Uh oh!
There was an error while loading. Please reload this page.
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.
@bitsandfoxes agree re the method name.
Is there any value in changing the result type from SentryId to
CaptureFeedbackResult
(to be able to distinguish failure reasons) or is this overkill do you think? See this comment above - I think there are only really two possible reasons for failure.