Skip to content

refactor(#10567): run logger plugins in production builds - #10645

Draft
nowgnuesLee wants to merge 1 commit into
feat/gh-10567-posthog-analyticsfrom
refactor/gh-10567-logger-plugins-in-prod
Draft

nowgnuesLee wants to merge 1 commit into
feat/gh-10567-posthog-analyticsfrom
refactor/gh-10567-logger-plugins-in-prod

Conversation

@nowgnuesLee

@nowgnuesLee nowgnuesLee commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Part of #10567

useBAILogger returned before running any plugin when its console output was off, and console output is off in every production build. A plugin registered with logger.use() therefore never saw a production log. This PR keeps the console silent in production but always runs the plugin hooks; with no plugin registered and the console off, logging() still returns immediately, so the default build pays nothing.

It also makes BAIErrorBoundary log the error it catches at ERROR level, with the component stack as logger context, so render errors reach logger plugins (PostHog error tracking in an analytics build, #10644).

Testing:

  • VERIFY_TESTS=1 bash scripts/verify.sh → === ALL PASS ===
  • New packages/backend.ai-ui/src/hooks/useBAILogger.test.ts (5 cases): console output when enabled; plugins run while the console stays silent when disabled; beforeLog aborting skips the console and afterLog; withContext metadata reaches plugins and is cleared afterwards; plugin failures reach onError.

Risk:

Logger plugins now run in production builds; nothing registers one unless the analytics build does.

How to revert:

Revert the merged commit(s) of this PR.

Checklist: (if applicable)

  • Documentation
  • Minimum required manager version (the supported floor is pnpm run dev-env compat, not a number in the repository)
  • Specific setting for review (eg., KB link, endpoint or how to setup)

E2E flow

Compared: none
Result: no flow change
Reason: logging internals only; no screen or step changes.

Logger.enabled is false in production, and logging() returned before any
plugin ran, so a plugin registered with logger.use() never saw a log in a
production build. Console output and plugin dispatch are now separate:
beforeLog/afterLog/onError always run, and only the console call is gated
by `enabled`, so the production console stays silent. With no plugin
registered and the console disabled, logging() still returns immediately.

BAIErrorBoundary now reports the render errors it catches through
useBAILogger at ERROR level, with the component stack as the logger
context, so a logger plugin (the analytics error reporter in the next
layer) sees them.

Adds a focused vitest for the dispatch rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nowgnuesLee
nowgnuesLee added this pull request to stack #10646 October 27, 2026 09:08
@github-actions github-actions Bot added the size:L 100~500 LoC label Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

GitHub Pages may take up to a minute to hydrate after the deploy.

🧩 Changed Components

No component files changed in packages/backend.ai-ui/src/components/.

2 other changed file(s) in packages/backend.ai-ui/
  • packages/backend.ai-ui/src/hooks/useBAILogger.test.ts
  • packages/backend.ai-ui/src/hooks/useBAILogger.tsx

📦 Bundle Size

File Size Gzip
backend.ai-ui.js 1338.0 kB 322.8 kB
dayjs.min-BjziuPGY.js 98.5 kB 27.7 kB
th-DW1HC9yT.js 46.4 kB 9.8 kB
el-DwFHFBMc.js 40.7 kB 10.9 kB
ru-CD4r8kTm.js 38.0 kB 10.3 kB
mn-Bcxmv4aG.js 37.6 kB 10.1 kB
ja-DeIS-xF6.js 32.5 kB 9.5 kB
vi-DvrElrOT.js 30.7 kB 9.1 kB
fr-DLezUzhq.js 29.6 kB 9.1 kB
ko-CVYezqMU.js 29.1 kB 9.1 kB
es-DOGqPBB4.js 28.8 kB 8.8 kB
de-Cxv_DDJp.js 28.7 kB 9.1 kB
it-CxuP9FYL.js 28.6 kB 8.8 kB
pt-BR-Cmj1Srfe.js 28.4 kB 8.7 kB
pt-B1Vcq00v.js 28.3 kB 8.7 kB
pl-D9BdB3IU.js 28.2 kB 9.2 kB
tr-CFtJvQYC.js 27.8 kB 8.9 kB
fi-Bkkfb504.js 27.6 kB 8.8 kB
ms-BMskjiqC.js 26.9 kB 8.4 kB
id-Yctu6r5_.js 26.9 kB 8.4 kB
zh-TW-0jTqNnLf.js 25.3 kB 9.1 kB
zh-CN-Do_WZ2ss.js 25.1 kB 9.0 kB

No base measurement — the merge-base build was skipped (dependency changes, or the base build failed).


Generated by the PR Preview workflow · Storybook · CI run

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report for backend-ai-ui-coverage (./packages/backend.ai-ui)

Status Category Percentage Covered / Total
🔵 Lines 45.45% 3519 / 7742
🔵 Statements 39.38% 4316 / 10958
🔵 Functions 41.65% 664 / 1594
🔵 Branches 27.72% 3005 / 10840
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/backend.ai-ui/src/hooks/useBAILogger.tsx 79.03% 85.71% 55.55% 85.18% 75, 120-132, 169-181
Generated in workflow #1210 for commit 0c6aa4f by the Vitest Coverage Report Action

github-actions Bot added a commit that referenced this pull request Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report for react-coverage (./react)

Status Category Percentage Covered / Total
🔵 Lines 20.88% 8069 / 38632
🔵 Statements 17.68% 10001 / 56566
🔵 Functions 19.39% 1333 / 6873
🔵 Branches 13.2% 7031 / 53240
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
react/src/components/BAIErrorBoundary.tsx 20.51% 0% 7.69% 20.51% 43-66, 94-225, 316-332
Generated in workflow #2446 for commit 0c6aa4f by the Vitest Coverage Report Action

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant