Skip to content

Add captureWarning for warnings#1506

Merged
N2D4 merged 1 commit into
devfrom
tembo/add-capture-warning-sentry
May 27, 2026
Merged

Add captureWarning for warnings#1506
N2D4 merged 1 commit into
devfrom
tembo/add-capture-warning-sentry

Conversation

@tembo
Copy link
Copy Markdown
Contributor

@tembo tembo Bot commented May 27, 2026

Summary

Added captureWarning function similar to captureError but logs warnings with console.warn and sends warnings to Sentry with level 'warning'.

  • Updated error sinks to handle 'error' and 'warning' levels.
  • Modified Sentry integration to capture warnings with appropriate level.
  • Replaced console.warn in SessionRecorder flush failure with captureWarning to log and report warnings.

This improves warning handling by integrating with Sentry and consistent logging.


Want tembo to make any changes? Add a comment with @tembo and i'll get back to work!

View on Tembo View Agent Settings


Summary by cubic

Add captureWarning to capture and send warnings to Sentry with the correct level and consistent logging. Error sinks now support levels, and SessionRecorder.flush uses the new warning capture.

  • New Features
    • Added captureWarning(location, error) in @stackframe/stack-shared.
    • Extended error sinks to accept a level ("error" | "warning"); Sentry in apps/backend, apps/dashboard, and packages/stack-cli forwards it to Sentry.captureException.
    • Replaced console.warn in SessionRecorder.flush with captureWarning, wrapping non-OK responses in an Error.

Written for commit 181aa7e. Summary will update on new commits. Review in cubic

…corder flush

Co-authored-by: Konsti <n2d4xc@gmail.com>
@tembo tembo Bot added the tembo Pull request created by Tembo label May 27, 2026
@tembo tembo Bot requested a review from N2D4 May 27, 2026 21:22
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-auth-internal-tool Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-auth-mcp Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-auth-skills Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-backend Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-dashboard Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-demo Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-docs Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-preview-backend Ready Ready Preview, Comment May 27, 2026 9:32pm
stack-preview-dashboard Ready Ready Preview, Comment May 27, 2026 9:32pm

@tembo
Copy link
Copy Markdown
Contributor Author

tembo Bot commented May 27, 2026

Requesting review from @N2D4 who has experience with the following files modified in this PR:

  • apps/backend/src/polyfills.tsx
  • apps/dashboard/src/polyfills.tsx
  • packages/stack-shared/src/utils/errors.tsx

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR adds a captureWarning function that mirrors captureError but routes events through sinks at level \"warning\", and updates all three Sentry sinks to forward that level to captureException. The first production use is in SessionRecorder.flush, replacing two bare console.warn calls.

  • errors.tsx extracts dispatch logic into a shared dispatchToSinks helper and exports the new CaptureLevel type, keeping customCaptureExtraArgs forwarding intact.
  • All three Sentry sinks (backend, dashboard, stack-cli) now pass level to captureException; however, warnings will appear as Exception events in Sentry rather than Message events, which may not match the intended semantic split.
  • session-replay.ts correctly wraps the HTTP failure response in a new Error(...) before calling captureWarning, preserving status code and body text in the message.

Confidence Score: 4/5

Safe to merge; the change is additive and the new warning path is functionally correct in all sinks.

The core logic in errors.tsx is clean and preserves existing behaviour. The main open question is whether Sentry warnings should be exception-type events or message-type events — the current choice means engineers will see warning entries in the Sentry Issues queue alongside real exceptions, which could create noise. The inline type annotations in the polyfills instead of the exported CaptureLevel are a minor coupling risk.

The three Sentry sink files (apps/backend/src/polyfills.tsx, apps/dashboard/src/polyfills.tsx, packages/stack-cli/src/lib/sentry.ts) are worth a second look for the captureException-vs-captureMessage decision.

Important Files Changed

Filename Overview
packages/stack-shared/src/utils/errors.tsx Adds CaptureLevel type, ErrorSink type alias, dispatchToSinks helper, and the new captureWarning function. Logic is sound — customCaptureExtraArgs extraction is correctly preserved in dispatchToSinks.
apps/backend/src/polyfills.tsx Updates sentryErrorSink to accept and pass level to captureException. Uses inline 'error'
apps/dashboard/src/polyfills.tsx Same change as backend polyfills: adds level to sentryErrorSink, same inline type and captureException-for-warnings concerns.
packages/stack-cli/src/lib/sentry.ts Updated registerErrorSink callback to accept and forward level to captureException. Same captureException-for-warnings concern as polyfills.
packages/template/src/lib/stack-app/apps/implementations/session-replay.ts Replaces two console.warn calls with captureWarning to route session-recorder flush failures to Sentry. The error is correctly materialised as a new Error() carrying HTTP status and body text.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[captureError / captureWarning] -->|level: error / warning| B[dispatchToSinks]
    B --> C[Console Sink\nconsole.error / console.warn\nwith ANSI color]
    B --> D[GlobalVar Sink\nstackCapturedErrors.push]
    B --> E[Sentry Sink\npolyfills / stack-cli]
    E --> F[Sentry.captureException\nwith level field]
    G[SessionRecorder.flush] -->|flush error| A
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/backend/src/polyfills.tsx:19
**Sentry exception type used for warnings**

