Skip to content

feat: add agentcore traces command and trace link in invoke TUI#493

Merged
tejaskash merged 10 commits intomainfrom
feat/traces-command
Mar 4, 2026
Merged

feat: add agentcore traces command and trace link in invoke TUI#493
tejaskash merged 10 commits intomainfrom
feat/traces-command

Conversation

@jesseturner21
Copy link
Contributor

@jesseturner21 jesseturner21 commented Mar 4, 2026

Description

Add agentcore traces command with two subcommands for viewing and downloading agent traces, plus a trace console link in the invoke TUI header.

  • agentcore traces list — queries CloudWatch Logs Insights to display recent traces for a deployed agent, with --agent and --limit options
  • agentcore traces get <traceId> — downloads full trace data (OpenTelemetry spans) to a JSON file, with --agent and --output options
  • Always-visible CloudWatch console trace URL in the invoke TUI header, displayed alongside the existing log link

Both CLI commands also print the CloudWatch console URL for quick access to the trace dashboard.

New dependency: @aws-sdk/client-cloudwatch-logs

Related Issue

Closes #

Documentation PR

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

How have you tested the change?

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

Additionally performed full end-to-end manual testing:

Here are the screenshots

result of the list command:
Screenshot 2026-03-04 at 10 13 47 AM
result of the get command:
image
the link to console in the get command:
image
open of the json file for the downloaded trace:
image
Invoke on the tui experience with the link:
image

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

@jesseturner21 jesseturner21 requested a review from a team March 4, 2026 15:19
@github-actions github-actions bot added the size/l PR size: L label Mar 4, 2026
Copy link
Contributor Author

@jesseturner21 jesseturner21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review feedback

Remove --target option from traces commands

The --target option should be removed from both traces list and traces get. There isn't a user story for multiple targets right now, so we shouldn't expose that concept here. This would simplify the commands and avoid confusion.

Specific changes needed:

  1. src/cli/commands/traces/command.tsx — Remove .option('--target <name>', 'Select deployment target') from both subcommands (lines 26 and 96)

  2. src/cli/commands/traces/types.ts — Remove target?: string from both TracesListOptions and TracesGetOptions

  3. src/cli/commands/traces/action.ts — Simplify resolveAgent to just use the single available target instead of accepting/validating a target selection. The function currently handles target lookup, missing target errors, and target name matching (lines 34-48) — all of that can be simplified to just grab targetNames[0].

@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 45.85% 3604 / 7859
🔵 Statements 45.44% 3799 / 8360
🔵 Functions 47.93% 707 / 1475
🔵 Branches 49.01% 2360 / 4815
Generated in workflow #860 for commit a50201d by the Vitest Coverage Report Action

@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
jesseturner21 and others added 5 commits March 4, 2026 16:18
Add traces support with three features:

1. `agentcore traces list` - Lists recent traces for a deployed agent
   by querying CloudWatch Logs Insights. Supports --agent, --target,
   and --limit options. Displays trace ID, timestamp, and session ID.

2. `agentcore traces get <traceId>` - Downloads a full trace to a JSON
   file from CloudWatch Logs. Supports --agent, --target, and --output
   options. Saves OpenTelemetry span data to agentcore/.cli/traces/.

3. Trace console link in invoke TUI header - Shows the CloudWatch
   console URL for viewing traces alongside the existing log link.

Both commands also print the CloudWatch console URL for quick access
to the trace dashboard.

New dependency: @aws-sdk/client-cloudwatch-logs
Multiple targets are not currently supported, so remove the --target
flag from both `traces list` and `traces get` to avoid exposing an
unsupported concept. The commands now always use the single deployed
target.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The polling loop only waited 30 seconds and silently fell through to a
misleading "No trace data found" error on timeout. Increase to 60s and
add an explicit timeout check matching the pattern in list-traces.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Match the get-trace timeout increase for consistency. Large log groups
may need more than 30 seconds for CWL Insights queries to complete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Truncating IDs made them unusable as input to `traces get`. Display the
full values so users can copy-paste trace IDs directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
…aces list

Extract duplicate agent resolution logic into a shared resolve-agent utility
(src/cli/operations/resolve-agent.ts) used by both logs and traces commands.
Move time-parser to shared utils (src/lib/utils/time-parser.ts). Add --since
and --until flags to `traces list` for custom time range queries instead of
the hardcoded 12h window.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
Copy link
Contributor

@tejaskash tejaskash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes

jesseturner21 and others added 4 commits March 4, 2026 17:33
Move the repeated 'DEFAULT' endpoint name string to DEFAULT_ENDPOINT_NAME
in cli/constants.ts and use it across logs/action.ts, get-trace.ts,
list-traces.ts, and trace-url.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Compute traceUrl at the top of the render block instead of using an
inline IIFE in the JSX. Simplifies the template to a straightforward
conditional render.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Return an error early if the user passes a non-numeric value for
--limit instead of silently passing NaN to the CloudWatch query.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reject non-hex trace IDs early to prevent query syntax injection
and give a clearer error for malformed input.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size/l PR size: L and removed size/l PR size: L labels Mar 4, 2026
Copy link
Contributor

@tejaskash tejaskash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@tejaskash tejaskash merged commit b10b2c7 into main Mar 4, 2026
17 checks passed
@tejaskash tejaskash deleted the feat/traces-command branch March 4, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants