feat(traces): implement search and aggregate subcommands - #65
Conversation
|
main has drifted @jakedgy some of those imports have changed |
|
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>
bd35d34 to
e39ac19
Compare
Update: Rust rewrite completeBranch has been rebased onto Usage verdictAfter gathering usage data: good enough to ship. Not perfect, but functional and follows all existing codebase patterns. Known limitation: agent context consumptionThe 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
|
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>
|
nice fwiw, useragent::is_agent_mode() || cfg.agent_mode can detect based on common environment variables or the |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Replace the placeholder
tracescommand with workingsearchandaggregatesubcommands using the typeddatadogV2.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
apmcommand 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:searchandaggregateare 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), reusesparseComputeStringfrom logs--from/--toflexible time parsing,--queryspan syntax,formatter.FormatOutputWhat'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:
--limit 50the right default, or do investigation flows need more/fewer spans?--compute/--group-byfeel right in practice, or should it mirror the logs interface more closely?Testing
go test -race ./...🤖 Generated with Claude Code