Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record trigger_event when recording ErrorEvent #178

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def record(self, event: Event | ErrorEvent):
"""

if self._session is not None and not self._session.has_ended:
if isinstance(event, ErrorEvent):
if event.trigger_event:
event.trigger_event_id = event.trigger_event.id
event.trigger_event_type = event.trigger_event.event_type
self._worker.add_event(event.trigger_event.__dict__)
event.trigger_event = None # removes trigger_event from serialization
self._worker.add_event(event.__dict__)
else:
logger.warning(
Expand Down Expand Up @@ -164,9 +170,6 @@ def _record_event_sync(self, func, event_name, *args, **kwargs):

event.returns = returns
event.end_timestamp = get_ISO_time()
# TODO: If func excepts this will never get called
# the dev loses all the useful stuff in ActionEvent they would need for debugging
# we should either record earlier or have Error post the supplied event to supabase
self.record(event)

except Exception as e:
Expand Down Expand Up @@ -203,9 +206,6 @@ async def _record_event_async(self, func, event_name, *args, **kwargs):

event.returns = returns
event.end_timestamp = get_ISO_time()
# TODO: If func excepts this will never get called
# the dev loses all the useful stuff in ActionEvent they would need for debugging
# we should either record earlier or have Error post the supplied event to supabase
self.record(event)

except Exception as e:
Expand Down Expand Up @@ -271,7 +271,8 @@ def end_session(self,
print('🖇 AgentOps: Could not determine cost of run.')
else:

print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost)))
print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(
token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost)))
self._session = None
self._worker = None

Expand Down
4 changes: 0 additions & 4 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ class ErrorEvent():

def __post_init__(self):
self.event_type = EventType.ERROR.value
if self.trigger_event:
self.trigger_event_id = self.trigger_event.id
self.trigger_event_type = self.trigger_event.event_type
self.trigger_event = None # removes trigger_event from serialization
if self.exception:
self.error_type = self.error_type or type(self.exception).__name__
self.details = self.details or str(self.exception)
Expand Down
Loading