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

Traces by hand: start_trace, tags and end state

start_trace and end_trace mark a trace around any code, with tags for filtering and an end state. As a context manager, the trace ends when the block does.

Examplemanual.py
trace = agentops.start_trace("refund-ticket", tags=["refunds", "tier-1"])
decision = "approved"
agentops.end_trace(trace, end_state="Success")

with agentops.start_trace("parcel-ticket", tags=["delivery"]):
    pass

local_collector.flush()
for span in local_collector.SPANS:
    attributes = span["attributes"]
    print(span["name"], attributes.get("agentops.tags"), attributes.get("agentops.session.end_state"))
Example
python manual.py

start_trace returns a trace context; end_trace takes it and an end_state, recorded on the root span. Tags, a list or a dictionary, are recorded as agentops.tags and are what the dashboard filters by: a customer, a product area, a release. The with form ended the second trace when the block finished, without an end state here because nothing set one.

Use manual traces where a decorator does not fit: a web request handler, a queue worker, a script with several phases.

Try it yourself
  • Set end_state="Failure" and print the result.
  • Pass tags={"customer": "acme", "tier": 1}.
  • Start a trace inside another and print the tree.

Little by little, you're building something great.