Errors in traces
An exception raised inside a decorated function marks its span as an error with the exception's message, and the exception still reaches your code.
from agentops.sdk.decorators import operation
@operation
def refund(order_id, amount):
if amount > 100:
raise ValueError(f"refund of {amount} is over the limit")
return "refunded"
@agentops.trace(name="refund-ticket")
def handle(amount):
return refund("A-1002", amount)for amount in [30, 250]:
try:
print(handle(amount))
except ValueError as error:
print("failed:", error)
local_collector.flush()
for span in local_collector.SPANS:
print(span["name"], "| error:", span["error"], "| end state:", span["attributes"].get("agentops.session.end_state"))python errors.pyThe 250 euro refund raised ValueError. Its refund task span got an error status with the exception's type and message, and AgentOps logged the error, the line starting with its logo. The trace span has no error status of its own, but its end state is Indeterminate instead of Success. The 30 euro run has no errors. The decorators do not swallow the exception: handle's caller still caught it.
Error messages are span data like any other. f"refund of {amount} is over the limit" is fine; a message that includes a card number or a customer's address sends it to AgentOps.
- Raise inside
lookup_orderfrom lesson 3 and print the tree with errors. - Catch the exception inside
refundand return a string. What changes? - Raise an exception with a long message and check what is recorded.
You understood something today that you didn't yesterday.