-
Notifications
You must be signed in to change notification settings - Fork 509
Better root span management #999
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
…racing, allowing concurrent traces.
…ving session handling. Added `trace`, `session`, `agent`, `task`, `workflow`, and `operation` decorators for better instrumentation. Updated `log_trace_url` to include titles for improved logging context. Refactored `Client` initialization trace name and adjusted end trace state handling. Improved error handling during trace logging in `TracingCore` and removed deprecated session decorator usage.
…gs`, `auto_init`, `skip_auto_end_session`, and `fail_safe`. Updated documentation to reflect changes and merged `tags` with `default_tags` for improved session management. Refactored client initialization to accommodate new options.
|
closes #999 |
bboynton97
left a comment
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.
definitely want tests to pass before merging. we should also add tests for the multi-session functionality as well as a test script / example :)
very nice work Dwij!!
…ession` in `agentops` module. This change improves code clarity and aligns with the updated session management approach.
…cessor. Added tests for start and end trace URL logging, handling failures gracefully, and verifying root span tracking. Improved test coverage for session decorators and ensured proper handling of unsampled spans. Refactored existing tests for clarity and consistency.
…nd attribute tracking. Updated span creation to use dynamic workflow names and improved error handling. Adjusted span kinds from CLIENT to INTERNAL for better clarity in tracing. Streamlined attribute setting for agents and tasks, ensuring accurate logging of results and metrics.
…r, simplifying the flush process. Updated logging to indicate completion of the flush operation.
…ditions for the API key. Only trigger a warning if a different non-None API key is provided during re-initialization, enhancing the clarity of client behavior.
… legacy session wrapper. Update unit tests to enhance coverage for new session management functionality, including explicit trace handling and decorator behavior. Ensure proper integration between new and legacy APIs for session and trace management.
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
…xception handling for token fetching and response processing, ensuring clearer error logging and re-raising of exceptions for better testability. Updated integration tests to reset client state between tests.
…on and error handling. Mock API client and tracing core to avoid real authentication during tests. Simplify concurrency test descriptions and ensure proper cleanup of client state between tests.
…ng all active traces when no context is provided. Refactor end_all_sessions to utilize the new end_trace functionality, ensuring legacy global state is cleared. Introduce thread-safe handling of active traces in TracingCore with locking mechanisms for improved concurrency.
… for invalid trace IDs. This ensures robustness when dealing with mocked spans or non-integer trace IDs, improving overall trace management reliability.
…agentops into better-root-span-management
…figuration and initialization. This allows for customizable trace/session naming, improving trace management and clarity in logs. Updated relevant classes and methods to utilize the new parameter.
…agentops into better-root-span-management
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 improves root span management in the AgentOps SDK by enhancing trace lifecycle handling and updating the tracing API. Key changes include:
- Introducing explicit start_trace and end_trace functions with improved configuration (including a trace name parameter)
- Refactoring session management in the client and deprecating legacy session handling
- Updating decorator behavior and telemetry shutdown procedures
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/test_session_concurrency.py | Updated test cases to reflect removal of legacy session decorators and improved error handling |
| tests/integration/test_auth_flow.py | Added client reset fixture for consistent auth flow testing |
| agentops/semconv/span_attributes.py | Added new span attribute for session end state |
| agentops/sdk/processors.py | Removed duplicate log_trace_url calls to streamline span logging |
| agentops/sdk/decorators/factory.py | Introduced type hints and parameter “tags” in decorators, along with enhanced logging messages |
| agentops/sdk/core.py | Added start_trace/end_trace methods with TraceContext management and improved shutdown flushing |
| agentops/instrumentation/crewai/instrumentation.py | Adapted workflow span naming to use configurable trace_name |
| agentops/helpers/dashboard.py | Updated log_trace_url to include an optional title for better logging context |
| agentops/config.py | Extended configuration to support default trace name |
| agentops/client/client.py | Refactored auto-start trace logic and re-initialization handling, deprecating global variables for legacy sessions |
| agentops/client/api/versions/v3.py | Improved error logging in auth token processing |
| agentops/init.py | Added start_trace/end_trace API and integrated new trace_name configuration in SDK init |
Comments suppressed due to low confidence (1)
agentops/init.py:193
- Auto-initializing the SDK within start_trace may lead to side effects; consider requiring explicit initialization to ensure predictable behavior and clearer control flow for SDK consumers.
if not tracing_core.initialized { ... init() // Attempt to initialize with environment variables / defaults
…ne code and improve clarity.
dot-agi
left a comment
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
📘 Description
Closes #991
Enhance AgentOps SDK with tracing capabilities
start_traceandend_tracefunctions for user-managed tracing, allowing concurrent traces.initmethod to handle auto-starting traces and improved session management.tracedecorator. Updatedlog_trace_urlto include titles for improved logging context.This is a hybrid approach:
agentops.init() will start a main trace (let's call it the "init trace" or "auto-trace").
This "init trace" will be automatically managed and ended when the program exits. This means we need to reinstate a form of atexit handling for this specific trace if and only if it was started by init and auto_start_session was true.
agentops.init() will not return this automatically managed session/trace object to the user. If it did, and the user also tried to end it, it could lead to double-ending.
Users can still call agentops.start_trace() to create additional, independent traces.
agentops.start_trace() will return a Trace (or Session-like) object.
Users will be responsible for explicitly ending these traces using agentops.end_trace(trace_object).
These explicit traces will allow for multiple concurrent, user-managed traces, independent of the "init trace."
auto_start_session=False:
If agentops.init(auto_start_session=False) is called, no "init trace" is automatically started.
init() would return None in this case.
The user is then fully responsible for starting and ending all traces using agentops.start_trace() and agentops.end_trace().
🧪 Testing
View the test code gist