Repository navigation
feat: add opt-out Sentry reporting for handled Akron errors #271
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4dd51eb
feat: add opt-in Sentry reporting for handled Akron errors
Microck 7145d22
ci: collect NuGet lock and formatter evidence for draft review
Microck 6cb73a9
fix: use restored NuGet content hashes and format telemetry sources
Microck 51863c0
fix: own and dispose the mod telemetry queue and transport
Microck 3b89895
feat: default automatic error reports on with a visible opt-out notice
Microck aae7a28
test: parse persisted reporting preferences without stripped game hel…
Microck 2146dd8
docs: record the verified Everest runtime symbol limitation
Microck 166ec03
fix: remove the automatic error reporting launch notice
Microck 10adc81
fix: preserve source lines through Everest relinking
Microck 82f0f12
docs: clarify automatic report privacy exclusions
Microck 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Sentry; | ||
| using Sentry.Extensibility; | ||
| using Sentry.Http; | ||
| using Sentry.Protocol.Envelopes; | ||
|
|
||
| namespace Celeste.Mod.Akron; | ||
|
|
||
| // SentryClient.Dispose only flushes its default worker. Own the public worker and | ||
| // transport extension points so an unloaded mod cannot leave an idle SDK task behind. | ||
| internal sealed class AkronTelemetryWorker : HttpTransportBase, IBackgroundWorker, IDisposable | ||
| { | ||
| private readonly object sync = new object(); | ||
| private readonly HttpClient httpClient; | ||
| private readonly CancellationTokenSource shutdown = new CancellationTokenSource(); | ||
| private readonly int limit; | ||
| private Task tail = Task.CompletedTask; | ||
| private Task completion = Task.CompletedTask; | ||
| private int queued; | ||
| private bool stopped; | ||
|
|
||
| internal AkronTelemetryWorker(SentryOptions options, HttpMessageHandler handler) : base(options) | ||
| { | ||
| limit = options.MaxQueueItems; | ||
| httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(10) }; | ||
| } | ||
|
|
||
| public int QueuedItems => Volatile.Read(ref queued); | ||
| internal Task Completion { get { lock (sync) return completion; } } | ||
|
|
||
| public bool EnqueueEnvelope(Envelope envelope) | ||
| { | ||
| lock (sync) | ||
| { | ||
| if (stopped || queued >= limit) return false; | ||
| Interlocked.Increment(ref queued); | ||
| Task previous = tail; | ||
| // Only accepted events schedule work. There is no task waiting on an empty queue. | ||
| tail = Task.Run(() => SendAfterAsync(previous, envelope)); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| private async Task SendAfterAsync(Task previous, Envelope envelope) | ||
| { | ||
| try | ||
| { | ||
| await previous.ConfigureAwait(false); | ||
| if (shutdown.IsCancellationRequested) return; | ||
| Envelope processed = ProcessEnvelope(envelope); | ||
| if (processed.Items.Count == 0) return; | ||
| using HttpRequestMessage request = CreateRequest(processed); | ||
| using HttpResponseMessage response = await httpClient.SendAsync(request, shutdown.Token).ConfigureAwait(false); | ||
| // The SDK's default HTTP handler handles plain 429s. Normalize them for | ||
| // the public transport base, which already applies Sentry rate-limit headers. | ||
| if (response.StatusCode == HttpStatusCode.TooManyRequests && !response.Headers.Contains("X-Sentry-Rate-Limits")) | ||
| { | ||
| double seconds = response.Headers.RetryAfter?.Delta?.TotalSeconds ?? | ||
| (response.Headers.RetryAfter?.Date - DateTimeOffset.UtcNow)?.TotalSeconds ?? 60; | ||
| string delay = Math.Ceiling(Math.Clamp(seconds, 0, int.MaxValue)).ToString(CultureInfo.InvariantCulture); | ||
| response.Headers.TryAddWithoutValidation("X-Sentry-Rate-Limits", delay + "::organization"); | ||
| } | ||
| await HandleResponseAsync(response, processed, shutdown.Token).ConfigureAwait(false); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| // Reporting is best effort. Cancellation and failed requests never escape to gameplay. | ||
| } | ||
| finally | ||
| { | ||
| envelope.Dispose(); | ||
| Interlocked.Decrement(ref queued); | ||
| } | ||
| } | ||
|
|
||
| public async Task FlushAsync(TimeSpan timeout) | ||
| { | ||
| Task pending; | ||
| lock (sync) pending = tail; | ||
| try { await pending.WaitAsync(timeout).ConfigureAwait(false); } | ||
| catch (TimeoutException) { } | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| lock (sync) | ||
| { | ||
| if (stopped) return; | ||
| stopped = true; | ||
| shutdown.Cancel(); | ||
| httpClient.Dispose(); | ||
| completion = FinishDisposalAsync(tail); | ||
| } | ||
| } | ||
|
|
||
| private async Task FinishDisposalAsync(Task pending) | ||
| { | ||
| try { await pending.ConfigureAwait(false); } | ||
| finally { shutdown.Dispose(); } | ||
| } | ||
| } |
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.