Commit 65ae689
committed
fix(appsec): Go runtime
Two related bugs caused the `_dd.appsec.enabled` metric 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 enablement.
**Bug 1 — race condition (context deleted by placeholder span)**
Go's tracer emits a placeholder `aws.lambda` span with `resource =
"dd-tracer-serverless-span"` in its `/v0.4/traces` flush. AppSec's
`service_entry_span_mut` was matching this placeholder (same name,
`request_id` in meta). Depending on tokio scheduling, the placeholder
could arrive and be processed by AppSec _after_ `/runtime/invocation/
response` had already set `response_seen = true`. In that case,
`Processor::process_span` would tag the placeholder (harmless, it gets
dropped by `ChunkProcessor`) and then _delete the AppSec context_ (the
"finalized" branch). 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`. These
spans are always dropped before reaching the backend, so 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 (e.g. `aws.lambda.url`). However, AppSec has not
yet run on the invocation span at that point, so the metric is not in
`invocation_span.metrics`. `propagate_appsec` therefore falls back to
the `serverless_appsec_enabled` config flag for the _inferred_ span
(which always got the tag) but never sets it on the _invocation_ span
itself. If the AppSec context could not be found at flush time for any
reason, `aws.lambda` shipped without `_dd.appsec.enabled`.
Fix: in `enrich_ctx_at_platform_done`, pre-set `_dd.appsec.enabled =
1.0` on the invocation span when AAP is enabled, before calling
`complete_inferred_spans`. This resolves the pre-existing TODO comment
(`// todo(duncanista): Add missing metric tags for ASM`), ensures the
inferred span inherits the value from the actual metric rather than the
config fallback, and makes the tag present even when the AppSec context
is unavailable.
Both issues are specific to Go (and Java) because only those runtimes
use the placeholder span pattern. Python and Node emit the `aws.lambda`
span directly in their tracer payload, which is not filtered and is not
subject to the context-deletion race.
JJ-Change-Id: xltnyl_dd.appsec.enabled missing on aws.lambda
1 parent 9f49e35 commit 65ae689
3 files changed
Lines changed: 24 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 | + | |
| 166 | + | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
| |||
| 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 | | |
| |||
| 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