Skip to content

fix(appsec): report request headers on Lambda spans#9257

Merged
CarlesDD merged 2 commits into
masterfrom
ccapell/APPSEC-60752/lambda-appsec-headers
Jul 9, 2026
Merged

fix(appsec): report request headers on Lambda spans#9257
CarlesDD merged 2 commits into
masterfrom
ccapell/APPSEC-60752/lambda-appsec-headers

Conversation

@CarlesDD

@CarlesDD CarlesDD commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Creates a single synthetic request object ({ headers }) per Lambda invocation and uses it as the req key throughout the entire invocation lifecycle: waf.run, waf.disposeContext, and Reporter.finishRequest.
This gives getCollectedHeaders access to req.headers so that the standard ASM header tags are collected on Lambda spans when AppSec is enabled

Motivation

Lambda spans were missing all http.request.headers.* tags even when AppSec was active. The root cause was that Reporter.finishRequest was called with the span as req; since span.headers is undefined, getCollectedHeaders returned empty tags every time.

A first fix passed { headers } only to finishRequest, but that introduced a WeakMap key mismatch: waf.run was still keyed by span, so metricsStoreMap and extendedDataCollectionRequest were populated under one key and looked up under another. The result was that _dd.appsec.waf.duration, waf.timeouts, all RASP metrics, and extended data collection for attacks were silently dropped.

Additional Notes

  • activeInvocations changes from WeakSet<span> to WeakMap<span, req> where req = { headers: headers ?? {} }.
  • waf.disposeContext now receives req instead of span, the WAF context was already keyed by whichever object is passed to waf.run, so both must use the same object.
  • The new test 'should use the same synthetic req key across WAF run, dispose, and finishRequest' pins object identity for all four call-sites and asserts the key is never the span, catching exactly the key-mismatch regression this PR fixes.
  • Validated end-to-end: _dd.appsec.waf.duration, duration_ext, and http.request.headers.* tags all appear on real Lambda traces.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jul 8, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 96.50% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0900ced | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.65 MB
Deduped: 7.31 MB
No deduping: 7.31 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 437.94 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.54%. Comparing base (6ffe627) to head (0900ced).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #9257    +/-   ##
========================================
  Coverage   96.54%   96.54%            
========================================
  Files         915      915            
  Lines      121034   121034            
  Branches    20808    20586   -222     
========================================
+ Hits       116849   116851     +2     
+ Misses       4185     4183     -2     
Flag Coverage Δ
aiguard 53.56% <ø> (-0.05%) ⬇️
aiguard-integration 57.00% <ø> (ø)
apm-bucket-0 53.79% <ø> (-0.05%) ⬇️
apm-bucket-1 58.09% <ø> (-0.05%) ⬇️
apm-bucket-2 56.11% <ø> (-0.05%) ⬇️
apm-capabilities-tracing 60.29% <12.50%> (-0.01%) ⬇️
apm-integrations-aerospike 52.94% <ø> (-0.05%) ⬇️
apm-integrations-confluentinc-kafka-javascript 57.00% <ø> (-0.12%) ⬇️
apm-integrations-couchbase 53.26% <ø> (-0.05%) ⬇️
apm-integrations-http 57.97% <12.50%> (-0.05%) ⬇️
apm-integrations-kafkajs 57.72% <ø> (-0.05%) ⬇️
apm-integrations-next 54.24% <ø> (-0.05%) ⬇️
apm-integrations-prisma 54.18% <ø> (-0.05%) ⬇️
apm-integrations-tedious 53.04% <ø> (-0.05%) ⬇️
appsec 69.02% <100.00%> (-0.05%) ⬇️
appsec-express_fastify_graphql 65.70% <12.50%> (-0.03%) ⬇️
appsec-integration 45.50% <12.50%> (-0.01%) ⬇️
appsec-kafka_ldapjs_lodash 59.12% <ø> (-0.04%) ⬇️
appsec-mongodb-core_mongoose_mysql 62.28% <12.50%> (-0.04%) ⬇️
appsec-next 52.85% <12.50%> (-0.05%) ⬇️
appsec-node-serialize_passport_postgres 61.91% <12.50%> (-0.05%) ⬇️
appsec-sourcing_stripe_template 60.26% <12.50%> (-0.05%) ⬇️
debugger 65.69% <ø> (-0.02%) ⬇️
instrumentations-bucket-0 48.75% <ø> (-0.05%) ⬇️
instrumentations-bucket-1 54.97% <ø> (-0.05%) ⬇️
instrumentations-bucket-10 56.64% <12.50%> (-0.05%) ⬇️
instrumentations-bucket-11 48.74% <ø> (-0.05%) ⬇️
instrumentations-bucket-12 48.84% <ø> (-0.05%) ⬇️
instrumentations-bucket-13 48.67% <ø> (-0.05%) ⬇️
instrumentations-bucket-2 49.73% <ø> (-0.05%) ⬇️
instrumentations-bucket-3 53.83% <ø> (-0.05%) ⬇️
instrumentations-bucket-4 49.16% <ø> (-0.05%) ⬇️
instrumentations-bucket-5 53.01% <ø> (-0.05%) ⬇️
instrumentations-bucket-6 55.62% <ø> (-0.05%) ⬇️
instrumentations-bucket-7 53.60% <ø> (-0.05%) ⬇️
instrumentations-bucket-8 54.64% <ø> (-0.05%) ⬇️
instrumentations-bucket-9 56.10% <12.50%> (-0.05%) ⬇️
instrumentations-instrumentation-couchbase 48.17% <ø> (-0.05%) ⬇️
instrumentations-integration-esbuild 33.90% <ø> (ø)
llmobs-ai_anthropic_bedrock 57.75% <ø> (-0.04%) ⬇️
llmobs-bucket-1 56.81% <ø> (-0.04%) ⬇️
llmobs-openai 57.58% <ø> (-0.04%) ⬇️
llmobs-sdk 59.98% <ø> (-0.05%) ⬇️
llmobs-vertex-ai 54.22% <ø> (-0.05%) ⬇️
master-coverage 96.54% <100.00%> (?)
openfeature 54.61% <ø> (+0.09%) ⬆️
openfeature-unit 49.82% <ø> (-0.05%) ⬇️
platform-core_esbuild_instrumentations-misc 38.40% <ø> (-0.03%) ⬇️
platform-integration 62.18% <ø> (ø)
platform-shimmer_unit-guardrails_webpack 37.19% <ø> (-0.03%) ⬇️
plugins-bucket-0 53.18% <ø> (-0.05%) ⬇️
plugins-bucket-1 55.07% <ø> (ø)
plugins-bucket-11 56.73% <ø> (-0.06%) ⬇️
plugins-bucket-17 56.75% <ø> (-0.05%) ⬇️
plugins-bucket-18 57.60% <ø> (-0.05%) ⬇️
plugins-bucket-19 57.13% <ø> (-0.05%) ⬇️
plugins-bucket-20 59.36% <ø> (-0.07%) ⬇️
plugins-bucket-4 53.85% <ø> (-0.05%) ⬇️
plugins-bullmq_cassandra_cookie 57.40% <ø> (-0.05%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 52.32% <ø> (-0.05%) ⬇️
plugins-fetch_fs_generic-pool 54.46% <ø> (-0.05%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 59.88% <ø> (-0.05%) ⬇️
plugins-hapi_hono_ioredis 55.87% <ø> (-0.05%) ⬇️
plugins-jest_knex_langgraph 51.66% <ø> (-0.05%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 53.44% <ø> (-0.05%) ⬇️
plugins-lodash_mariadb_memcached 54.21% <ø> (-0.05%) ⬇️
plugins-mongodb_mongodb-core_mongoose 55.46% <ø> (-0.05%) ⬇️
plugins-multer_mysql_mysql2 54.37% <ø> (-0.05%) ⬇️
plugins-nats_node-serialize_opensearch 56.07% <ø> (-0.05%) ⬇️
plugins-passport-http_pino_postgres 54.75% <ø> (-0.05%) ⬇️
plugins-process_pug_redis 53.88% <ø> (-0.05%) ⬇️
plugins-undici_url_valkey 54.38% <ø> (-0.05%) ⬇️
plugins-vm_winston_ws 55.27% <ø> (-0.05%) ⬇️
profiling 58.21% <ø> (-0.05%) ⬇️
serverless-aws-sdk-aws-sdk 50.66% <ø> (-0.04%) ⬇️
serverless-aws-sdk-bedrockruntime 50.68% <ø> (-0.05%) ⬇️
serverless-aws-sdk-client 51.95% <ø> (-0.05%) ⬇️
serverless-aws-sdk-dynamodb 51.75% <ø> (-0.05%) ⬇️
serverless-aws-sdk-eventbridge 46.22% <ø> (-0.05%) ⬇️
serverless-aws-sdk-kinesis 54.70% <ø> (-0.05%) ⬇️
serverless-aws-sdk-lambda 52.78% <ø> (-0.05%) ⬇️
serverless-aws-sdk-s3 51.52% <ø> (-0.05%) ⬇️
serverless-aws-sdk-serverless-peer-service 54.73% <ø> (-0.05%) ⬇️
serverless-aws-sdk-sns 55.48% <ø> (-0.05%) ⬇️
serverless-aws-sdk-sqs 55.91% <ø> (-0.05%) ⬇️
serverless-aws-sdk-stepfunctions 51.25% <ø> (-0.05%) ⬇️
serverless-aws-sdk-util 48.45% <ø> (-0.05%) ⬇️
serverless-bucket-0 55.23% <ø> (ø)
serverless-bucket-1 56.01% <ø> (-0.05%) ⬇️
test-optimization-cucumber 72.93% <ø> (-0.04%) ⬇️
test-optimization-cypress 66.40% <ø> (+0.01%) ⬆️
test-optimization-jest 73.89% <ø> (-0.05%) ⬇️
test-optimization-mocha 74.30% <ø> (+0.05%) ⬆️
test-optimization-playwright-playwright-atr 61.60% <ø> (-0.01%) ⬇️
test-optimization-playwright-playwright-efd 61.79% <ø> (ø)
test-optimization-playwright-playwright-final-status 61.74% <ø> (+0.06%) ⬆️
test-optimization-playwright-playwright-impacted-tests 61.47% <ø> (+0.16%) ⬆️
test-optimization-playwright-playwright-reporting 61.37% <ø> (-0.01%) ⬇️
test-optimization-playwright-playwright-test-management 62.28% <ø> (-0.12%) ⬇️
test-optimization-playwright-playwright-test-span 61.51% <ø> (-0.06%) ⬇️
test-optimization-selenium 60.69% <ø> (-0.17%) ⬇️
test-optimization-testopt 59.16% <ø> (+0.08%) ⬆️
test-optimization-vitest 72.75% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented Jul 8, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-08 12:37:13

Comparing candidate commit 0900ced in PR branch ccapell/APPSEC-60752/lambda-appsec-headers with baseline commit 6ffe627 in branch master.

📊 Benchmarking dashboard

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-201.481ms; +206.200ms] or [-7.609%; +7.787%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-231869.023µs; +230086.623µs] or [-9.123%; +9.052%]

scenario:appsec-appsec-enabled-with-attacks-24

  • unstable execution_time [-158391.173µs; +158288.940µs] or [-5.135%; +5.132%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-191.741ms; +188.152ms] or [-6.585%; +6.462%]

scenario:appsec-control-20

  • unstable execution_time [-120.201ms; +130.524ms] or [-7.372%; +8.006%]

scenario:appsec-control-24

  • unstable execution_time [-116.858ms; +113.746ms] or [-9.425%; +9.174%]

scenario:appsec-control-26

  • unstable execution_time [-121.244ms; +128.433ms] or [-9.829%; +10.412%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-12.284ms; +18.655ms] or [-4.813%; +7.309%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-13358.211µs; +14436.634µs] or [-5.256%; +5.680%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-12483.952µs; +13321.019µs] or [-4.914%; +5.244%]

scenario:appsec-iast-with-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-33918.263µs; +34637.321µs] or [-6.116%; +6.245%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-26.119ms; +28.881ms] or [-4.792%; +5.298%]

scenario:child_process-file-args-24

  • unstable execution_time [-26.523ms; +21.746ms] or [-5.515%; +4.522%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-1566.185ms; +689.903ms] or [-18.359%; +8.087%]
  • unstable execution_time [-1580.363ms; +672.161ms] or [-17.083%; +7.266%]
  • unstable instructions [-13.5G instructions; +6.0G instructions] or [-19.353%; +8.531%]
  • unstable throughput [-213.242op/s; +421.068op/s] or [-6.011%; +11.869%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-2857.785ms; +2838.705ms] or [-28.566%; +28.375%]
  • unstable execution_time [-2865.172ms; +2827.495ms] or [-26.691%; +26.340%]
  • unstable instructions [-25735.5M instructions; +25743.9M instructions] or [-30.785%; +30.795%]
  • unstable max_rss_usage [-8229.104KB; +9725.904KB] or [-5.111%; +6.040%]
  • unstable throughput [-615.166op/s; +625.677op/s] or [-19.804%; +20.142%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-458.680ms; +601.993ms] or [-5.624%; +7.381%]
  • unstable execution_time [-439.190ms; +556.843ms] or [-4.962%; +6.291%]
  • unstable instructions [-4199.8M instructions; +5113.0M instructions] or [-6.307%; +7.678%]
  • unstable throughput [-223.765op/s; +180.196op/s] or [-6.163%; +4.963%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-3538.110ms; +3634.660ms] or [-31.615%; +32.477%]
  • unstable execution_time [-3710.488ms; +3736.027ms] or [-31.051%; +31.264%]
  • unstable instructions [-31214.7M instructions; +31777.9M instructions] or [-33.133%; +33.731%]
  • unstable max_rss_usage [-11126.478KB; +11492.878KB] or [-6.759%; +6.981%]
  • unstable throughput [-816.962op/s; +794.781op/s] or [-28.466%; +27.693%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-526.978ms; +126.962ms] or [-10.705%; +2.579%]
  • unstable execution_time [-529.995ms; +116.270ms] or [-10.589%; +2.323%]
  • unstable throughput [-39319.671op/s; +181954.358op/s] or [-2.346%; +10.858%]

scenario:id-parse-64bit-20

  • unstable execution_time [-133.013ms; +160.502ms] or [-5.201%; +6.276%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable cpu_user_time [-709876.362µs; +710223.762µs] or [-5.538%; +5.541%]
  • unstable execution_time [-705.920ms; +713.075ms] or [-5.386%; +5.441%]
  • unstable throughput [-3.298op/s; +3.242op/s] or [-5.370%; +5.279%]

scenario:plugin-mongodb-core-binary-hash-20

  • unstable execution_time [-136.268ms; +214.431ms] or [-4.449%; +7.001%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-3953.205KB; +4141.205KB] or [-4.973%; +5.210%]

@CarlesDD
CarlesDD marked this pull request as ready for review July 8, 2026 12:53
@CarlesDD
CarlesDD requested a review from a team as a code owner July 8, 2026 12:53
@CarlesDD
CarlesDD merged commit 30cd4fc into master Jul 9, 2026
654 checks passed
@CarlesDD
CarlesDD deleted the ccapell/APPSEC-60752/lambda-appsec-headers branch July 9, 2026 05:21
This was referenced Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants