Skip to content

Implement client-side trace stats computation#293

Draft
bm1549 wants to merge 6 commits intomainfrom
brian.marks/client-side-stats
Draft

Implement client-side trace stats computation#293
bm1549 wants to merge 6 commits intomainfrom
brian.marks/client-side-stats

Conversation

@bm1549
Copy link
Contributor

@bm1549 bm1549 commented Mar 19, 2026

Summary

Implements Client-Side Trace Stats Computation (CSS) from scratch, matching the Go reference implementation.

  • DDSketch with 1% accuracy, 2048 max bins for latency distributions
  • StatsConcentrator with 12-dimension aggregation key
  • 10-second time bucketing by span end time
  • Msgpack serialization, POST to /v0.6/stats
  • gRPC status extraction (4-key priority order)
  • Peer tags for client/producer/consumer + internal spans with service override
  • Payload includes RuntimeID, Sequence, Service, TracerVersion
  • Default: disabled (DD_TRACE_STATS_COMPUTATION_ENABLED=false)

Test plan

  • 40 new unit tests (DDSketch + StatsConcentrator)
  • All 146 test cases passing
  • clang-format passes

Part of cross-tracer CSS v1.3.0 alignment effort.

🤖 Generated with Claude Code

bm1549 and others added 3 commits March 19, 2026 11:32
Add client-side trace stats computation that aggregates span metrics
(hits, errors, duration distributions) into 10-second time buckets
and flushes them to the Datadog Agent via POST /v0.6/stats.

This enables the Agent to drop priority-0 (unsampled) traces without
losing service-level metrics.

Key components:
- DDSketch: minimal C++ implementation with 1% relative accuracy, 2048
  max bins, and msgpack serialization
- StatsConcentrator: aggregates eligible spans by 12 dimensions
  (service, name, resource, type, HTTP/gRPC status codes, span_kind,
  synthetics, is_trace_root, peer_tags, HTTP method/endpoint)
- Stats flusher: fire-and-forget POST /v0.6/stats with msgpack payload
- Config: DD_TRACE_STATS_COMPUTATION_ENABLED env var (default: false)
- Headers: Datadog-Client-Computed-Stats, Datadog-Client-Computed-Top-Level

Span eligibility: top-level OR measured OR span.kind in
{server, client, producer, consumer}.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- GRPCStatusCode: serialize as string instead of uint32 to match
  protobuf definition (string GRPC_status_code = 18)
- PeerTags: serialize as msgpack array of "key:value" strings instead
  of a single comma-separated string (repeated string peer_tags = 16)
- Peer tag separator: use ":" instead of "=" to match Go/Java/Python/Ruby
- Peer tag keys: update to match Go agent standard (8 keys instead of 17)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The /v0.6/stats payload was missing TracerVersion, RuntimeID, Sequence,
and Service fields required by the spec. Add these four fields to the
top-level msgpack map (now 9 keys instead of 5), with Sequence as a
monotonically increasing counter that increments on each flush.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bm1549 bm1549 added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Mar 19, 2026
Fix clang-format violations in stats_concentrator.cpp, stats_concentrator.h,
and test_stats_concentrator.cpp caught by the verify CI job.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@pr-commenter
Copy link

pr-commenter bot commented Mar 19, 2026

Benchmarks

Benchmark execution time: 2026-03-19 17:11:53

Comparing candidate commit 0bc8472 in PR branch brian.marks/client-side-stats with baseline commit 14280af in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

…NABLED

Regenerate supported-configurations.json to include the new
DD_TRACE_STATS_COMPUTATION_ENABLED env var added in environment.h.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The new source files ddsketch.{cpp,h} and stats_concentrator.{cpp,h}
were missing from the Bazel cc_library srcs list, causing Bazel builds
to fail with 'stats_concentrator.h file not found'.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@datadog-official

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant