* 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
155 lines
4.2 KiB
CSS
155 lines
4.2 KiB
CSS
span.phpdebugbar-widgets-value {
|
|
white-space: pre;
|
|
}
|
|
|
|
dl.phpdebugbar-widgets-kvlist.phpdebugbar-widgets-hooklist dt {
|
|
float: left;
|
|
width: 230px;
|
|
padding: 5px;
|
|
border-top: 1px solid #eee;
|
|
font-weight: bold;
|
|
clear: both;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
dl.phpdebugbar-widgets-kvlist.phpdebugbar-widgets-hooklist dt span {
|
|
font-weight: bold;
|
|
}
|
|
dl.phpdebugbar-widgets-kvlist dd {
|
|
margin-left: 240px;
|
|
padding: 5px;
|
|
border-top: 1px solid #eee;
|
|
cursor: pointer;
|
|
min-height: 17px;
|
|
}
|
|
|
|
dl.phpdebugbar-widgets-kvlist dd span {
|
|
display: inline-block;
|
|
}
|
|
|
|
dl.phpdebugbar-widgets-kvlist dd span strong{
|
|
font-weight: bold;
|
|
}
|
|
|
|
dl.phpdebugbar-widgets-kvlist dd span:nth-of-type(1) {
|
|
min-width: 550px;
|
|
margin-right: 20px;
|
|
}
|
|
|
|
dl.phpdebugbar-widgets-kvlist dd span:nth-of-type(2) {
|
|
min-width: 90px;
|
|
margin-right: 20px;
|
|
}
|
|
|
|
dl.phpdebugbar-widgets-kvlist dd span:nth-of-type(3) {
|
|
min-width: 80px;
|
|
margin-right: 20px;
|
|
}
|
|
|
|
/*
|
|
* Additions for the SQL widget
|
|
*/
|
|
|
|
/* Lightweight tracing icon toggle */
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-tracing-icon {
|
|
float: right;
|
|
margin-left: 8px;
|
|
color: #888;
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-tracing-icon:before {
|
|
font-family: "Font Awesome 5 Free" !important;
|
|
font-weight: 900;
|
|
margin-right: 4px;
|
|
font-size: 12px;
|
|
content: "\f070";
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-tracing-icon.phpdebugbar-widgets-tracing-enabled:before {
|
|
content: "\f06e";
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-tracing-icon.phpdebugbar-widgets-tracing-enabled {
|
|
color: #f0ad4e;
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-tracing-icon:hover {
|
|
color: #333;
|
|
}
|
|
|
|
/* Show backtrace button */
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-show-backtrace,
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-copy-clipboard {
|
|
float: right;
|
|
margin-left: 8px;
|
|
color: #888;
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-status span.phpdebugbar-widgets-tracing-icon,
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-status span.phpdebugbar-widgets-show-backtrace,
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-status span.phpdebugbar-widgets-copy-clipboard {
|
|
color: #555;
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-tracing-icon:before,
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-show-backtrace:before,
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-copy-clipboard:before {
|
|
font-family: "Font Awesome 5 Free" !important;
|
|
font-weight: 900;
|
|
margin-right: 4px;
|
|
font-size: 12px;
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-show-backtrace:before {
|
|
content: "\f0cb";
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-show-backtrace.active {
|
|
color: #d9534f;
|
|
}
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-show-backtrace:hover {
|
|
color: #333;
|
|
}
|
|
|
|
/* Backtrace styling */
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-backtrace-container {
|
|
margin: 10px 0;
|
|
padding: 8px;
|
|
background: #f9f9f9;
|
|
border-left: 3px solid #d9534f;
|
|
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
|
font-size: 12px;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-backtrace-header {
|
|
font-weight: bold;
|
|
color: #d9534f;
|
|
margin-bottom: 5px;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-backtrace-toggle {
|
|
font-weight: normal;
|
|
color: #666;
|
|
font-size: 11px;
|
|
margin-left: 5px;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-backtrace-list {
|
|
margin-top: 8px;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-backtrace-frame {
|
|
padding: 4px 0;
|
|
border-bottom: 1px solid #e0e0e0;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-backtrace-frame:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-backtrace-function {
|
|
font-weight: 600;
|
|
color: #333;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
div.phpdebugbar-widgets-sqlqueries span.phpdebugbar-widgets-backtrace-filename {
|
|
color: #888;
|
|
font-style: italic;
|
|
font-size: 11px;
|
|
}
|