fix(chat): Improve agent loop tracing#303
Merged
dcramer merged 7 commits intoMay 21, 2026
Merged
Conversation
|
@obostjancic is attempting to deploy a commit to the Sentry Team on Vercel. A member of the Team first needs to authorize it. |
Each iteration of the pi-agent-core agent loop now produces its own gen_ai.chat Sentry span via a traced streamFn wrapper. This gives visibility into individual LLM calls (input/output messages, token usage, finish reasons) nested under the parent gen_ai.invoke_agent span. Co-Authored-By: Claude <[email protected]>
…s and fix traced-stream test key
slackChannelListMessages returned a plain object with the full messages
array as details, causing gen_ai.tool.call.result to exceed the 12k
attribute limit and only appear on error returns. Switch the success path
to a structured { content, details } result where details carries only
the compact metadata (ok, channel_id, count, next_cursor).
Also fix a stale key reference in the traced-stream test (turnId → runId).
Co-Authored-By: Claude <[email protected]>
a9661dd to
faeadbb
Compare
- Set error status (code 2) on the gen_ai.chat span when base() throws or stream.result() rejects, so failed LLM calls appear as errors in Sentry rather than successful spans - Wrap success callback body in try/finally so span.end() is guaranteed even if buildChatEndAttributes or setAttribute throws; suppress the resulting floating rejection with .catch() - Pass createTracedStreamFn() into the advisor context so advisor agent loop iterations also produce gen_ai.chat child spans Co-Authored-By: Claude <[email protected]>
…ents - Add error status rule for failed gen_ai.chat spans to tracing spec - Note traced streamFn now covers the advisor agent loop too - Add gen_ai.chat to Agent And Model spans in TELEMETRY.md - Add gen_ai.tool.call.result to Tools domain attributes Co-Authored-By: Claude <[email protected]>
…ocal constant Removes the duplicated "vercel-ai-gateway" string literal in traced-stream.ts and reuses the canonical GEN_AI_PROVIDER_NAME export already used by all other files in packages/junior/src/chat/pi/. Co-Authored-By: Claude <[email protected]>
…structured result Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4cc8534. Configure here.
…che tokens Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

createTracedStreamFn— wrapsstreamSimpleto emit agen_ai.chatspan per LLM iteration inside the pi-agent-core loop; captures input/output messages, token usage, finish reason, and response model; spans nest under the existinggen_ai.invoke_agentparentslackChannelListMessages: success path now returns a structured{ content, details }result sogen_ai.tool.call.resultis set in Sentry — previously the full messages array swamped the 12k attribute limit and the attribute only appeared on error returnsBefore:

After:
