Repository navigation
Send the last five minutes of activity from the device, and stop NotFound being a dead end #159
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f906820
Stop treating every "Not Found" as a permanent, unreportable dead end
c6ec909
Let a user send the last five minutes of activity from the device
9e93056
CI: Update UI screenshots [skip ci]
github-actions[bot] 8851757
PR feedback: never let a Report tap do nothing, and drop an unused Clear
cbbdf9d
CI: Update UI screenshots [skip ci]
github-actions[bot] dd52676
Say what the log-line contract actually is, rather than overstating it
91cac61
CI: Update UI screenshots [skip ci]
github-actions[bot] faf7033
Date the classifier's reasoning instead of asserting a contract we re…
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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
172 changes: 172 additions & 0 deletions
172
src/AniSprinkles.Core/PageModels/DiagnosticsReportCoordinator.cs
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,172 @@ | ||
| using AniSprinkles.Services; | ||
| using AniSprinkles.Services.Abstractions; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace AniSprinkles.PageModels; | ||
|
|
||
| /// <summary> | ||
| /// The whole send-a-diagnostic-report flow, in one place so both entry points behave identically: | ||
| /// the Settings card and the Report action on any error card (#112). | ||
| /// <para> | ||
| /// Order matters and is the point of the type. Disclose first — the user sees what is about to leave | ||
| /// their device before anything is collected, not after. Then snapshot, build, redact, send, and say | ||
| /// what happened. Sentry is silent to the sender, so the popup and the confirmation are the only | ||
| /// things telling the user their report exists. | ||
| /// </para> | ||
| /// </summary> | ||
| public sealed class DiagnosticsReportCoordinator | ||
| { | ||
| /// <summary> | ||
| /// What the popup promises. Kept here rather than in the popup's XAML so the promise and the | ||
| /// thing that fulfils it live in one file and are asserted together — a disclosure that drifts | ||
| /// from what is actually collected is worse than no disclosure, because it is trusted. | ||
| /// </summary> | ||
| public const string DisclosureSummary = | ||
| "This sends the last 5 minutes of app activity: the screens you opened, the AniList ids they " | ||
| + "were for, the requests the app made and how they failed, plus your app version and device " | ||
| + "model. Your AniList login is never included."; | ||
|
|
||
| /// <summary>Shown after a successful send. Names the thing the popup promised, so the two read | ||
| /// back against each other rather than the user having to take "sent" on faith.</summary> | ||
| public const string SentMessage = "Diagnostics sent — last 5 minutes of activity."; | ||
|
|
||
| /// <summary>Shown when nothing left the device. Never silently swallowed: a report the user | ||
| /// believes they filed and did not is worse than a visible failure.</summary> | ||
| public const string FailedMessage = "Couldn't send diagnostics. Check your connection and try again."; | ||
|
|
||
| /// <summary> | ||
| /// Shown by an entry point that could not even reach this coordinator — i.e. the DI container | ||
| /// was unavailable. Lives here with the other two so all three read as one voice, even though | ||
| /// nothing in this class can show it: by definition that path never got this far. | ||
| /// </summary> | ||
| public const string UnavailableMessage = "Diagnostics aren't available right now."; | ||
|
|
||
| private readonly DiagnosticsLogBuffer _buffer; | ||
| private readonly DiagnosticsSessionLog _sessionLog; | ||
| private readonly IDiagnosticsSink _sink; | ||
| private readonly IDialogService _dialogs; | ||
| private readonly IUserFeedback _feedback; | ||
| private readonly IAppEnvironment _environment; | ||
| private readonly IAuthService _authService; | ||
| private readonly TimeProvider _timeProvider; | ||
| private readonly ILogger<DiagnosticsReportCoordinator> _logger; | ||
|
|
||
| public DiagnosticsReportCoordinator( | ||
| DiagnosticsLogBuffer buffer, | ||
| DiagnosticsSessionLog sessionLog, | ||
| IDiagnosticsSink sink, | ||
| IDialogService dialogs, | ||
| IUserFeedback feedback, | ||
| IAppEnvironment environment, | ||
| IAuthService authService, | ||
| TimeProvider timeProvider, | ||
| ILogger<DiagnosticsReportCoordinator> logger) | ||
| { | ||
| _buffer = buffer; | ||
| _sessionLog = sessionLog; | ||
| _sink = sink; | ||
| _dialogs = dialogs; | ||
| _feedback = feedback; | ||
| _environment = environment; | ||
| _authService = authService; | ||
| _timeProvider = timeProvider; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// True while a report is being assembled or sent. Guards against a double tap producing two | ||
| /// events for one intent — the send is slow enough (it waits for the Sentry flush) that a second | ||
| /// press is easy. | ||
| /// </summary> | ||
| public bool IsBusy { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Runs the flow. Returns <c>true</c> only when a report actually reached Sentry — cancelling at | ||
| /// the popup returns <c>false</c>, as does a failed send, so a caller that disables its button | ||
| /// after a successful report does not disable it on a cancel. | ||
| /// </summary> | ||
| public async Task<bool> ReportAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| if (IsBusy) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| IsBusy = true; | ||
| try | ||
| { | ||
| var choice = await _dialogs.ShowDiagnosticsReportAsync(DisclosureSummary).ConfigureAwait(true); | ||
| if (choice is null) | ||
| { | ||
| _logger.LogInformation("Diagnostic report cancelled at the disclosure."); | ||
| return false; | ||
| } | ||
|
|
||
| // Snapshotted only after consent. Collecting first and discarding on cancel would work | ||
| // just as well technically, and would make the disclosure a formality rather than a gate. | ||
| var current = _buffer.Snapshot(); | ||
| var previous = _sessionLog.Load(); | ||
|
|
||
| var report = DiagnosticsReportBuilder.Build( | ||
| await BuildContextAsync(cancellationToken).ConfigureAwait(true), | ||
| _timeProvider.GetUtcNow(), | ||
| previous, | ||
| current, | ||
| choice.Value.Description); | ||
|
|
||
| var sent = await _sink.SendAsync(report, choice.Value.Description, cancellationToken).ConfigureAwait(true); | ||
|
|
||
| if (sent) | ||
| { | ||
| // Only once it is genuinely gone. Clearing on a failed send would throw away the | ||
| // previous session's lines — the ones a crash flush existed to preserve — and the | ||
| // retry would carry less than the attempt that failed. | ||
| _sessionLog.Clear(); | ||
|
|
||
| // Confirmed branch only, matching how the other repeatable user actions breadcrumb. | ||
| // Its value is on *later* events: "this user had already reported something" is real | ||
| // context, and a cancel breadcrumb would only add buffer noise. | ||
| SentrySdk.AddBreadcrumb("Diagnostic report sent", "state", "user"); | ||
| } | ||
|
|
||
| await _feedback.ShowSnackbarAsync(sent ? SentMessage : FailedMessage).ConfigureAwait(true); | ||
| return sent; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| // This runs off a button the user pressed because something was already wrong. The | ||
| // reporting path throwing on top of that is the worst outcome available, so it is caught | ||
| // here and told to the user rather than raised. | ||
| _logger.LogError(ex, "Diagnostic report flow failed."); | ||
| await _feedback.ShowSnackbarAsync(FailedMessage).ConfigureAwait(true); | ||
| return false; | ||
| } | ||
| finally | ||
| { | ||
| IsBusy = false; | ||
| } | ||
| } | ||
|
|
||
| private async Task<DiagnosticsContext> BuildContextAsync(CancellationToken cancellationToken) | ||
| { | ||
| var isSignedIn = false; | ||
| try | ||
| { | ||
| isSignedIn = !string.IsNullOrWhiteSpace( | ||
| await _authService.GetAccessTokenAsync(cancellationToken).ConfigureAwait(true)); | ||
| } | ||
| catch (Exception ex) when (ex is not OperationCanceledException) | ||
| { | ||
| // A header field is not worth losing the report over — secure storage can fail, and if it | ||
| // just did, that is itself something the log will show. | ||
| _logger.LogWarning(ex, "Could not determine sign-in state for the diagnostic report."); | ||
| } | ||
|
|
||
| return new DiagnosticsContext( | ||
| _environment.AppVersion, | ||
| _environment.BuildConfiguration, | ||
| _environment.Device, | ||
| _environment.OsVersion, | ||
| isSignedIn); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/AniSprinkles.Core/Services/Abstractions/IAppEnvironment.cs
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,26 @@ | ||
| namespace AniSprinkles.Services.Abstractions; | ||
|
|
||
| /// <summary> | ||
| /// The handful of environment facts a diagnostic report needs in its header (#112). | ||
| /// <para> | ||
| /// A seam because every one of these comes from MAUI Essentials — <c>AppInfo</c>, <c>DeviceInfo</c> — | ||
| /// which throw rather than degrade on the plain <c>net10.0</c> test TFM. Reading them straight from a | ||
| /// page model would make the whole report flow untestable. | ||
| /// </para> | ||
| /// </summary> | ||
| public interface IAppEnvironment | ||
| { | ||
| /// <summary>Version and build, e.g. <c>0.13.0 (142)</c>.</summary> | ||
| string AppVersion { get; } | ||
|
|
||
| /// <summary><c>Debug</c> or <c>Release</c>. Load on this repo's behaviour genuinely diverges | ||
| /// between the two — log levels, CI stubs, fault injection — so a report that does not say which | ||
| /// one it came from is missing a fact the reader would otherwise have to guess.</summary> | ||
| string BuildConfiguration { get; } | ||
|
|
||
| /// <summary>Manufacturer and model, e.g. <c>Google Pixel 7</c>.</summary> | ||
| string Device { get; } | ||
|
|
||
| /// <summary>Platform and version, e.g. <c>Android 15</c>.</summary> | ||
| string OsVersion { get; } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/AniSprinkles.Core/Services/Abstractions/IDiagnosticsSink.cs
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,20 @@ | ||
| namespace AniSprinkles.Services.Abstractions; | ||
|
|
||
| /// <summary> | ||
| /// Where a finished diagnostic report is sent (#112). | ||
| /// <para> | ||
| /// A seam for the same reason <see cref="IDialogService"/> is one, and with a sharper edge: an | ||
| /// uninitialised <c>SentrySdk</c> does not throw, it silently discards. A page model calling it | ||
| /// directly would no-op in a test and read as a pass, so "the report was sent" would never actually | ||
| /// be asserted anywhere. | ||
| /// </para> | ||
| /// </summary> | ||
| public interface IDiagnosticsSink | ||
| { | ||
| /// <summary> | ||
| /// Sends <paramref name="report"/>, with <paramref name="description"/> attached as the user's own | ||
| /// account of what happened when they gave one. Returns whether it was accepted for delivery. | ||
| /// Never throws — a failed send is reported to the user, not raised. | ||
| /// </summary> | ||
| Task<bool> SendAsync(string report, string? description, CancellationToken cancellationToken = default); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.