Skip to content

Conversation

tonyghiani
Copy link
Contributor

@tonyghiani tonyghiani commented Oct 3, 2025

📓 Summary

This PR addresses the issue of noisy XState console logging in development mode by introducing runtime toggling functionality. Previously, the XState inspector logged all state machine events directly to the console, which interfered with debugging other application features.

Screen.Recording.2025-10-03.at.17.23.06.mov

🎯 Problem

As discussed in the team thread, the XState console inspector was always active in dev mode, causing excessive console noise. The original implementation used:

const log = console.info.bind(console);

This meant all XState state machine events, transitions, and snapshots were logged unconditionally, making it difficult for developers to debug non-XState-related issues when the console was cluttered with state machine information.

Context from discussion:

  • XState v5 no longer supports the Redux DevTools extension, requiring a custom observable inspector
  • The console inspector was created as a replacement, but lacked conditional control
  • Developers needed a way to enable/disable logging without code changes
  • Browser-side toggling was preferred over environment variables (which are harder to forward to the browser)

🔧 Solution & Usage

To enable XState logging:

  1. Open your browser's DevTools console
  2. Run: toggleXstateInspector()
  3. You'll see: ℹ️ XState inspector enabled
  4. All XState events will now be logged to the console

To disable XState logging:

  1. Run toggleXstateInspector() again
  2. You'll see: ℹ️ XState inspector disabled
  3. Console logging stops immediately

On page load:

  • You'll see a one-time help message: ℹ️ To toggle the XState inspector, for advanced debugging, run toggleXstateInspector() on your browser console.
  • XState logging is disabled by default
  • The console remains clean unless you explicitly enable it

💡 Technical Notes

  • Opt-in by default: Logging is disabled on initialization, keeping the console clean
  • Dev mode only: The inspector is only available when isDevMode() returns true
  • Persistence: The toggle state is persisted across page reloads
  • No code changes needed: Developers can enable/disable logging at runtime without modifying source code or rebuilding

@tonyghiani tonyghiani requested a review from a team as a code owner October 3, 2025 15:38
@tonyghiani tonyghiani added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:obs-ux-logs Observability Logs User Experience Team labels Oct 3, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-logs-team (Team:obs-ux-logs)

@elasticmachine
Copy link
Contributor

💔 Build Failed

Failed CI Steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-logs Observability Logs User Experience Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants