Skip to main content

Search, sessions, agent graph and comments

Lens records every step your agents take. These four views help you find and understand the runs that matter without knowing their ids:

  • Search finds the runs whose steps contain the words you type, for example the order number from a customer complaint or the text of an error.
  • Sessions groups the runs of one conversation, such as every turn of a chat, and shows them as a thread you can read top to bottom.
  • Graph draws one run as a picture of who did what: the agents that ran, the agents they handed work to, and the tools and models each one called.
  • Comments let your team leave notes on a run, for example why it went wrong or which ticket tracks the fix.

They come with the gateway and need no license. They work whenever the gateway is connected to Lens, see Lens.

A real-world scenario​

A customer writes in: "your assistant promised me a refund for order 4471 and nothing happened". The support lead opens Lens, clicks Search, types 4471 refund and presses Enter. One run matches, with the snippet "Customer asks for a refund on order 4471". She clicks it, opens Graph and sees that the support agent called the refund_order tool twice and both calls failed. She opens Sessions from the run's session to read the whole chat, then adds a comment on the run: "refund_order timed out twice, the bot still told the customer it worked. Filed SUP-812." The engineer who picks up SUP-812 opens the same run from the comment's link and finds the note waiting.

Steps​

  1. In the Admin UI open Lens under Observability, or go to /ui/lens.
  2. Click Search, type the words to find (put an exact phrase in "quotes") and press Search. Each result shows the agent, where the words matched (Input, Output, Error or Name) and a short snippet. Click the agent name to open the run.
  3. In the open run, click Graph next to Steps and Thread to see the agents, tools and models of the run. The table under the picture lists every link with its calls, failures and time.
  4. Click Comments, type a note and click Add comment. Your own comments show Edit and Delete.
  5. Click Sessions to list conversations. Type part of a session id in the filter to narrow the list, and click a session to read it as a thread. Open run jumps to that turn's steps, and All sessions goes back.

The same views are API routes. With a key that may read traces:

curl -G http://localhost:4000/v1/traces/search \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
--data-urlencode 'q=4471 refund'

curl http://localhost:4000/v1/traces/sessions -H "Authorization: Bearer $SPANWAY_API_KEY"

curl -G http://localhost:4000/v1/traces/sessions/chat-7f3a \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
--data-urlencode 'session_ref=5E1D9C7B3A2F4E6D8C0B1A3F5E7D9C1B3A5F7E9D1C3B5A7F9E1D3C5B7A9F1E3D'

curl http://localhost:4000/v1/traces/4bf92f3577b34da6a3ce929d0e0e4736/graph \
-H "Authorization: Bearer $SPANWAY_API_KEY"

curl -X POST http://localhost:4000/v1/traces/4bf92f3577b34da6a3ce929d0e0e4736/comments \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"body": "refund_order timed out twice. Filed SUP-812.", "span_id": "00f067aa0ba902b7"}'

Expected result​

The search answers with the matching runs, newest first:

{
"query": "4471 refund",
"terms": ["4471", "refund"],
"searched_fields": ["input", "output", "error", "name"],
"start_ms": 1795078800000,
"end_ms": 1795683600000,
"hits": [
{
"trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
"trace_ref": "9D3C1E0B7A4F2E6D8C5B1A0F3E2D4C6B8A9F7E5D3C1B0A2F4E6D8C0B2A4F6E8D",
"start_ms": 1795683600000,
"matched_spans": 2,
"span_id": "00f067aa0ba902b7",
"span_name": "lookup_refund_policy",
"agent": "support-bot",
"field": "input",
"snippet": "Customer asks for a refund on order 4471 after the parcel arrived damaged"
}
],
"truncated": false
}

A new comment answers 201 with the stored comment, and the run's Comments view lists it with your name.

The search looks at the runs of the last 7 days by default. start_ms and end_ms (unix milliseconds) choose another window of at most 31 days, and limit returns up to 100 runs (50 by default). truncated is true when more runs matched than were returned, so narrow the words or the window.

  • Every word must appear in the same step, in any order, ignoring upper and lower case. Up to 8 words or phrases count, each up to 200 characters.
  • A "quoted phrase" must appear exactly as written, spaces included.
  • The search looks inside step inputs, outputs and error messages, and always in trace ids, step names, agent names and model names. searched_fields lists where it looked for you.

Sessions​

A session is the set of runs that carry the same session id. Your app sets it on each run as the session.id attribute (on the span or on the resource), or as the OpenTelemetry gen_ai.conversation.id attribute. The list shows sessions active in the last 7 days, most recent first, with how many runs they hold, how many steps failed, the tokens used and up to 10 agent names. contains keeps sessions whose id contains that text.

Opening a session shows each run as a turn, oldest first, with the run's first input and its final output, each cut to 4,000 characters. Two different keys can reuse the same session id, so the list gives every session a session_ref. Pass it when you open a session to see only that key's runs, the Admin UI does this for you. Without it, the thread holds every run you may read that uses the id.

Agent graph​

The graph has one node for the run, one for each agent, each tool and each model, and a link for:

  • starts, the run starting a top level agent,
  • hands off to, one agent passing work to another,
  • calls tool and calls model, an agent using a tool or a model.

