-
[OPIK-2488] [P SDK] Add context managers to handle spans and trace creation (#3613)
发布于
2025-10-10 15:27:23 +00:00 - [OPIK-2488] [P SDK] Refactor and enhance span/trace creation flow with modularization
- Introduced
add_start_candidatesfor modular handling of span/trace creation and registration. - Added
extract_distributed_trace_headersfunction inarguments_helpersto streamline header extraction. - Created
SpanCreationResultto encapsulate span/trace creation results. - Implemented
start_as_current_spancontext manager for managing span lifecycles. - Refactored
create_span_respecting_contextto useSpanCreationResultfor cleaner return type and logic.
- [OPIK-2488] [P SDK] Refactor and enhance span/trace creation flow with modularization
- Introduced
add_start_candidatesfor modular handling of span/trace creation and registration. - Added
extract_distributed_trace_headersfunction inarguments_helpersto streamline header extraction. - Created
SpanCreationResultto encapsulate span/trace creation results. - Implemented
start_as_current_spancontext manager for managing span lifecycles. - Refactored
create_span_respecting_contextto useSpanCreationResultfor cleaner return type and logic.
-
[OPIK-2488] [P SDK] Remove redundant error handling logic in
span_context_managerand re-raise the user's error after logging. This allows users to handle its errors directly. -
[OPIK-2488] [P SDK] Fixed import
-
[OPIK-2488] [P SDK] Add
start_as_current_tracecontext manager and enhance trace creation flow
- Introduced
start_as_current_tracecontext manager to manage trace lifecycles. - Enhanced
add_start_trace_candidatefor modular handling of trace creation with active trace logging. - Updated span/trace logic to respect tracing activity and improve error handling consistency.
- [OPIK-2488] [P SDK] Update mock call assertion and add docstring for
trace_context_manager
- Changed
assert_called_oncetoassert_calledin unit test for improved flexibility. - Added comprehensive docstring to
trace_context_managerfor clarity on arguments, functionality, and usage.
- [OPIK-2488] [P SDK] Add unit tests for
start_as_current_tracecontext manager
- Added comprehensive unit tests covering various scenarios for
start_as_current_traceto validate trace lifecycles and parameter handling. - Ensured tests handle minimal and overridden parameter cases, error propagation, and proper metadata logging.
- Exported
start_as_current_tracein the module's public API.
- [OPIK-2488] [P SDK] Add unit test for
start_as_current_spanensuring parent trace reuse
- Added a new unit test to validate that an existing parent trace is reused without creating a new trace.
- Ensured test includes detailed parameter configurations and proper metadata assertions.
- [OPIK-2488] [P SDK] Enhance
span_context_managererror handling and add comprehensive unit test
- Improved error handling by utilizing
error_info_collectorto capture detailed error information in spans and traces. - Refactored span/trace creation logic to ensure consistent data updates during context lifecycle.
- Added unit test to validate error propagation and metadata assertions, covering new model and provider fields.
- [OPIK-2488] [P SDK] Enhance
trace_context_managererror handling and add validation test
- Updated
trace_context_managerto useerror_info_collectorfor capturing detailed error information and set output toNoneon errors. - Added assertion for error trace tree validation in the unit test to ensure correct metadata and error handling.
- Improved client trace saving logic with a
finallyblock to ensure consistent data updates and flushing at the context's end.
- [OPIK-2488] [P SDK] Added documentation
下载附件