发布

  • [OPIK-2488] [P SDK] Add context managers to handle spans and trace creation (#3613)

    frostbyte_neo 发布于 2025-10-10 15:27:23 +00:00

    • [OPIK-2488] [P SDK] Refactor and enhance span/trace creation flow with modularization
    • Introduced add_start_candidates for modular handling of span/trace creation and registration.
    • Added extract_distributed_trace_headers function in arguments_helpers to streamline header extraction.
    • Created SpanCreationResult to encapsulate span/trace creation results.
    • Implemented start_as_current_span context manager for managing span lifecycles.
    • Refactored create_span_respecting_context to use SpanCreationResult for cleaner return type and logic.
    • [OPIK-2488] [P SDK] Refactor and enhance span/trace creation flow with modularization
    • Introduced add_start_candidates for modular handling of span/trace creation and registration.
    • Added extract_distributed_trace_headers function in arguments_helpers to streamline header extraction.
    • Created SpanCreationResult to encapsulate span/trace creation results.
    • Implemented start_as_current_span context manager for managing span lifecycles.
    • Refactored create_span_respecting_context to use SpanCreationResult for cleaner return type and logic.
    • [OPIK-2488] [P SDK] Remove redundant error handling logic in span_context_manager and 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_trace context manager and enhance trace creation flow

    • Introduced start_as_current_trace context manager to manage trace lifecycles.
    • Enhanced add_start_trace_candidate for 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_once to assert_called in unit test for improved flexibility.
    • Added comprehensive docstring to trace_context_manager for clarity on arguments, functionality, and usage.
    • [OPIK-2488] [P SDK] Add unit tests for start_as_current_trace context manager
    • Added comprehensive unit tests covering various scenarios for start_as_current_trace to validate trace lifecycles and parameter handling.
    • Ensured tests handle minimal and overridden parameter cases, error propagation, and proper metadata logging.
    • Exported start_as_current_trace in the module's public API.
    • [OPIK-2488] [P SDK] Add unit test for start_as_current_span ensuring 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_manager error handling and add comprehensive unit test
    • Improved error handling by utilizing error_info_collector to 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_manager error handling and add validation test
    • Updated trace_context_manager to use error_info_collector for capturing detailed error information and set output to None on 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 finally block to ensure consistent data updates and flushing at the context's end.
    • [OPIK-2488] [P SDK] Added documentation
    下载附件