Skip to content

[Feature] Add API span tracking infrastructure (PR #5/9)#13

Merged
sriumcp merged 3 commits intomainfrom
pr5ofjourney
Jan 27, 2026
Merged

[Feature] Add API span tracking infrastructure (PR #5/9)#13
sriumcp merged 3 commits intomainfrom
pr5ofjourney

Conversation

@sriumcp
Copy link
Copy Markdown

@sriumcp sriumcp commented Jan 27, 2026

Add span tracking dict and helper methods to OpenAIServing for future API-side journey tracing. This PR adds infrastructure only - no spans are created or managed yet (deferred to PR #6).

Changes

  • Add _api_spans dict to track (span, arrival_time, first_response_time)
  • Add _cached_is_tracing_enabled flag with defensive error handling
  • Add helper methods: _get_is_tracing_enabled, _store_api_span, _get_api_span_info, _cleanup_api_span
  • Add 8 comprehensive unit tests for dict operations and caching

Key Design Decisions

  • All state is private and lives outside Pydantic models to avoid serialization issues
  • Error handling defaults to False to prevent tracing failures from breaking serving
  • Safe to merge independently - introduces no lifecycle obligations

Testing

All 8 unit tests pass:

  • ✅ Dict initialization
  • ✅ Store/retrieve operations
  • ✅ Missing entry handling (returns safe defaults)
  • ✅ Cleanup safety (idempotent)
  • ✅ Cache behavior (reduces async calls)
  • ✅ Error handling (defensive defaults)
  • ✅ Multi-request independence

Non-Goals (Deferred to PR #6)

  • ❌ No span creation
  • ❌ No span ending
  • ❌ No event emission
  • ❌ No OTEL imports
  • ❌ No lifecycle management

Part of Journey Tracing Series

This is PR #5 of 9 in the dual-stream journey tracing implementation:

🤖 Generated with Claude Code

sriumcp and others added 3 commits January 27, 2026 05:35
Add span tracking dict and helper methods to OpenAIServing for future
API-side journey tracing. This PR adds infrastructure only - no spans
are created or managed yet (deferred to PR #6).

Changes:
- Add _api_spans dict to track (span, arrival_time, first_response_time)
- Add _cached_is_tracing_enabled flag with defensive error handling
- Add helper methods: _get_is_tracing_enabled, _store_api_span,
  _get_api_span_info, _cleanup_api_span
- Add 8 comprehensive unit tests for dict operations and caching

All state is private and lives outside Pydantic models to avoid
serialization issues. Safe to merge independently - introduces no
lifecycle obligations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Mark PR #5 as completed with implementation summary:
- Status: Completed (PR #13 merged)
- Branch: pr5ofjourney
- Size: 67 lines production code, 177 lines test code
- Tests: 8 comprehensive tests, all passing
- Implementation details: Added _api_spans dict, helper methods, and
  defensive error handling

Updated code examples to match actual implementation including
error handling in _get_is_tracing_enabled() method.
Reduce Implementation History from 229 lines to 53 lines (~77% reduction):
- Condensed PR #0-#5 to essential info only (commit, PR number, line stats)
- Removed verbose implementation details (already in individual PR sections)
- Added PR #5 completion entry
- Added summary line: 5 PRs completed, ~350 production lines, ~1022 test lines, 31 tests

Total file size: 2266 → 2089 lines (177 line reduction)
@sriumcp sriumcp merged commit 91fa916 into main Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant