Skip to content

Replace _trace_manager variables with FastAPI dependency injection#78

Merged
krisztianfekete merged 1 commit intomainfrom
chore/trace-manager-refactor
Mar 31, 2026
Merged

Replace _trace_manager variables with FastAPI dependency injection#78
krisztianfekete merged 1 commit intomainfrom
chore/trace-manager-refactor

Conversation

@krisztianfekete
Copy link
Copy Markdown
Contributor

This PR replaces global _trace_manager variables and setter functions with standard FastAPI dependency injection, making the wiring less brittle and tests simpler.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates trace manager wiring from module-level globals/setters to FastAPI dependency injection via app.state, reducing hidden state and simplifying test setup for OTLP + streaming/debug routes.

Changes:

  • Introduces get_trace_manager / require_trace_manager dependencies and injects StreamingTraceManager into OTLP, streaming, and debug endpoints.
  • Updates app/OTLP app startup to share the trace manager through app.state.trace_manager instead of setter functions.
  • Refactors tests and integration fixtures to pass/set the manager explicitly and patches the new internal helper used by evaluation routes.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_otlp_receiver.py Updates OTLP processing tests to pass mgr explicitly into _process_traces/_process_logs.
tests/test_api.py Switches live wiring to app.state.trace_manager, updates patches to _do_create_eval_set, and adjusts expected status for debug load when live mode is off.
tests/integration/conftest.py Sets test_app.state.trace_manager in ASGI fixtures and forwards main app manager into otlp_app for live server tests.
src/agentevals/api/streaming_routes.py Removes global manager/setter; injects manager via Depends(require_trace_manager) and factors shared eval-set creation into _do_create_eval_set.
src/agentevals/api/otlp_routes.py Removes _trace_manager global/setter; injects manager via Depends(require_trace_manager) and threads it through processing helpers.
src/agentevals/api/otlp_app.py Copies trace_manager from main app state into OTLP app state during lifespan.
src/agentevals/api/dependencies.py Adds FastAPI dependencies for optional/required access to request.app.state.trace_manager.
src/agentevals/api/debug_routes.py Removes _trace_manager global/setter; injects manager (optional for bundle, required for load).
src/agentevals/api/app.py Removes trace manager globals/setters; creates/uses app.state.trace_manager in live mode and during lifespan cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@krisztianfekete krisztianfekete merged commit a56f5fb into main Mar 31, 2026
8 checks passed
@krisztianfekete krisztianfekete deleted the chore/trace-manager-refactor branch March 31, 2026 10:03
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.

2 participants