feat(telemetry): add isolated beta quality diagnostics and release identity

This commit is contained in:
dadachann
2026-09-15 09:35:01 +00:00
parent 91d6de8858
commit f8123ead0a
89 changed files with 4205 additions and 175 deletions
+38
View File
@@ -1,5 +1,7 @@
from __future__ import annotations
from ..telemetry import diagnostics
import asyncio
import contextlib
import dataclasses
@@ -368,6 +370,22 @@ class RuntimeBot:
) -> dict[str, typing.Any]:
"""Record structured event routing state while preserving the human log."""
binding = binding or {}
diagnostics.event(
self,
'route',
'route.primary',
{
'not_matched': 'skipped',
'discarded': 'skipped',
'matched': 'started',
'delivered': 'succeeded',
'failed': 'failed',
}.get(status, 'unknown'),
stage='dispatch',
platform_event_type=event_type,
processor_type=target_type or binding.get('target_type', ''),
reason_code=failure_code or status,
)
metadata = {
'kind': 'event_route_trace',
'event_type': event_type,
@@ -380,6 +398,16 @@ class RuntimeBot:
'reason': reason or text,
'run_id': run_id,
}
diagnostics.set_outcome(
{
'not_matched': 'skipped',
'discarded': 'skipped',
'matched': 'started',
'delivered': 'succeeded',
'failed': 'failed',
}.get(status, 'unknown'),
reason_code=failure_code or status,
)
log_method = getattr(self.logger, level, self.logger.info)
await log_method(text, metadata=metadata)
return metadata
@@ -835,6 +863,7 @@ class RuntimeBot:
processor_id=agent.get('uuid'),
)
@diagnostics.observe('event', 'platform.receive', source='platform', stage='dispatch')
async def _handle_platform_event(
self,
event: platform_events.EBAEvent,
@@ -864,6 +893,7 @@ class RuntimeBot:
if isinstance(result, BaseException):
await self.logger.error(f'Event delivery failed: {result}')
@diagnostics.observe('route', 'route.subscription', source='platform', stage='dispatch')
async def _dispatch_plugin_subscription(self, event, adapter, processor_uuid):
event_type = event.type
event_binding = {
@@ -882,6 +912,7 @@ class RuntimeBot:
# Resolve the installed declaration each time, including after plugin updates.
patterns = descriptor.supported_event_patterns
if not patterns or not self._agent_supports_event_type(patterns, event_type):
diagnostics.set_outcome('skipped', reason_code='not_matched')
return
agent = {**agent, 'supported_event_patterns': patterns}
return await self._dispatch_eba_event_to_processor(event, adapter, event_binding, agent)
@@ -898,6 +929,7 @@ class RuntimeBot:
text=f'Plugin processor {processor_uuid} failed: {exc}',
)
@diagnostics.observe('route', 'route.dispatch', source='platform', stage='dispatch')
async def _dispatch_eba_event_to_processor(
self,
event: platform_events.EBAEvent,
@@ -1165,6 +1197,7 @@ class RuntimeBot:
except Exception as e:
await self.logger.error(f'Failed to record discarded message: {e}')
@diagnostics.observe('event', 'platform.legacy_receive', source='platform', stage='dispatch')
async def _handle_legacy_message_event(
self,
event: platform_events.FriendMessage | platform_events.GroupMessage,
@@ -1250,6 +1283,7 @@ class RuntimeBot:
execution_context=self.execution_context,
)
@diagnostics.observe('interaction', 'interaction.submit', source='platform', stage='dispatch')
async def _handle_interaction_submission(
self,
event: platform_events.PlatformSpecificEvent,
@@ -1358,6 +1392,7 @@ class RuntimeBot:
execution_context=self.execution_context,
)
@diagnostics.observe('interaction', 'interaction.resume', source='platform', stage='resume')
async def _resume_agent_interaction(
self,
record: dict[str, typing.Any],
@@ -1512,6 +1547,9 @@ class RuntimeBot:
return
await self._handle_platform_event(self._legacy_message_to_eba_event(event, adapter), adapter)
from ..telemetry.diagnostic_catalog import snapshot_bot
snapshot_bot(self)
get_supported_events = getattr(self.adapter, 'get_supported_events', None)
supported_events: list[str] = []
if callable(get_supported_events):