Skip to content

Audit Phase 4: Tracing Middleware #428

@nycomp

Description

@nycomp

Phase 4: Tracing Middleware

Parent: #424

Tasks

  • Create internal audit client (campus.audit.client)
  • Create tracing core logic (start_span, end_span, build_span_from_context)
  • Create ingestion pipeline (async via ThreadPoolExecutor)
  • Register middleware hooks (deploy.py)
  • Start span, generate/reuse trace_id (uid.generate_trace_id exists)
  • Complete span, record duration, ingest
  • 32-char hex (OpenTelemetry-compatible) - uid.generate_trace_id()
  • 16-char hex - uid.generate_span_id()
  • Safe JSON extraction
  • Extract with 64KB truncation
  • Strip Authorization header before storage
  • Echo X-Request-ID header in response
  • Async span ingestion to avoid blocking requests
  • Handle edge cases (streaming responses, errors, etc.)

Acceptance Criteria

  • Middleware captures all requests automatically
  • Trace IDs are consistent across parent-child spans
  • Authorization headers are stripped
  • Response bodies truncated at 64KB
  • Integration test proves spans are recorded
  • No performance impact on normal requests (< 1ms overhead)

References

  • PRD §4.3: Design Decisions (Authorization stripping)
  • PRD §9.1: Middleware-Based Ingestion
  • PRD §9.3: Sensitive Data
  • PRD §9.4: Body Truncation
  • Plan §6: Middleware for Trace Capture

Status: Implementation complete (~90%), pending integration tests and performance benchmarking

Last Updated: April 10, 2026 - Created internal audit client and implemented full tracing middleware

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Implementation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions