$tags Event tags. * @param float|null $duration_ms Duration in milliseconds. * @return void */ public function record_event( string $event, array $tags = array(), ?float $duration_ms = null ): void { unset( $duration_ms ); try { if ( 'mcp.request' !== $event ) { return; } ClientsRecorder::record( $this->signals( $tags ) ); } catch ( \Throwable $e ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- A registry failure must never reach the client. error_log( '[acrossai-mcp] ConnectionObservabilityHandler failed: ' . $e->getMessage() ); } } /** * Everything the registry needs to know about this request. * * Assembled from request scope rather than from the tags, because the tags * carry what the adapter measured and none of what identifies the caller. * `server_id` and the session id are the only two that come from tags. * * @since 0.4.8 * @param array $tags Raw event tags. * @return array */ protected function signals( array $tags ): array { $slug = $this->tag( $tags, 'server_id' ); // On `initialize` the `session_id` tag is absent and the id arrives as // `new_session_id` — and `initialize` is the ONE request that carries // clientInfo. Without this coalesce the registry would never learn a // single client's name. $session_id = $this->tag( $tags, 'session_id' ); if ( '' === $session_id ) { $session_id = $this->tag( $tags, 'new_session_id' ); } $user_id = get_current_user_id(); $client = ConnectionContext::client_info( $session_id, $user_id ); return array( 'server_id' => ConnectionContext::server_id_for_slug( $slug ), 'connection_type' => ConnectionContext::resolve_type(), 'connector_slug' => ConnectionContext::connector_slug(), 'client_id' => ConnectionContext::client_id(), 'fleet_host_key' => ConnectionContext::fleet_host_key(), 'client_name' => $client['name'], 'client_version' => $client['version'], 'credential_id' => ConnectionContext::credential_id(), 'credential_hint' => ConnectionContext::credential_hint( $user_id ), 'user_id' => $user_id, 'ip_address' => ConnectionContext::ip_address(), 'user_agent' => ConnectionContext::user_agent(), ); } /** * Read one tag as a trimmed string. * * Defensive by policy: these names live inside the vendor RequestRouter, so * a renamed tag must degrade one field to empty rather than fatal inside a * recording path. The 0.6.1 → 0.7.0 meta-ability episode is the precedent. * * @since 0.4.8 * @param array $tags Event tags. * @param string $key Tag name. * @return string */ protected function tag( array $tags, string $key ): string { return isset( $tags[ $key ] ) && is_scalar( $tags[ $key ] ) ? trim( (string) $tags[ $key ] ) : ''; } }