Replace _trace_manager variables with FastAPI dependency injection#78
Merged
krisztianfekete merged 1 commit intomainfrom Mar 31, 2026
Merged
Replace _trace_manager variables with FastAPI dependency injection#78krisztianfekete merged 1 commit intomainfrom
krisztianfekete merged 1 commit intomainfrom
Conversation
97c1f58 to
b510cfa
Compare
There was a problem hiding this comment.
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_managerdependencies and injectsStreamingTraceManagerinto OTLP, streaming, and debug endpoints. - Updates app/OTLP app startup to share the trace manager through
app.state.trace_managerinstead 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces global
_trace_managervariables and setter functions with standard FastAPI dependency injection, making the wiring less brittle and tests simpler.