async def _handle_turn_ended(self, turn_number: int, duration: float, was_interrupted: bool):
        """Handle a turn end event by ending the current span."""
        if not is_tracing_available() or not self._current_span:
            return

        # Only end the span if it matches the current turn
        if turn_number == self._current_turn_number:
            # Set additional attributes
            self._current_span.set_attribute("turn.duration_seconds", duration)
            self._current_span.set_attribute("turn.was_interrupted", was_interrupted)

            # End the span
            self._current_span.end()
            self._current_span = None

            # Clear the context provider
            context_provider = TurnContextProvider.get_instance()
            context_provider.set_current_turn_context(None)

            logger.debug(f"Ended tracing for Turn {turn_number}")
Handle a turn end event by ending the current span.
src/pipecat/utils/tracing/turn_trace_observer.py