AgentOpsAgentOps 0.4.21 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
11 small wins to finish your pathNext lesson

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.

Exampleerrors.py, after the setup lines
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)
Exampleerrors.py, after the setup lines, continued
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"))
Example
python errors.py

The 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.

Try it yourself
  • Raise inside lookup_order from lesson 3 and print the tree with errors.
  • Catch the exception inside refund and 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.