Skip to content

fix(auth): report server-side errors to telemetry - #388

Closed
flcrom wants to merge 1 commit into
modelence:mainfrom
flcrom:fix/334-auth-telemetry
Closed

flcrom wants to merge 1 commit into
modelence:mainfrom
flcrom:fix/334-auth-telemetry

Conversation

@flcrom

@flcrom flcrom commented Sep 26, 2026 •

Copy link
Copy Markdown

Auth failures in the landing handlers, OAuth callbacks and hooks were logged only to the console, so APM missed them. Report them through captureError, retaining each handler's context in APM and in console output when telemetry is off. User-facing redirects and failures are unchanged.

Closes #334


Note

Low Risk
Observability-only: logging path changes with no intended change to auth behavior, redirects, or user-visible errors.

Overview
Auth server-side failures that were only written to console.error now go through captureError from @/telemetry, so they show up in APM when telemetry is enabled. User-facing redirects and error responses are unchanged.

captureError now accepts an optional context message (and unknown errors). With telemetry off, the console fallback logs message plus the error; with telemetry on, the message is passed to APM as custom context.

Call sites include magic-link landing and hook failures, token-restore errors, password-reset landing, email verification, GitHub/Google OAuth callbacks, OAuth error redirect / errorComponent failures, and OAuth hook execution. Tests mock @/telemetry and assert captureError is invoked with the same context strings that used to appear in console logs.

Reviewed by Cursor Bugbot for commit 130a284. Bugbot is set up for automated code reviews on this repo. Configure here.

@flcrom
flcrom requested a review from omegascorp as a code owner September 26, 2026 08:18
@flcrom

flcrom commented Oct 10, 2026

Copy link
Copy Markdown
Author

Bumping this in case it was missed. Happy to update it if anything needs changing.

@omegascorp omegascorp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The gap is real: these landing handlers and OAuth callbacks catch their own errors and return a 302, so the route handler's captureError never runs for them. Sending them through telemetry makes sense.

One change is needed before we can merge:

These errors must still be printed when telemetry is on. On deployed apps telemetry is enabled, and in that case captureError sends only to APM and prints nothing. Since #343 the Logs page shows only stdout/stderr, so with this PR these auth errors would disappear from the logs and show up in APM alone. Today they are printed. Method and route errors avoid this because something else prints them as well (server.ts, and the route handler's own console.error).

Please make these call sites always print the error and also capture it when telemetry is on. See the inline comment for one way to do it.

Optional nit: the context strings end in a colon ('Error handling magic link landing:'), which reads oddly as an APM error message. Consider dropping the colon.

}

getApm().captureError(error);
if (message) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When telemetry is enabled, nothing reaches the console from here, so the auth errors this PR routes through captureError are no longer printed on deployed apps.

We shouldn't make captureError always print either: methods and routes already print their errors elsewhere, so they would be logged twice. One option is a separate helper for the auth call sites that always prints and also captures when telemetry is on:

export function reportError(error: unknown, message: string) {
  console.error(message, error);
  if (isTelemetryEnabled()) {
    const cause = error instanceof Error ? error : new Error(String(error));
    getApm().captureError(cause, { message });
  }
}

That way the output is the same as today with telemetry off, and the errors reach APM without leaving the logs when it is on. The tests should then check both the console output and the APM call with telemetry enabled.

@omegascorp

Copy link
Copy Markdown
Collaborator

Hi @flcrom, a quick follow-up on the review. #422 has since landed and added logError in @/telemetry, which makes the requested change simpler: at each call site, logError('Error handling magic link landing', { error }) followed by captureError(error) covers both stdout and APM, so the extra message parameter on captureError may not be needed. The branch also conflicts with main now after recent auth changes (#413, #418, #423) and needs a rebase. Can you pick this up in the next week or so? If not, no problem: we'll finish it on your branch and keep your commit.

@omegascorp omegascorp mentioned this pull request Nov 9, 2026
3 of 4 tasks
@omegascorp

Copy link
Copy Markdown
Collaborator

Thanks @flcrom for picking this up and for the clear write-up. Since we didn't hear back, we finished it in #454: each call site now prints with logError and also reports with captureError, so the errors stay on the Logs page when telemetry is on. Your authorship is kept on the commit via Co-authored-by. Closing this one in favor of #454.

@omegascorp omegascorp closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry: Replace console.error with captureError in resetPassword landing handler

2 participants