PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / trunk
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). vtrunk
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / vendor / wordpress / mcp-adapter / includes / Infrastructure / Observability / ConsoleObservabilityHandler.php
commercebird / vendor / wordpress / mcp-adapter / includes / Infrastructure / Observability Last commit date
Contracts 2 months ago ConsoleObservabilityHandler.php 2 months ago ErrorLogMcpObservabilityHandler.php 2 months ago FailureReason.php 2 months ago McpObservabilityHelperTrait.php 2 months ago NullMcpObservabilityHandler.php 2 months ago
ConsoleObservabilityHandler.php
57 lines
1 <?php
2 /**
3 * Console Observability Handler for testing and debugging.
4 *
5 * Outputs formatted observability events to stdout for easy testing.
6 *
7 * @package McpAdapter
8 */
9
10 declare( strict_types=1 );
11
12 namespace WP\MCP\Infrastructure\Observability;
13
14 use WP\MCP\Infrastructure\Observability\Contracts\McpObservabilityHandlerInterface;
15
16 /**
17 * Console-based observability handler for testing.
18 *
19 * Outputs nicely formatted events to stdout/error_log with JSON formatting.
20 */
21 class ConsoleObservabilityHandler implements McpObservabilityHandlerInterface {
22
23 use McpObservabilityHelperTrait;
24
25 /**
26 * Record an event with formatted output.
27 *
28 * @param string $event The event name.
29 * @param array $tags Tags to attach.
30 * @param float|null $duration_ms Duration in milliseconds.
31 *
32 * @return void
33 */
34 public function record_event( string $event, array $tags = array(), ?float $duration_ms = null ): void {
35 $formatted_event = self::format_metric_name( $event );
36 $merged_tags = self::merge_tags( $tags );
37
38 // Create a structured output
39 $output = array(
40 'event' => $formatted_event,
41 'duration_ms' => $duration_ms,
42 'tags' => $merged_tags,
43 'timestamp' => gmdate( 'Y-m-d H:i:s' ),
44 );
45
46 // Pretty print JSON for readability
47 $json = wp_json_encode( $output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
48
49 // Output with visual separator
50 $separator = str_repeat( '=', 80 );
51 $message = "\n{$separator}\n[MCP OBSERVABILITY EVENT]\n{$separator}\n{$json}\n{$separator}\n";
52
53 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
54 error_log( $message );
55 }
56 }
57