Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions livekit-agents/livekit/agents/voice/agent_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ async def start(
room_output_options: NotGivenOr[room_io.RoomOutputOptions] = NOT_GIVEN,
) -> None: ...

@tracer.start_as_current_span("agent_session", end_on_exit=False)
async def start(
self,
agent: Agent,
Expand All @@ -485,13 +484,14 @@ async def start(
if self._started:
return None

self._session_span = current_span = tracer.start_span("agent_session")

self._recorded_events = []
self._room_io = None
self._recorder_io = None

self._closing = False
self._root_span_context = otel_context.get_current()
self._session_span = current_span = trace.get_current_span()
current_span = trace.get_current_span()
current_span.set_attribute(trace_types.ATTR_AGENT_LABEL, agent.label)

Expand Down Expand Up @@ -766,11 +766,12 @@ async def _aclose_impl(
if self._recorder_io:
await self._recorder_io.aclose()

self._started = False
if self._session_span:
self._session_span.end()
self._session_span = None

self._started = False

self.emit("close", CloseEvent(error=error, reason=reason))

self._cancel_user_away_timer()
Expand Down