Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add potential multi-dataset logger #4920

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
mjangda marked this conversation as resolved.
Show resolved Hide resolved
[
'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