Both the backend and dashboard polyfills (and the CLI sink) call `Sentry.captureException` regardless of `level`. When `level` is `"warning"`, this creates an *Exception* event in Sentry rather than a *Message* event, so warnings land in the Issues section alongside real exceptions. For non-Error values passed to `captureWarning`, Sentry will still try to parse them as exception objects. Using `Sentry.captureMessage` for the `"warning"` branch would keep warnings as message events and errors as exception events, matching Sentry's intended semantic split. The same pattern applies in `apps/dashboard/src/polyfills.tsx` and `packages/stack-cli/src/lib/sentry.ts`.

### Issue 2 of 2
apps/backend/src/polyfills.tsx:13
The `level` parameter is typed inline as `"error" | "warning"` rather than using the exported `CaptureLevel` type from `errors.tsx`. If `CaptureLevel` gains a new variant in the future, this sink silently drops those events without a compile error. Importing and using `CaptureLevel` keeps the sink in sync with the shared contract.

```suggestion
const sentryErrorSink = (location: string, error: unknown, level: import("@stackframe/stack-shared/dist/utils/errors").CaptureLevel) => {
```

Reviews (1): Last reviewed commit: "feat(errors): add captureWarning for war..." | Re-trigger Greptile

return;
}
Sentry.captureException(error, { extra: { location } });
Sentry.captureException(error, { extra: { location }, level });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Sentry exception type used for warnings

Both the backend and dashboard polyfills (and the CLI sink) call Sentry.captureException regardless of level. When level is "warning", this creates an Exception event in Sentry rather than a Message event, so warnings land in the Issues section alongside real exceptions. For non-Error values passed to captureWarning, Sentry will still try to parse them as exception objects. Using Sentry.captureMessage for the "warning" branch would keep warnings as message events and errors as exception events, matching Sentry's intended semantic split. The same pattern applies in apps/dashboard/src/polyfills.tsx and packages/stack-cli/src/lib/sentry.ts.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/backend/src/polyfills.tsx
Line: 19

Comment:
**Sentry exception type used for warnings**

Both the backend and dashboard polyfills (and the CLI sink) call `Sentry.captureException` regardless of `level`. When `level` is `"warning"`, this creates an *Exception* event in Sentry rather than a *Message* event, so warnings land in the Issues section alongside real exceptions. For non-Error values passed to `captureWarning`, Sentry will still try to parse them as exception objects. Using `Sentry.captureMessage` for the `"warning"` branch would keep warnings as message events and errors as exception events, matching Sentry's intended semantic split. The same pattern applies in `apps/dashboard/src/polyfills.tsx` and `packages/stack-cli/src/lib/sentry.ts`.

How can I resolve this? If you propose a fix, please make it concise.

}

const sentryErrorSink = (location: string, error: unknown) => {
const sentryErrorSink = (location: string, error: unknown, level: "error" | "warning") => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The level parameter is typed inline as "error" | "warning" rather than using the exported CaptureLevel type from errors.tsx. If CaptureLevel gains a new variant in the future, this sink silently drops those events without a compile error. Importing and using CaptureLevel keeps the sink in sync with the shared contract.

Suggested change
const sentryErrorSink = (location: string, error: unknown, level: "error" | "warning") => {
const sentryErrorSink = (location: string, error: unknown, level: import("@stackframe/stack-shared/dist/utils/errors").CaptureLevel) => {
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/backend/src/polyfills.tsx
Line: 13

Comment:
The `level` parameter is typed inline as `"error" | "warning"` rather than using the exported `CaptureLevel` type from `errors.tsx`. If `CaptureLevel` gains a new variant in the future, this sink silently drops those events without a compile error. Importing and using `CaptureLevel` keeps the sink in sync with the shared contract.

```suggestion
const sentryErrorSink = (location: string, error: unknown, level: import("@stackframe/stack-shared/dist/utils/errors").CaptureLevel) => {
```

How can I resolve this? If you propose a fix, please make it concise.

@N2D4 N2D4 merged commit 244e7e7 into dev May 27, 2026
34 of 38 checks passed
@N2D4 N2D4 deleted the tembo/add-capture-warning-sentry branch May 27, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tembo Pull request created by Tembo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants