Commit 47d70b3
authored
## Problem
Two related bugs caused `_dd.appsec.enabled` and other AppSec tags to be
absent from the `aws.lambda` invocation span for Go (and Java) runtimes
when using extension-side App & API Protection.
The symptom was flaky integration tests: sometimes all AppSec tags were
missing, and even when that race was won, `_dd.appsec.enabled` was
consistently absent from `aws.lambda` while the inferred trigger span
(`aws.lambda.url`, `aws.httpapi`, etc.) always had it.
## Root causes
### Bug 1 — race condition: AppSec context deleted by placeholder span
Go's tracer emits a placeholder `aws.lambda` span with `resource =
"dd-tracer-serverless-span"` alongside its child spans in
`/v0.4/traces`. `AppSecProcessor::service_entry_span_mut` was matching
this placeholder (it has `name = "aws.lambda"` and `request_id` in
meta). Depending on tokio scheduling, the placeholder could reach
`Processor::process_span` _after_ `/runtime/invocation/response` had set
`response_seen = true`. In that case, `process_span` would tag the
placeholder — harmless, since `ChunkProcessor` drops it — but then
**delete the AppSec context**. When `process_on_platform_runtime_done`
later sent the extension-built `aws.lambda` span via `send_ctx_spans`,
the context was gone and no tags were applied.
**Fix:** filter placeholder spans out of `service_entry_span_mut` by
excluding spans whose `resource == INVOCATION_SPAN_RESOURCE`
(`"dd-tracer-serverless-span"`). These spans are always dropped before
reaching the backend; tagging them is both pointless and harmful.
### Bug 2 — `_dd.appsec.enabled` never pre-set on the invocation span
`enrich_ctx_at_platform_done` calls `inferrer.complete_inferred_spans`,
which propagates `_dd.appsec.enabled` from the invocation span to the
inferred trigger span via `propagate_appsec`. However, AppSec has not
yet run on the invocation span at that point, so `_dd.appsec.enabled` is
not in `invocation_span.metrics`. `propagate_appsec` falls back to the
`serverless_appsec_enabled` config flag for the _inferred_ span (so it
always got the tag) but **never sets it on the invocation span itself**.
If AppSec's context was unavailable at flush time for any reason,
`aws.lambda` shipped without the tag. This also explains an existing `//
todo(duncanista): Add missing metric tags for ASM` comment at that exact
location.
**Fix:** pre-set `_dd.appsec.enabled = 1.0` on the invocation span in
`enrich_ctx_at_platform_done` when AAP is enabled, before calling
`complete_inferred_spans`. This ensures the inferred span inherits from
the actual metric value rather than the config fallback, and guarantees
the tag is present even when the AppSec security context cannot be found
at flush time.
## Why Go/Java only
Only Go and Java use the placeholder span pattern. Python and Node emit
their `aws.lambda` span directly in their tracer payload with `resource
= function_name`, so `service_entry_span_mut` correctly identifies it,
and the context-deletion race cannot happen.
## Changes
| File | Change |
|---|---|
| `bottlecap/src/traces/mod.rs` | Make `INVOCATION_SPAN_RESOURCE`
`pub(crate)` |
| `bottlecap/src/appsec/processor/mod.rs` | Filter placeholder spans in
`service_entry_span_mut` |
| `bottlecap/src/lifecycle/invocation/processor.rs` | Pre-set
`_dd.appsec.enabled` on invocation span before `complete_inferred_spans`
|
## Testing
- Existing `appsec_processor_test` integration test passes.
- The race condition is no longer reproducible in Go + Lambda URL
integration tests.
- `_dd.appsec.enabled` is now consistently present on the `aws.lambda`
span.
1 parent 2c240b0 commit 47d70b3
3 files changed
Lines changed: 159 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
154 | 160 | | |
155 | 161 | | |
156 | 162 | | |
157 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
158 | 166 | | |
159 | 167 | | |
160 | 168 | | |
| |||
812 | 820 | | |
813 | 821 | | |
814 | 822 | | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
815 | 860 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
618 | | - | |
619 | 618 | | |
620 | 619 | | |
621 | 620 | | |
| |||
626 | 625 | | |
627 | 626 | | |
628 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
629 | 641 | | |
630 | 642 | | |
631 | 643 | | |
| |||
2334 | 2346 | | |
2335 | 2347 | | |
2336 | 2348 | | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
2337 | 2448 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments