Skip to content

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

Merged
platinummonkey merged 3 commits into
DataDog:mainfrom
jakedgy:feat/traces-search-aggregate
Feb 24, 2026
Merged

feat(traces): implement search and aggregate subcommands#65
platinummonkey merged 3 commits into
DataDog:mainfrom
jakedgy:feat/traces-search-aggregate

Conversation

@jakedgy

@jakedgy jakedgy commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

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

@platinummonkey

Copy link
Copy Markdown
Collaborator

main has drifted @jakedgy some of those imports have changed

@platinummonkey

Copy link
Copy Markdown
Collaborator

Note: just refactored this project onto Rust so let me know and will happily port this change over

@jakedgy

jakedgy commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

Note: just refactored this project onto Rust so let me know and will happily port this change over

All good -- startup life meant I didn't get to this as quickly as I wanted.

But I have been wanting to learn more Rust. I'll take care of it. Thanks for the heads up.

Replace placeholder traces command with full search and aggregate
implementations using the Datadog Spans API (v2).

- search: query individual spans with time range, sort, and limit
- aggregate: compute stats (count, avg, sum, min, max, median,
  cardinality, percentiles) with optional group-by facet
- parse_compute_raw/parse_compute: layered parsing for wasm32 compat
- validate_sort: reject invalid sort values
- agent-mode metadata for both subcommands
- 18 unit tests covering all aggregation functions and error paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jakedgy
jakedgy force-pushed the feat/traces-search-aggregate branch from bd35d34 to e39ac19 Compare February 24, 2026 03:22
@jakedgy

jakedgy commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

Update: Rust rewrite complete

Branch has been rebased onto main (Rust codebase) and the traces implementation rewritten from Go to Rust.

Usage verdict

After gathering usage data: good enough to ship. Not perfect, but functional and follows all existing codebase patterns.

Known limitation: agent context consumption

The biggest issue is that trace span data can fill up agent context quickly — individual spans contain a lot of nested attributes (tags, meta, metrics). This isn't traces-specific though; it's a general problem for any command that returns large payloads in agent mode.

Follow-up idea: We should think about an output format that is agent/context-friendly — e.g., a compact summary mode that returns key fields only, or a truncation strategy that caps nested attribute depth. This would benefit all commands, not just traces.

Changes in this push

  • Full Go → Rust rewrite of traces.rs (search + aggregate)
  • Updated main.rs with clap subcommand definitions and dispatch
  • 18 unit tests passing
  • All CI checks clean (clippy, fmt, build)
  • Code reviewed against .claude/code-health/ guidance

@jakedgy
jakedgy marked this pull request as ready for review February 24, 2026 03:23
The DD Spans API rejects requests without the type field set.
SpansListRequestData needs SEARCH_REQUEST and SpansAggregateData
needs AGGREGATE_REQUEST — the client library doesn't default these.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@platinummonkey

Copy link
Copy Markdown
Collaborator

nice fwiw, useragent::is_agent_mode() || cfg.agent_mode can detect based on common environment variables or the --agent flag being sent. This would allow for more compact outputs under that circumstance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@platinummonkey
platinummonkey merged commit 45ccc84 into DataDog:main Feb 24, 2026
6 checks passed
@jakedgy
jakedgy deleted the feat/traces-search-aggregate branch February 24, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants