dolibarr/htdocs/debugbar/js
Alexandre Janniaux 163c51ae31
NEW debugbar: Add backtrace capture for database query failures (#36612)
* debugbar: Add backtrace capture for database query failures

Implements backtrace forwarding to capture and display backtraces when
database queries fail, making it easier for developers to identify the
source of database errors.

Backtrace are captured in TraceableDB::endTracing() when queries fail
using debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) and stored to be
fowarded to the DolQueryCollector that will expose it to the debugbar
integration.

Because of that, the backtrace is now captured at the correct location,
ie. when the query fails, rather than when the error is retrieved,
ensuring it shows the actual application code that triggered the
problematic query.

This is particularly useful for debugging MySQL to PostgreSQL
compatibility issues, module development and maintenance, and quickly
identifying query origins during development. In particular, paired with
the list and time profiling of each request, it will allow finding the
location where queries are not properly optimized.

Before this patch, it was possible to try and find snippets from the
queries but because queries are generated at runtime, it was tedious and
could lead to the wrong location.

Related to #34050

* debugbar: Add SQL query backtrace

Extends the debugbar SQL widget with backtrace display capabilities.

To keep vendor files pristine, a custom widget (TracingSQLQueriesWidget)
extends the vendor SQLQueriesWidget using DOM manipulation to inject
Dolibarr-specific features after parent render completes.

The widget intercepts the parent's data binding callback via
wrapDataBinding() to enhance rendered queries with backtrace buttons.
This patch pattern depends on php-debugbar internals but might break if
the vendor API changes, without breaking the rendering done by
php-debugbar.

A tracing toggle icon in the status bar allows switching between
tracing failed queries only (default, minimal overhead) and tracing
all queries. The setting persists via cookie (debugbar_full_tracing)
which the PHP backend reads to decide whether to capture backtraces.

Custom styles in widgets.css is for the tracing state (eye/eye-slash
icons) and so as to format the backtrace display within a frame and
using monospace font.

Closes #34050
2026-05-03 16:26:33 +02:00
..
widgets.js NEW debugbar: Add backtrace capture for database query failures (#36612) 2026-05-03 16:26:33 +02:00