Option C oc_diagnostics
Loading...
Searching...
No Matches
oc_diagnostics.ui_event_logger Namespace Reference

Functions

str _format_event_value (str prop_name, value)
bool _find_component_id (node, str target_id, int _depth=0)
None _check_store_present (app)
 register_callbacks (app)
 ui_event_logger (app)

Variables

str REQUIRED_STORE_ID = "debug-settings-data-store"
int _MAX_EVENT_VALUE_LEN = 500
 _STRUCTURED_PROPS = frozenset({"figure", "data"})

Detailed Description

UI Event Logger
===============

Purpose
-------
Register a single Dash callback that captures all user interactions across
an instrumented Dash application and routes every genuine event through
``_dbg()``.

Responsibilities
----------------
- Register a universal ``ALL``-pattern ``Input`` callback that listens to
  ``n_clicks``, ``value``, ``data``, ``figure``, and ``selectedData`` on
  all instrumented components (those whose IDs were rewritten to
  ``{"event": "<original-id>"}``).
- Use ``ctx.triggered_prop_ids`` to build the set of ``(original_id,
  prop_name)`` pairs that actually triggered the current cycle, filtering
  out components that are non-``None`` but did not change (e.g. a Dropdown
  holding its default selection).
- Log each genuine user interaction via
  ``_dbg("UI", ..., override=True)`` so UI events always appear in the log
  regardless of domain debug levels.
- Truncate large event values before logging (``_MAX_EVENT_VALUE_LEN``).
  For ``figure`` and ``data`` properties, log type + length summary unless
  ``DEBUG_LEVELS["UI"] >= 9``.
- Emit a clear L1 diagnostic warning when the required
  ``dcc.Store(id=REQUIRED_STORE_ID)`` component is absent from
  ``app.layout`` at registration time.

Diagnostics
-----------
Domain: UI
Levels:
    L2 — lifecycle
    L3 — semantic details
    L4 — deep tracing

Contracts
---------
- Must only log events that actually triggered the current callback cycle.
- Must route all log output through ``_dbg()`` with ``override=True``.
- Requires Dash (``pip install oc_diagnostics[dash]``).
- Must return ``no_update`` from the callback so the store is not dirtied.
- Must not raise; logging failures must be silently swallowed.
- Event values must be truncated to ``_MAX_EVENT_VALUE_LEN`` characters in
  ``repr()`` form before being passed to ``_dbg()``.
- A L1 warning must be emitted when ``REQUIRED_STORE_ID`` is not found in
  ``app.layout`` at ``register_callbacks()`` time.

Function Documentation

◆ _check_store_present()

None oc_diagnostics.ui_event_logger._check_store_present ( app)
protected
Emit a L1 warning if ``REQUIRED_STORE_ID`` is absent from ``app.layout``.

Silently skips the check when:
- ``app.layout`` is ``None`` (layout not yet assigned), or
- ``app.layout`` is a callable (resolved at request time).

Definition at line 131 of file ui_event_logger.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _find_component_id()

bool oc_diagnostics.ui_event_logger._find_component_id ( node,
str target_id,
int _depth = 0 )
protected
Recursively search *node* (a Dash layout) for a component with *target_id*.

Returns ``True`` as soon as a match is found; stops at depth 100 to
avoid performance issues on very large layouts.

Definition at line 110 of file ui_event_logger.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _format_event_value()

str oc_diagnostics.ui_event_logger._format_event_value ( str prop_name,
value )
protected
Return a log-safe string representation of *value*.

For structured properties (``figure``, ``data``) the full repr is only
returned when ``DEBUG_LEVELS["UI"] >= 9``; otherwise a concise type +
length summary is returned.  For all other properties the repr is
truncated at ``_MAX_EVENT_VALUE_LEN`` characters.

Definition at line 91 of file ui_event_logger.py.

Here is the caller graph for this function:

◆ register_callbacks()

oc_diagnostics.ui_event_logger.register_callbacks ( app)
Register the universal UI event logger callback.

This callback listens to the following properties on ALL components
whose IDs were instrumented into {"event": "<original-id>"}:

    - n_clicks
    - value
    - data
    - figure
    - selectedData

These cover all interactive Dash components:
    Buttons, Dropdowns, Inputs, Checklists, Sliders, Stores,
    Graphs, Tabs, etc.

Dash requires explicit property names (no ALL wildcard allowed),
so we register one Input() per property.

Prerequisites
-------------
The layout must contain ``dcc.Store(id=REQUIRED_STORE_ID, ...)``.  A L1
warning is emitted at registration time when this component is not found.

Note
----
The ``ui_event_properties`` setting is read once at callback registration
time.  Changes to ``global_settings.ui_event_properties`` (via config
hot-reload or ``set_global_setting()``) will NOT be picked up by an
already-registered callback — a full application restart is required.

Definition at line 173 of file ui_event_logger.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_event_logger()

oc_diagnostics.ui_event_logger.ui_event_logger ( app)
Convenience wrapper to match existing usage.

Definition at line 270 of file ui_event_logger.py.

Here is the call graph for this function:

Variable Documentation

◆ _MAX_EVENT_VALUE_LEN

int oc_diagnostics.ui_event_logger._MAX_EVENT_VALUE_LEN = 500
protected

Definition at line 75 of file ui_event_logger.py.

◆ _STRUCTURED_PROPS

oc_diagnostics.ui_event_logger._STRUCTURED_PROPS = frozenset({"figure", "data"})
protected

Definition at line 84 of file ui_event_logger.py.

◆ REQUIRED_STORE_ID

str oc_diagnostics.ui_event_logger.REQUIRED_STORE_ID = "debug-settings-data-store"

Definition at line 64 of file ui_event_logger.py.