Skip to content

Commit

Permalink
Add potential multi-dataset logger (#4920)
Browse files Browse the repository at this point in the history
* Add potential multi dataset logger

* Sanitize fields

* Use esc_url_raw since sanitize_url is deprecated

* Update prometheus-collectors/class-potential-multi-dataset-queries-collector.php

Co-authored-by: Mohammad Jangda <[email protected]>

* Check if log2logstash is defined before calling it

---------

Co-authored-by: Mohammad Jangda <[email protected]>
  • Loading branch information
luismulinari and mjangda authored Oct 5, 2023
1 parent 280f1c3 commit a6adfed
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Prometheus\Counter;
use Prometheus\RegistryInterface;
use function Automattic\VIP\Logstash\log2logstash;

class Potential_Multi_Dataset_Queries_Collector implements CollectorInterface {
private Counter $potential_multi_dataset_queries_collector;
Expand Down Expand Up @@ -49,6 +50,27 @@ public function sql_query_log( $query ): void {
$blog_ids_count >= 3 ? '3+' : (string) $blog_ids_count,
]
);

if ( ! function_exists( '\Automattic\VIP\Logstash\log2logstash' ) ) {
return;
}

$backtrace = function_exists( 'wp_debug_backtrace_summary' ) ? wp_debug_backtrace_summary( null, 4, false ) : []; // phpcs:ignore
\Automattic\VIP\Logstash\log2logstash(
[
'severity' => 'debug',
'feature' => 'potential_multi_dataset_queries',
'message' => 'Potential multi dataset query detected',
'extra' => [
'uri' => isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( $_SERVER['REQUEST_URI'] ) : '',
'http_method' => isset( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( $_SERVER['REQUEST_METHOD'] ) : '',
'backtrace' => $backtrace,
'last_global_table' => $last_global_table,
'last_blog_table' => $last_blog_table,
'blog_ids_count' => $blog_ids_count,
],
]
);
}
}

Expand Down

0 comments on commit a6adfed

Please sign in to comment.