Skip to content

feat(traces): implement search and aggregate subcommands#65

Draft
jakedgy wants to merge 7 commits intodatadog-labs:mainfrom
jakedgy:feat/traces-search-aggregate
Draft

feat(traces): implement search and aggregate subcommands#65
jakedgy wants to merge 7 commits intodatadog-labs:mainfrom
jakedgy:feat/traces-search-aggregate

Conversation

@jakedgy
Copy link
Contributor

@jakedgy jakedgy commented Feb 15, 2026

Summary

Replace the placeholder traces command with working search and aggregate subcommands using the typed datadogV2.SpansApi.

This is a draft — I'm using these subcommands in real investigation workflows to shape the interface before requesting review.

Closes #49

Motivation: Agent-Driven Trace Investigation

The primary use case is AI agents performing structured investigations. The apm command provides the bird's-eye view (services, operations, dependencies), but when an agent needs to drill into why a service is slow or erroring, it needs span-level data:

apm services stats  →  "web-server has elevated p99"
apm dependencies    →  "web-server → postgres is slow"
traces search       →  "show me the actual slow spans"
traces aggregate    →  "p99 duration by resource_name"

search and aggregate are the two operations that matter for this workflow. Everything else (SpansMetrics CRUD, etc.) is out of scope — it doesn't serve the investigation use case.

What's Here

  • traces search — find individual spans with auto-pagination (SpansApi.ListSpans)
  • traces aggregate — compute stats over spans (SpansApi.AggregateSpans), reuses parseComputeString from logs
  • Follows existing patterns: --from/--to flexible time parsing, --query span syntax, formatter.FormatOutput
  • Structure + execution tests with mock client

What's Still Being Explored

I have actual work that will exercise these commands, so I'm letting real usage inform what needs to change before this is review-ready:

  • Output shaping — Do agents need different default fields or formatting for spans vs. logs?
  • Pagination defaults — Is --limit 50 the right default, or do investigation flows need more/fewer spans?
  • Aggregate UX — Does --compute / --group-by feel right in practice, or should it mirror the logs interface more closely?
  • Error messages — Are the troubleshooting hints actually useful when things go wrong?

Testing

  • Command structure tests (registration, flags, defaults)
  • Search + aggregate execution with mock client
  • All existing tests pass with go test -race ./...

🤖 Generated with Claude Code

jakedgy and others added 7 commits February 14, 2026 19:29
Resolves the design phase for issue datadog-labs#49. Documents the command interface
(search + aggregate), typed API client approach, testing strategy, and
follow-up work (time range unification, SpansMetrics CRUD).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Detailed task-by-task plan: skeleton, search, aggregate, tests,
docs update, and PR creation. References the design doc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tracesCmd with search and aggregate subcommands, flags, and
structure tests. RunE functions are stubs that will be implemented
in subsequent commits.

Closes datadog-labs#49

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Uses typed SpansApi.ListSpans with manual cursor-based pagination.
Supports --query, --from, --to, --limit, --sort flags with flexible
time parsing. Includes detailed error messages with troubleshooting
hints.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Uses typed SpansApi.AggregateSpans with --compute parsing reusing
the existing parseComputeString helper. Supports grouping by any
span facet via --group-by.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update traces status from placeholder to working. Add search and
aggregate subcommands to command index. Update domain categories
description.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Readme states traces are implemented but code says otherwise

1 participant

Comments