-
Notifications
You must be signed in to change notification settings - Fork 509
feat: Context management for using with that manages trace(s) automatically
#1019
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
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this 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 introduces native context manager support for trace management, enabling developers to use Python’s with statement for automatic trace lifecycle handling. Key changes include:
- Implementation of enter and exit methods on the TraceContext class for automatic state management on trace exit
- Updates to the AgentOps initialization and client retrieval logic, including the addition of a new tool decorator
- New example scripts and documentation demonstrating context manager usage for production, parallel, error handling, and basic scenarios
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/context_manager/production_patterns.py | New production example showcasing API pattern, batch processing, and monitoring using context managers |
| examples/context_manager/parallel_traces.py | New example illustrating sequential, nested, and concurrent trace management |
| examples/context_manager/error_handling.py | New example covering various exception handling patterns with context managers |
| examples/context_manager/basic_usage.py | New basic example demonstrating native TraceContext usage |
| examples/context_manager/README.md | New README outlining context manager examples and usage instructions |
| docs/v2/usage/context-managers.mdx | Documentation update to cover context manager support and usage patterns |
| docs/mint.json | Updated mint config to include context manager usage documentation |
| agentops/sdk/core.py | Added enter and exit implementations to support context management |
| agentops/init.py | Updated client initialization and decorator imports to support new tool decorator and context manager usage |
There was a problem hiding this 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 introduces native context manager support for automatic trace lifecycle management by adding enter and exit methods to the TraceContext class and updating related references from TracingCore to a global tracer. Key changes include support for parallel traces, updated documentation and examples, and enhanced thread safety via a double-checked locking mechanism during client initialization.
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/unit/*.py | Updated comments and patch references to reflect the global tracer rename |
| agentops/sdk/core.py | Added context manager methods and improved end_state type handling |
| agentops/init.py | Updated client initialization with thread safety improvements |
| Other examples and docs (e.g., README.md, .md files) | Revised usage examples and documentation to demonstrate new context manager support |
📥 Pull Request
📘 Description
Added native context manager support to TraceContext class, enabling
with agentops.start_trace("name") as trace:syntax for automatic trace lifecycle management.Basic Usage:
Changelog:
__enter__and__exit__methods toTraceContextclass inagentops/sdk/core.pydocs/v2/usage/context-managers.mdx🧪 Testing
__enter__,__exit__behavior)