[Migration #121.6] Implement FastAPI and agent tracing instrumentation #313

Closed
opened 2026-02-04 02:35:59 +00:00 by jason.woltje · 1 comment
Owner

Parent EPIC: #121 - Backend Migration from Jarvis r1
Phase: 3 - OpenTelemetry Infrastructure
Estimate: 1-2 days
Dependencies: Requires #121.5 (OpenTelemetry core)

Description

Migrate automatic instrumentation for FastAPI and custom agent/tool tracing.

Source Files

  • jarvis/core/telemetry.py (FastAPI instrumentation)
  • jarvis/core/agent_tracing.py
  • jarvis/core/tool_tracing.py

Target Implementation

  • Add FastAPI auto-instrumentation
  • Implement agent operation tracing
  • Implement tool execution tracing
  • Add custom span attributes
  • Create trace decorators

Acceptance Criteria

  • FastAPI requests automatically traced
  • Agent operations traced
  • Tool executions traced
  • Custom decorators for tracing
  • Span enrichment with context
  • Unit tests (85% coverage)
**Parent EPIC:** #121 - Backend Migration from Jarvis r1 **Phase:** 3 - OpenTelemetry Infrastructure **Estimate:** 1-2 days **Dependencies:** Requires #121.5 (OpenTelemetry core) ## Description Migrate automatic instrumentation for FastAPI and custom agent/tool tracing. ## Source Files - `jarvis/core/telemetry.py` (FastAPI instrumentation) - `jarvis/core/agent_tracing.py` - `jarvis/core/tool_tracing.py` ## Target Implementation - Add FastAPI auto-instrumentation - Implement agent operation tracing - Implement tool execution tracing - Add custom span attributes - Create trace decorators ## Acceptance Criteria - [ ] FastAPI requests automatically traced - [ ] Agent operations traced - [ ] Tool executions traced - [ ] Custom decorators for tracing - [ ] Span enrichment with context - [ ] Unit tests (85% coverage)
jason.woltje added this to the M4-LLM (0.0.4) milestone 2026-02-04 02:35:59 +00:00
Author
Owner

Issue #313 successfully implemented and merged to develop (commit 6de631c).

Implementation Summary

Added comprehensive OpenTelemetry distributed tracing to the coordinator FastAPI service.

Features Delivered:
FastAPI requests automatically traced via FastAPIInstrumentor
Agent operations traced (@trace_agent_operation decorator)
Tool executions traced (@trace_tool_execution decorator)
Custom decorators supporting both sync and async functions
Span enrichment with context (issue_id, agent_type, agent_id)
Unit tests: 25 tests, 90-91% coverage

Files Added:

  • src/telemetry.py (184 lines) - OTEL SDK initialization
  • src/tracing_decorators.py (158 lines) - Custom decorators
  • tests/test_telemetry.py (181 lines) - Telemetry tests
  • tests/test_tracing_decorators.py (204 lines) - Decorator tests
  • docs/security-review-issue-313.md - Security assessment
  • docs/security-review-issue-313-summary.md - Security summary

Files Modified:

  • src/main.py - Added telemetry initialization and FastAPI instrumentation
  • src/coordinator.py - Added @trace_agent_operation to 3 key methods
  • .env.example - Added OTEL configuration variables
  • pyproject.toml - Added OpenTelemetry dependencies

Quality Gates:
All tests passing (25/25)
Coverage: 90-91% (exceeds 85% requirement)
Zero linting errors (ruff)
Zero type checking errors (mypy)
Security review: APPROVED (no vulnerabilities)
Code review: APPROVED
QA testing: PASS

Configuration:

  • OTEL_ENABLED (default: true)
  • OTEL_SERVICE_NAME (default: mosaic-coordinator)
  • OTEL_EXPORTER_OTLP_ENDPOINT (default: http://localhost:4318/v1/traces)
  • OTEL_DEPLOYMENT_ENVIRONMENT (default: development)
  • OTEL_TRACES_SAMPLER_ARG (default: 1.0)

Tracing is now production-ready and compatible with Jaeger, Tempo, and other OTLP backends.

Issue #313 successfully implemented and merged to develop (commit 6de631c). ## Implementation Summary Added comprehensive OpenTelemetry distributed tracing to the coordinator FastAPI service. **Features Delivered:** ✅ FastAPI requests automatically traced via FastAPIInstrumentor ✅ Agent operations traced (@trace_agent_operation decorator) ✅ Tool executions traced (@trace_tool_execution decorator) ✅ Custom decorators supporting both sync and async functions ✅ Span enrichment with context (issue_id, agent_type, agent_id) ✅ Unit tests: 25 tests, 90-91% coverage **Files Added:** - src/telemetry.py (184 lines) - OTEL SDK initialization - src/tracing_decorators.py (158 lines) - Custom decorators - tests/test_telemetry.py (181 lines) - Telemetry tests - tests/test_tracing_decorators.py (204 lines) - Decorator tests - docs/security-review-issue-313.md - Security assessment - docs/security-review-issue-313-summary.md - Security summary **Files Modified:** - src/main.py - Added telemetry initialization and FastAPI instrumentation - src/coordinator.py - Added @trace_agent_operation to 3 key methods - .env.example - Added OTEL configuration variables - pyproject.toml - Added OpenTelemetry dependencies **Quality Gates:** ✅ All tests passing (25/25) ✅ Coverage: 90-91% (exceeds 85% requirement) ✅ Zero linting errors (ruff) ✅ Zero type checking errors (mypy) ✅ Security review: APPROVED (no vulnerabilities) ✅ Code review: APPROVED ✅ QA testing: PASS **Configuration:** - OTEL_ENABLED (default: true) - OTEL_SERVICE_NAME (default: mosaic-coordinator) - OTEL_EXPORTER_OTLP_ENDPOINT (default: http://localhost:4318/v1/traces) - OTEL_DEPLOYMENT_ENVIRONMENT (default: development) - OTEL_TRACES_SAMPLER_ARG (default: 1.0) Tracing is now production-ready and compatible with Jaeger, Tempo, and other OTLP backends.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#313