Task 65 — Mesh observability
Phase: 4
Initiative: 25
Status: done
Owner: —
Slug: mesh-observability
Goal
Каждый локальный и межагентный шаг эмитит коррелированные traces, метрики и структурированные логи. Mesh-трафик, routing-решения, ретраи и взаимодействия с хранилищами видимы и атрибутируемы per request и per agent.
Acceptance criteria
Sub-tasks
- Wire
IMeshObservabilityServiceintoCapabilityMeshRouter: emit routing decision spans +routing_decisionmetrics per RouteAsync call - Wire
IMeshObservabilityServiceintoResilientTransport: emit retry spans +retry_attempt+circuit_breaker_state_changemetrics - Wire
IMeshObservabilityServiceintoIntentRouter: emit delegation spans (outbound/inbound) with trace context propagation - Add
IMeshObservabilityServiceoptional injection toTaskLifecycleProtocolfor observability on task lifecycle events - Add
IMeshObservabilityServiceoptional injection toFanOutOrchestratorfor fan-out spans - Add
MeshObservabilityControllerwithGET /api/mesh/observability/statusendpoint - Wire
IMeshObservabilityServiceinMeshServiceExtensionsDI (already wired; verify) - Add unit tests in
tests/Phase4Tests/MeshObservabilityTests.csfor router/router/health/transport observability dotnet build src/agent/Hercules.csproj— 0 errorsdotnet test— all Phase 4 tests pass
Scope / Likely files
src/agent/Mesh/Observability/, src/agent/Observability/MeshEnrichment.cs
Dependencies
- блокирует / опирается на: task_013 — opentelemetry
- блокирует / опирается на: task_041 — inter-agent-audit
- блокирует / опирается на: task_043 — mesh-router
Risks / Rollback
PII и секреты в трейсах; централизованная redaction + sampling policy.
Implementation notes
Date: 2026-08-14
src/agent/Mesh/Router/MeshRouter.cs — added IMeshObservabilityService? optional dependency:
RouteAsyncemitsrouting_decisionmetric (0 when disabled, N candidates when enabled)RouteCoreAsyncstartsMeshRouter.Routespan, enriches with top candidate agent IDRecordMeshEvent("router.completed")on span completion
src/agent/Mesh/Resilience/ResilientTransport.cs — added IMeshObservabilityService?:
SendAsyncstartsResilientTransport.Sendspan with peer + intent tags- Per-attempt child spans:
ResilientTransport.Retry.{N}with success/failure events RecordMeshEvent("transport.success/failure")per attempt with latencyRecordMeshMetric("retry_attempt")before each retry- Circuit-open rejection emits
resilience.circuit_openevent resilience.exhaustedevent when all retries fail
src/agent/Mesh/IntentRouter.cs — added IMeshObservabilityService?:
RouteAsyncstartsIntentRouter.Delegatespan for peer delegationEnrichSpanWithMeshTagswith intent, sender, receiver, delegation depth, hop countInjectTraceContextfor W3C/B3 propagationdelegationcounter,delegation.success/failureevents,delegation_latency_mshistogram- Trace context propagated via
TraceContextCarrier
src/agent/Mesh/TaskLifecycle/TaskLifecycleProtocol.cs — added optional IMeshObservabilityService constructor param.
src/agent/Mesh/Router/FanOutOrchestrator.cs — added optional IMeshObservabilityService:
OrchestrateFanOutAsyncstartsFanOut.Orchestratespanfanout.no_peersevent when no peers available
src/agent/Mesh/Observability/MeshObservabilityService.cs — added retry_attempt case to RecordMeshMetric.
src/agent/Mesh/MeshServiceExtensions.cs — updated DI registrations to pass IMeshObservabilityService:
IntentRouter,TaskLifecycleProtocol,ResilientTransport,FanOutOrchestrator— all getsp.GetService<IMeshObservabilityService>()(null-safe)
src/agent/Hercules.WebApi/Controllers/MeshObservabilityController.cs — new controller:
GET /api/mesh/observability/status— enabled flag + full configGET /api/mesh/observability/config— basic enabled state
src/agent/Hercules.WebApi/Program.cs — added app.MapMeshObservability().
Tests: tests/Phase4Tests/MeshObservabilityTests.cs — 9 tests (all pass):
MeshObservabilityService_RecordMeshMetric_RetryAttempt_NoThrowMeshObservabilityService_RecordMeshMetric_UnknownMetric_NoThrowMeshObservabilityService_IsEnabled_ReflectsConfig(true/false)CapabilityMeshRouter_RouteAsync_EmitsMetric_WhenDisabledCapabilityMeshRouter_RouteAsync_CallsObservabilityWhenEnabledCapabilityMeshRouter_RouteAsync_WithoutObservability_DoesNotThrowTraceContextCarrier_HasTrace_ReturnsFalse_WhenEmptyTraceContextCarrier_HasTrace_ReturnsTrue_WhenTraceIdSetTraceContextCarrier_AllPropertiesInitialized
Validation:
dotnet build src/agent/Hercules.csproj— 0 errors (pre-existing warnings only)dotnet build src/agent/Hercules.WebApi/Hercules.WebApi.csproj— 0 errorsdotnet build tests/Hercules.Agent.Tests/Hercules.Agent.Tests.csproj— 0 errorsdotnet test --filter "MeshObservabilityTests"— 9/9 passeddotnet test --filter "Phase4Tests"— 284/286 passed (2 pre-existingNumericValidatorTestsfailures)- Backlog: ../backlog.md
- Roadmap (EN): ../../ROADMAP-EN.md
- Roadmap (RU): ../../ROADMAP-RU.md