Every node and link counts calls, failed calls and time, and model nodes add their input and output tokens. Steps that are not agents, such as chains, do not appear, but the steps inside them are linked to the nearest agent above them. A failing link is drawn in red. The graph reads at most the first 5,000 steps of a run and says so when a run was longer. It shows no prompt or answer text.

Comments​

Anyone who may read a run may read its comments. Anyone who may read it can also comment, except the read only roles (admin viewer and internal viewer). You can edit and delete your own comments, and proxy admins can delete anyone's. A comment holds up to 4,000 characters, may point at one step with span_id, and a run holds at most 500 comments. A comment can quote the run it sits on, so it expires with the run: once it is older than AGENT_TRACING_RETENTION_DAYS (14 days by default) the gateway deletes it within the hour, the same time Lens drops the run. Set AGENT_TRACING_RETENTION_DAYS on the gateway to the same value as on Lens, otherwise comments follow the 14 day default. At any time, erasing a person through a data subject request deletes every comment they wrote. Comments are stored in the gateway database, see database tables. Do not paste secrets into comments.

Who sees what​

Search, sessions, graphs and comments only ever show runs you may already read in Lens. Proxy admins and admin viewers see every team's runs. Everyone else sees the runs of their own user and of the teams whose logs they may read, and a key with no user sees none.

When a custom role hides prompts, responses or tool arguments, Lens hides them too:

  • Search does not look inside hidden content, so a hidden prompt can never match or appear in a snippet. Hiding tool arguments also keeps search out of every step's input and error text, because those can quote tool arguments.
  • Sessions return null for hidden inputs or outputs and list them in hidden_fields. Hiding tool arguments hides every input too. The Admin UI shows "Hidden by your role".
  • Steps show [hidden by your role] in place of hidden inputs, outputs, previews, error text and the span attributes that can quote them. A trace step does not say which part of its input is a tool argument, so hiding tool arguments hides step inputs too.
  • Trace SQL (POST /v1/traces/query) is refused for such a role, because a query could read the content directly.

Audit​

Every change and every read of conversation content is written to the audit log:

ActionTableWritten when
created, updated, deletedSpanway_TraceCommentA comment is added, edited or deleted. The row holds the trace, the step, the author, the length of the text and a SHA-256 fingerprint of it, before and after for an edit, never the text. A comment that expired with its run is deleted with changed_by trace_comment_retention.
viewedSpanway_AgentTracesA search looks inside inputs, outputs or errors (object_id trace_search, with a fingerprint and the length of the search text, never the text), or a session is opened (object_id session:<ref>). Both follow the audit_log_content_reads setting. The session list follows audit_log_list_reads.

Errors​

StatusWhat you seeWhat it meansFix
400q must hold at least one word to search forThe search text was only spaces or empty quotes.Type at least one word.
400end_ms must be after start_ms and the window at most 31 daysThe window is backwards or longer than 31 days.Pick a shorter window.
403Not allowed to view agent tracesThe key has no user, so it may not read traces.Use a key that belongs to a user, or a proxy admin key.
403Read only roles cannot change comments on tracesAdmin viewers and internal viewers may read comments only.Ask someone with a writing role.
403Only the author or a proxy admin can change this commentYou tried to edit or delete someone else's comment.Ask its author or a proxy admin.
403Your role hides request content, so it cannot run SQL over tracesYour custom role hides prompts, responses or tool arguments.Use search and sessions, which hide that content for you.
404Trace <id> not found, Session <id> not found or Comment <id> not foundNothing with that id is visible to you.Check the id, and pass trace_ref or session_ref from the list.
409This trace already has 500 commentsThe run holds the most comments allowed.Delete old comments first.
422A validation error naming bodyThe comment is empty, longer than 4,000 characters, or holds control characters.Shorten or clean the text.
500DB not connected. This endpoint needs a database; ...The gateway runs without a database, so comments cannot be stored.Connect the gateway to Postgres.
501Agent tracing is not enabledThe gateway is not connected to Lens.Set SPANWAY_LENS_URL, see Lens.
503Traces are temporarily unavailable. Please try again.Lens did not answer or the search ran past the reader limits.Retry after the Retry-After seconds, or narrow the search.
503Trace SQL queries require a configured proxy master keySearch and sessions run through the trace reader, which needs the master key.Set SPANWAY_MASTER_KEY on the gateway.

See the error reference for every gateway error.

Logs​

LevelLineMeaningAction
WARNINGTrace explorer query returned rows of an unexpected shape: ...Lens answered a search or session read with rows the gateway does not understand, usually because the gateway and Lens versions differ. The caller gets 503.Run the same release of the gateway and Lens.
WARNINGTrace read unavailable: ...Lens could not be reached or failed while reading.Check the Lens worker and SPANWAY_LENS_URL.
INFOtrace comments: deleted <n> comments older than the <days> day agent trace retentionThe hourly retention job deleted comments whose runs Lens no longer keeps. Normal.None. Change AGENT_TRACING_RETENTION_DAYS on the gateway to keep comments longer or shorter.