fix sandbox replace trace identity
This commit is contained in:
parent
dff28efecf
commit
02770bce7d
3 changed files with 120 additions and 7 deletions
|
|
@ -67,10 +67,22 @@ class CreateSandbox:
|
|||
return session
|
||||
|
||||
result = 'created'
|
||||
new_session_id: UUID | None = None
|
||||
if session is not None:
|
||||
result = 'replaced'
|
||||
span.set_attribute('session.id', str(session.session_id))
|
||||
span.set_attribute('container.id', session.container_id)
|
||||
new_session_id = _new_session_id()
|
||||
span.set_attribute(
|
||||
'sandbox.previous_session.id',
|
||||
str(session.session_id),
|
||||
)
|
||||
span.set_attribute(
|
||||
'sandbox.previous_container.id',
|
||||
session.container_id,
|
||||
)
|
||||
span.set_attribute(
|
||||
'sandbox.new_session.id',
|
||||
str(new_session_id),
|
||||
)
|
||||
self._logger.info(
|
||||
'sandbox_replaced',
|
||||
attrs=_sandbox_attrs(session),
|
||||
|
|
@ -81,16 +93,24 @@ class CreateSandbox:
|
|||
|
||||
created_at = self._clock.now()
|
||||
expires_at = created_at + self._ttl
|
||||
session_id = _new_session_id()
|
||||
span.set_attribute('session.id', str(session_id))
|
||||
if new_session_id is None:
|
||||
new_session_id = _new_session_id()
|
||||
span.set_attribute('session.id', str(new_session_id))
|
||||
new_session = self._runtime.create(
|
||||
session_id=session_id,
|
||||
session_id=new_session_id,
|
||||
chat_id=chat_id,
|
||||
created_at=created_at,
|
||||
expires_at=expires_at,
|
||||
)
|
||||
if result == 'replaced':
|
||||
span.set_attribute(
|
||||
'sandbox.new_container.id',
|
||||
new_session.container_id,
|
||||
)
|
||||
self._repository.save(new_session)
|
||||
_set_active_count(self._metrics, self._repository)
|
||||
if result == 'replaced':
|
||||
span.set_attribute('session.id', str(new_session.session_id))
|
||||
span.set_attribute('container.id', new_session.container_id)
|
||||
span.set_attribute('sandbox.result', result)
|
||||
self._metrics.increment(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue