Repository navigation
feat: bring live Sentry mode back to Glitch Invaders through vault_services #26
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
3 commits
Select commit
Hold shift + click to select a range
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
56 changes: 56 additions & 0 deletions
56
challenges/glitch-invaders/game/src/diagnostics/live-evidence.mjs
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,56 @@ | ||
| /** | ||
| * Live-mode evidence: report the failure to Sentry, then ask the page server for what Sentry | ||
| * recorded. When either step fails, the console still gets the simulated evidence, labelled with | ||
| * why, so it is never left blank. | ||
| */ | ||
|
|
||
| /** How long the page waits for the server, which gives up on Sentry sooner than this. */ | ||
| const EVIDENCE_TIMEOUT_MS = 20_000; | ||
|
|
||
| /** The notes a fallback carries, by what went wrong. */ | ||
| export const FALLBACK_NOTES = { | ||
| unsent: 'Sentry did not accept the report, so this is simulated evidence.', | ||
| unavailable: 'Sentry could not return the report in time, so this is simulated evidence.', | ||
| restored: 'The page reloaded after this report, so this is simulated evidence.', | ||
| }; | ||
|
|
||
| /** Builds evidence from Sentry's own record of each report. */ | ||
| export class LiveEvidenceProvider { | ||
| /** | ||
| * @param {{ reporter: { report: Function }, simulated: { evidenceFor: Function }, | ||
| * fetchImpl: typeof fetch }} options `fetchImpl` reaches the page server. | ||
| */ | ||
| constructor(options) { | ||
| this.options = options; | ||
| } | ||
|
|
||
| /** Report `encounter` and fetch Sentry's evidence for it. Never rejects. */ | ||
| async evidenceFor(encounter) { | ||
| const outcome = await this.options.reporter.report(encounter); | ||
| if (!outcome.delivered) { | ||
| return this.fallback(encounter, 'unsent'); | ||
| } | ||
|
|
||
| try { | ||
| const query = new URLSearchParams({ bug: encounter.bug, id: outcome.id }); | ||
| const response = await this.options.fetchImpl(`/api/sentry-evidence?${query}`, { | ||
| cache: 'no-store', | ||
| signal: AbortSignal.timeout(EVIDENCE_TIMEOUT_MS), | ||
| }); | ||
| if (!response.ok) { | ||
| return this.fallback(encounter, 'unavailable'); | ||
| } | ||
|
|
||
| return await response.json(); | ||
| } catch { | ||
| return this.fallback(encounter, 'unavailable'); | ||
| } | ||
| } | ||
|
|
||
| /** The simulated evidence for `encounter`, labelled as a fallback with the note for `reason`. */ | ||
| async fallback(encounter, reason) { | ||
| const simulated = await this.options.simulated.evidenceFor(encounter); | ||
|
|
||
| return { ...simulated, source: 'fallback', note: FALLBACK_NOTES[reason] }; | ||
| } | ||
| } |
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.