PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wp-media / mcp-oauth / inc / Transport / McpObservabilityHandler.php

McpObservabilityHandler.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/wp-media/mcp-oauth/inc/Transport/McpObservabilityHandler.php

47 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MCP Observability Handler.
4 *
5 * Bridges the MCP adapter's observability interface with this library's
6 * McpLogger, providing structured request/event metrics without external
7 * dependencies. Implements the single-method McpObservabilityHandlerInterface.
8 */
9
10 declare( strict_types=1 );
11
12 namespace WPMedia\MCP\OAuth\Transport;
13
14 use WP\MCP\Infrastructure\Observability\Contracts\McpObservabilityHandlerInterface;
15 use WP\MCP\Infrastructure\Observability\McpObservabilityHelperTrait;
16 use WPMedia\MCP\OAuth\Logging\McpLogger;
17
18 /**
19 * Observability handler that writes MCP events to the MCP OAuth log.
20 */
21 class McpObservabilityHandler implements McpObservabilityHandlerInterface {
22 use McpObservabilityHelperTrait;
23
24 /**
25 * Record an MCP event, optionally with timing data.
26 *
27 * Events are written via McpLogger under the 'OBSERVABILITY' scope.
28 * All events, including error/failure events, are only written when
29 * both WP_DEBUG_LOG and WP_DEBUG are enabled.
30 *
31 * @param string $event Event name (e.g. 'mcp.request', 'mcp.component.registration').
32 * @param array $tags Key-value context tags (status, method, tool_name, etc.).
33 * @param float|null $duration_ms Optional request duration in milliseconds.
34 * @return void
35 */
36 public function record_event( string $event, array $tags = [], ?float $duration_ms = null ): void {
37 $formatted_event = self::format_metric_name( $event );
38 $merged_tags = self::merge_tags( $tags );
39
40 if ( null !== $duration_ms ) {
41 $merged_tags['duration_ms'] = round( $duration_ms, 2 );
42 }
43
44 McpLogger::log( 'OBSERVABILITY', $formatted_event, $merged_tags );
45 }
46 }
47