You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Background
traces/stats that go through Lambda extension can generate stats in
three ways:
1. tracer generates stats and sends them to extension at `/v0.6/stats`.
Only works if the env var `DD_TRACE_STATS_COMPUTATION_ENABLED` is
`true`.
2. extension generates stats from traces. It's off by default, and works
only if env var `DD_COMPUTE_TRACE_STATS_ON_EXTENSION` is true.
3. Datadog backend generates stats from traces. Works only if the trace
tag `_dd.compute_stats` is `1`.
A separate thing: the Go tracer sends a dummy `aws.lambda` span to the
extension, just to send metadata. The extension extracts metadata from
this span received, and sets it on the real `aws.lambda` span generated
on the extension side. The latter is what's finally sent to the trace
intake.
## Summary
If a trace has the header `Datadog-Client-Computed-Stats` with a truthy
value (which means 1 is on), then turn off 2 and 3 to avoid duplicate
counts, i.e.
1. make extension not generate stats
2. set trace tag `_dd.compute_stats` to 0
As a special case, if the dummy `aws.lambda` span sent by the Go tracer
has a `Datadog-Client-Computed-Stats` header with truthy value, then
extension propagates this value to the `aws.lambda` span generated by
the extension.
The `_dd.compute_stats` tag is determined by the combination of
`compute_trace_stats_on_extension` and `client_computed_stats`:
| Input: `compute_trace_stats_on_extension` | Input:
`client_computed_stats` | Expected: `_dd.compute_stats` | Expected:
Extension generates stats? |
|-------------------------------------------|--------------------------------|-------------------------------|--------------------------------------|
| `false` | `false` | `"1"` | No |
| `false` | `true` | `"0"` | No |
| `true` | `false` | `"0"` | Yes |
| `true` | `true` | `"0"` | No |
## Details
- `_dd.compute_stats` is now always set in `process_traces()`
(centralized from `tags_from_env()` in `tags.rs`), with the value
determined by both `compute_trace_stats_on_extension` and
`client_computed_stats` as shown in the table above
- When `client_computed_stats` is true or
`compute_trace_stats_on_extension` is true, the extension skips stats
generation in `send_processed_traces()` to avoid double-counting
- `COMPUTE_STATS_KEY` is `pub(crate)` in `tags.rs` so it can be
referenced from `trace_processor`
- Propagates `client_computed_stats` to the extension-generated
`aws.lambda` invocation span: when the Go tracer sends its placeholder
span (`dd-tracer-serverless-span`) with `Datadog-Client-Computed-Stats:
t`, that flag is stored in the invocation `Context` and passed through
to `send_spans`, so the extension also skips stats generation for the
`aws.lambda` span it creates
## Test plan
### Automated tests
Passed the new unit tests
### Manual tests
#### Steps
1. Deploy a Lambda function that uses `github.com/DataDog/dd-trace-go/v2
v2.6.0`
2. Set env var:
1. `DD_TRACE_STATS_COMPUTATION_ENABLED`: `true`, which turns on 1
2. `DD_COMPUTE_TRACE_STATS_ON_EXTENSION`: `true`, which tries to turn on
2
#### Result
Before: 2 hits (duplicate):
1. one with `resource_name=dd-tracer-serverless-span`, generated by Go
tracer
1. one with `resource_name=yiming2-xxx`
<img width="699" height="286" alt="image"
src="https://github.com/user-attachments/assets/6545cf12-c90b-4ed1-832e-1dab7b6c4d7c"
/>
After: 1 hit. Only the one with
`resource_name=dd-tracer-serverless-span`
<img width="696" height="283" alt="image"
src="https://github.com/user-attachments/assets/d2e49c3a-473c-4043-a952-9a555eada0e7"
/>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments