-
Notifications
You must be signed in to change notification settings - Fork 43
feat(telemetry): instrument auth recovery and workspace lifecycle #948
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
EhabY
wants to merge
9
commits into
main
Choose a base branch
from
feat/issue-906-auth-workspace-telemetry
base: main
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9fe4eca
feat(telemetry): instrument auth and workspace state
EhabY af7a20d
refactor(telemetry): keep lifecycle tracking isolated
EhabY ad17282
refactor(telemetry): simplify auth/workspace instrumentation
EhabY 32ce9d7
fix changelog
EhabY 978c685
refactor(telemetry): decouple auth/workspace instrumentation
EhabY 1393c08
refactor(telemetry): self-review polish
EhabY f3b287c
refactor(telemetry): address PR review
EhabY 5523f85
refactor(telemetry): address PR review (round 2)
EhabY 57902fc
refactor(telemetry): simplify span result tracking and property typing
EhabY 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import type { TelemetryReporter } from "../telemetry/reporter"; | ||
|
|
||
| export type AuthTokenRefreshTrigger = "background" | "reactive"; | ||
| export type AuthRecoveryAction = "refresh_success" | "login_required" | "none"; | ||
| export type AuthLoginPromptTrigger = "auth_required" | "missing_session"; | ||
|
|
||
| /** | ||
| * Why a login prompt ended without a session. `auth_failed` indicates | ||
| * authentication itself failed; the others are user-driven aborts. | ||
| */ | ||
| export type LoginPromptReason = | ||
| | "user_dismissed" | ||
| | "no_url_provided" | ||
| | "auth_failed"; | ||
|
|
||
| export type LoginPromptOutcome = | ||
| | { success: true } | ||
| | { success: false; reason: LoginPromptReason }; | ||
|
|
||
| /** Span annotator for the auth-recovery flow. Defaults to safe values. */ | ||
| export interface AuthRecoveryRecorder { | ||
| setRecovery(recovery: AuthRecoveryAction): void; | ||
| setRefreshAttempted(attempted: boolean): void; | ||
| } | ||
|
|
||
| export class AuthTelemetry { | ||
| public constructor(private readonly telemetry: TelemetryReporter) {} | ||
|
|
||
| public traceTokenRefresh<T>( | ||
| trigger: AuthTokenRefreshTrigger, | ||
| fn: () => Promise<T>, | ||
| ): Promise<T> { | ||
| return this.telemetry.trace("auth.token_refreshed", fn, { trigger }); | ||
| } | ||
|
|
||
| /** Logged when a refresh call joins an in-flight refresh and emits no span of its own. */ | ||
| public tokenRefreshDeduped(trigger: AuthTokenRefreshTrigger): void { | ||
| this.telemetry.log("auth.token_refresh.deduped", { trigger }); | ||
| } | ||
|
|
||
| /** | ||
| * Wraps the auth-recovery path triggered by a 401. Initial properties | ||
| * cover the throw-before-callback case. | ||
| */ | ||
| public traceAuthRecovery<T>( | ||
| fn: (recorder: AuthRecoveryRecorder) => Promise<T>, | ||
| ): Promise<T> { | ||
| return this.telemetry.trace( | ||
| "auth.unauthorized_intercepted", | ||
| (span) => | ||
| fn({ | ||
| setRecovery: (recovery) => span.setProperty("recovery", recovery), | ||
| setRefreshAttempted: (attempted) => | ||
| span.setProperty("refreshAttempted", attempted), | ||
| }), | ||
| { recovery: "none", refreshAttempted: false }, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Records `auth.login_prompted`. `auth_failed` marks the span as failure; | ||
| * other non-success reasons mark it as aborted. The reason is copied to the | ||
| * span's `reason` property on failure/abort only. | ||
| */ | ||
| public traceLoginPrompt<T extends LoginPromptOutcome>( | ||
| trigger: AuthLoginPromptTrigger, | ||
| fn: () => Promise<T>, | ||
| ): Promise<T> { | ||
| return this.telemetry.trace( | ||
| "auth.login_prompted", | ||
| async (span) => { | ||
|
EhabY marked this conversation as resolved.
|
||
| const result = await fn(); | ||
| if (!result.success) { | ||
| span.setProperty("reason", result.reason); | ||
| if (result.reason === "auth_failed") { | ||
| span.markFailure(); | ||
| } else { | ||
| span.markAborted(); | ||
| } | ||
| } | ||
| return result; | ||
| }, | ||
| { trigger }, | ||
| ); | ||
| } | ||
| } | ||
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.