Commit ab461a4
authored
[APMSVLS-487] respect
## Overview
Makes the extension respect the tracer's `Datadog-Client-Computed-Stats`
header and moves `_dd.compute_stats` from a baked-in function tag to a
per-span backend directive.
We tried supporting the `Datadog-Client-Computed-Stats` header before in
#1118, but that was reverted in #1176.
### Background
Span attribute `_dd.compute_stats` asks the backend to compute trace
stats. It must be set to `"1"` only when nobody else computed them —
neither the extension (agent) nor the tracer. Previously the extension:
1. **Baked `_dd.compute_stats` into the function tags** unconditionally
(`tags_from_env`), which also leaked the key into `_dd.tags.function`.
2. **Ignored `Datadog-Client-Computed-Stats`** entirely, so when a
tracer computed stats client-side, the backend was still asked to
compute them.
### Canonical semantics (validated against the Go agent)
The Go agent (`pkg/serverless/tags/tags.go`) only ever sets
`_dd.compute_stats = "1"`, never `"0"`, and leaves the key absent
otherwise. This PR matches that:
> Set `_dd.compute_stats="1"` iff `!compute_trace_stats_on_extension &&
!client_computed_stats`; otherwise leave it absent.
| `client_computed_stats` (header from tracer) | `compute_on_extension`
(extension config) | who computes | stamp `_dd.compute_stats="1"`?
| -------------------- | --------------------- | --------------- | ---
| true | (ignored) | tracer | ❌ no
| false | true | extension | ❌ no
| false | false | backend | ✅ yes
### Changes
- **`tags/lambda/tags.rs`** — stop baking `_dd.compute_stats` in
`tags_from_env` (no longer leaks into `_dd.tags.function`);
`COMPUTE_STATS_KEY` is now `pub` so the integration test can reuse it
instead of re-declaring the literal.
- **Path A: `traces/trace_processor.rs`** — `ChunkProcessor` gains
`client_computed_stats` and stamps `_dd.compute_stats="1"` per-span only
when neither side computes stats; the extension-side stats-generation
guard in `send_processed_traces` now also skips when
`client_computed_stats` is set.
- **Path B (extension-generated `aws.lambda` span)** —
`client_computed_stats` is propagated from the tracer's placeholder span
through `context.rs` → `processor.rs` → `processor_service.rs` →
`trace_agent.rs`, so Path B reuses the same `ChunkProcessor` stamping
(single source of truth).
- **OTLP: `otlp/agent.rs`** — the OTLP stats-generation guard previously
checked only `compute_trace_stats_on_extension`, so an OTLP request
carrying `Datadog-Client-Computed-Stats` would still generate
extension-side stats and double-count against the tracer. It now also
skips when `client_computed_stats` is set, mirroring the
`send_processed_traces` guard.
- **Single source of truth: `traces/trace_processor.rs`** — the three
decisions over the same two inputs (the per-span `_dd.compute_stats`
stamp, plus the extension-side stats-generation guards in
`send_processed_traces` and `otlp/agent.rs`) are now derived from one
`StatsComputedBy::resolve(compute_on_extension, client_computed_stats)`
helper, so the stamp and the guards can't silently drift apart.
### Note on the header value (cross-runtime)
`Datadog-Client-Computed-Stats` is not standardized (`"true"`
.NET/Java/PHP/Python, `"yes"` JS/Ruby/C++, `"t"` Go). bottlecap consumes
the already-parsed `client_computed_stats` bool from
`libdd_trace_utils`, where any non-empty value → `true`, so the fix
triggers on every runtime. A separate libdatadog PR
([DataDog/libdatadog#2071](DataDog/libdatadog#2071))
aligns the header parsing with the Go agent's `isHeaderTrue`/`ParseBool`
rules; this PR only consumes the bool and does not depend on that
change.
## Testing
- ~**Tier 0** (header-parsing contract)~ — moved to the libdatadog bump
PR #1244, since those tests assert libdatadog parsing behavior that the
`db05e1f → 48da0d8` bump changes. This branch keeps Tiers 1–3 and
rebases onto [#1244](//pull/1244) after
it merges.
- **Tier 1** (`trace_processor.rs`) — truth-table on `Span.meta`,
stats-skip guard via the real `StatsConcentratorService`, and updated
`tags.rs` unit tests asserting the key no longer appears in the tags
map. Fixed the logs/metrics integration tests that asserted the old
leak.
- **Tier 2** (`context.rs`, `processor.rs`) — context-level flag
recording and an end-to-end Path B test driving `send_ctx_spans` through
the `trace_tx` channel, asserting `_dd.compute_stats` on the
`aws.lambda` span across the truth table.
- **Tier 3** (`apm_integration_test.rs`) — full fake-intake E2E routing
a trace through `SendingTraceProcessor::send_processed_traces`: asserts
on the captured `AgentPayload` span meta and on `stats_payloads()`
(stats suppressed unless the extension computes and the tracer did not).
### Datadog-Client-Computed-Stats header (#1245)1 parent d2d30fc commit ab461a4
10 files changed
Lines changed: 696 additions & 30 deletions
File tree
- bottlecap
- src
- lifecycle/invocation
- otlp
- tags/lambda
- traces
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
| |||
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
| 110 | + | |
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| |||
515 | 522 | | |
516 | 523 | | |
517 | 524 | | |
518 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
519 | 533 | | |
520 | 534 | | |
521 | 535 | | |
522 | 536 | | |
523 | 537 | | |
| 538 | + | |
524 | 539 | | |
525 | 540 | | |
526 | 541 | | |
| |||
646 | 661 | | |
647 | 662 | | |
648 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
649 | 692 | | |
650 | 693 | | |
651 | 694 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
| 668 | + | |
| 669 | + | |
668 | 670 | | |
669 | | - | |
670 | | - | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
671 | 679 | | |
672 | 680 | | |
673 | 681 | | |
| |||
732 | 740 | | |
733 | 741 | | |
734 | 742 | | |
735 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
736 | 746 | | |
737 | 747 | | |
738 | 748 | | |
| |||
746 | 756 | | |
747 | 757 | | |
748 | 758 | | |
| 759 | + | |
749 | 760 | | |
750 | 761 | | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
751 | 765 | | |
752 | 766 | | |
753 | 767 | | |
| |||
756 | 770 | | |
757 | 771 | | |
758 | 772 | | |
759 | | - | |
| 773 | + | |
760 | 774 | | |
761 | 775 | | |
762 | 776 | | |
| |||
1448 | 1462 | | |
1449 | 1463 | | |
1450 | 1464 | | |
1451 | | - | |
| 1465 | + | |
1452 | 1466 | | |
1453 | | - | |
| 1467 | + | |
| 1468 | + | |
1454 | 1469 | | |
1455 | 1470 | | |
1456 | 1471 | | |
| |||
2622 | 2637 | | |
2623 | 2638 | | |
2624 | 2639 | | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
2625 | 2773 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
379 | 380 | | |
380 | 381 | | |
381 | 382 | | |
| 383 | + | |
382 | 384 | | |
383 | 385 | | |
384 | 386 | | |
385 | 387 | | |
| 388 | + | |
386 | 389 | | |
387 | 390 | | |
388 | 391 | | |
| |||
617 | 620 | | |
618 | 621 | | |
619 | 622 | | |
620 | | - | |
621 | | - | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
622 | 628 | | |
623 | 629 | | |
624 | 630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| |||
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
81 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
| |||
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
114 | 124 | | |
115 | 125 | | |
116 | 126 | | |
| |||
0 commit comments