MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / __exit__

Method __exit__

agentops/sdk/core.py:47–72  ·  view source on GitHub ↗

Exit the trace context and end the trace. Automatically sets the trace status based on whether an exception occurred: - If an exception is present, sets status to ERROR - If no exception occurred, sets status to OK Returns: False: Always returns False to

(self, exc_type: Optional[type], exc_val: Optional[Exception], exc_tb: Optional[Any])

Source from the content-addressed store, hash-verified

45 return self
46
47 def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], exc_tb: Optional[Any]) -> bool:
48 """Exit the trace context and end the trace.
49
50 Automatically sets the trace status based on whether an exception occurred:
51 - If an exception is present, sets status to ERROR
52 - If no exception occurred, sets status to OK
53
54 Returns:
55 False: Always returns False to propagate any exceptions that occurred
56 within the context manager block, following Python's
57 context manager protocol for proper exception handling.
58 """
59 if exc_type is not None:
60 self._end_state = StatusCode.ERROR
61 if exc_val:
62 logger.debug(f"Trace exiting with exception: {exc_val}")
63 else:
64 # No exception occurred, set to OK
65 self._end_state = StatusCode.OK
66
67 try:
68 tracer.end_trace(self, self._end_state)
69 except Exception as e:
70 logger.error(f"Error ending trace in context manager: {e}")
71
72 return False
73
74
75# get_imported_libraries moved to agentops.helpers.system

Calls 1

end_traceMethod · 0.80