-
Notifications
You must be signed in to change notification settings - Fork 30
feat: trace provider interface #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b5ba6ee
feat: add TraceProvider interface and trace data types
afarntrog 3e8eb89
feat(providers): Add TraceProvider interface for observability backends
afarntrog 73bd27a
feat(providers): Add TraceProvider interface for observability backends
afarntrog 47261a6
Merge branch 'main' into trace_provider
afarntrog 8923de6
refactor: simplify TraceProvider by removing optional methods and Ses…
afarntrog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from .exceptions import ( | ||
| ProviderError, | ||
| SessionNotFoundError, | ||
| TraceNotFoundError, | ||
| TraceProviderError, | ||
| ) | ||
| from .trace_provider import ( | ||
| TraceProvider, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ProviderError", | ||
| "SessionNotFoundError", | ||
| "TraceNotFoundError", | ||
| "TraceProvider", | ||
| "TraceProviderError", | ||
| ] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Exceptions for trace providers.""" | ||
|
|
||
|
|
||
| class TraceProviderError(Exception): | ||
| """Base exception for trace provider errors.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class SessionNotFoundError(TraceProviderError): | ||
| """No traces found for the given session ID.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class TraceNotFoundError(TraceProviderError): | ||
| """Trace with the given ID not found.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class ProviderError(TraceProviderError): | ||
| """Provider is unreachable or returned an error.""" | ||
|
|
||
| pass |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """TraceProvider interface for retrieving agent trace data from observability backends.""" | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
| from ..types.evaluation import TaskOutput | ||
|
|
||
|
|
||
| class TraceProvider(ABC): | ||
| """Retrieves agent trace data from observability backends for evaluation. | ||
|
|
||
| Implementations handle authentication, pagination, and conversion from | ||
| provider-native formats to the types the evals system consumes. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def get_evaluation_data(self, session_id: str) -> TaskOutput: | ||
afarntrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Retrieve all data needed to evaluate a session. | ||
|
|
||
| This is the primary access pattern — given a session ID, fetch all | ||
| traces, extract the agent output and trajectory, and return them | ||
| in a format ready for evaluation. | ||
|
|
||
| Args: | ||
| session_id: The session identifier (maps to Strands session_id) | ||
|
|
||
| Returns: | ||
| TaskOutput with 'output' (final agent response) and | ||
| 'trajectory' (Session containing all traces/spans) | ||
|
|
||
| Raises: | ||
| SessionNotFoundError: If no traces found for session_id | ||
| ProviderError: If the provider is unreachable or returns an error | ||
| """ | ||
| ... | ||
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
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """Tests for TraceProvider ABC and exception hierarchy.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from strands_evals.providers.exceptions import ( | ||
| ProviderError, | ||
| SessionNotFoundError, | ||
| TraceNotFoundError, | ||
| TraceProviderError, | ||
| ) | ||
| from strands_evals.providers.trace_provider import ( | ||
| TraceProvider, | ||
| ) | ||
| from strands_evals.types.evaluation import TaskOutput | ||
| from strands_evals.types.trace import Session | ||
|
|
||
|
|
||
| class ConcreteProvider(TraceProvider): | ||
| """Minimal concrete implementation for testing the ABC.""" | ||
|
|
||
| def __init__(self, session: Session | None = None): | ||
| self._session = session | ||
|
|
||
| def get_evaluation_data(self, session_id: str) -> TaskOutput: | ||
| if self._session is None: | ||
| raise SessionNotFoundError(f"No session found: {session_id}") | ||
| return TaskOutput( | ||
| output="test response", | ||
| trajectory=self._session, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| class TestExceptionHierarchy: | ||
| def test_trace_provider_error_is_exception(self): | ||
| assert issubclass(TraceProviderError, Exception) | ||
|
|
||
| def test_session_not_found_is_trace_provider_error(self): | ||
| assert issubclass(SessionNotFoundError, TraceProviderError) | ||
|
|
||
| def test_trace_not_found_is_trace_provider_error(self): | ||
| assert issubclass(TraceNotFoundError, TraceProviderError) | ||
|
|
||
| def test_provider_error_is_trace_provider_error(self): | ||
| assert issubclass(ProviderError, TraceProviderError) | ||
|
|
||
| def test_exceptions_carry_message(self): | ||
| err = SessionNotFoundError("session-123 not found") | ||
| assert "session-123 not found" in str(err) | ||
|
|
||
| def test_catching_base_catches_all(self): | ||
| """All provider exceptions can be caught with TraceProviderError.""" | ||
| for exc_class in (SessionNotFoundError, TraceNotFoundError, ProviderError): | ||
| with pytest.raises(TraceProviderError): | ||
| raise exc_class("test") | ||
|
|
||
|
|
||
|
|
||
| class TestTraceProviderABC: | ||
| def test_cannot_instantiate_without_get_evaluation_data(self): | ||
| with pytest.raises(TypeError): | ||
| TraceProvider() # type: ignore[abstract] | ||
|
|
||
| def test_concrete_provider_instantiates(self): | ||
| provider = ConcreteProvider() | ||
| assert isinstance(provider, TraceProvider) | ||
|
|
||
| def test_get_evaluation_data_returns_task_output(self): | ||
| session = Session(session_id="s1", traces=[]) | ||
| provider = ConcreteProvider(session=session) | ||
| result = provider.get_evaluation_data("s1") | ||
| assert result["output"] == "test response" | ||
| assert result["trajectory"] == session | ||
|
|
||
| def test_get_evaluation_data_raises_session_not_found(self): | ||
| provider = ConcreteProvider(session=None) | ||
| with pytest.raises(SessionNotFoundError, match="No session found"): | ||
| provider.get_evaluation_data("missing") |
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.
Uh oh!
There was an error while loading. Please reload this page.