Skip to content

feat(appsec): report duration metrics for waf and rasp - #9286

Merged
CarlesDD merged 12 commits into
masterfrom
ccapell/APPSEC-69055/rasp-metrics-telemetry
Aug 20, 2026
Merged

CarlesDD merged 12 commits into
masterfrom
ccapell/APPSEC-69055/rasp-metrics-telemetry

Conversation

@CarlesDD

@CarlesDD CarlesDD commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Re-implements waf.duration, waf.duration_ext, rasp.duration and rasp.duration_ext as instrumentation telemetry distribution metrics, closing a coverage gap where these values were only visible as span tags (_dd.appsec.waf.duration, etc.) but never reported to telemetry.

The per-request totals were already being accumulated internally (addWafRequestMetrics/addRaspRequestMetrics); this PR adds the missing emission step, flushing each total once per request, via incrementWafDurationMetrics/incrementRaspDurationMetrics, orchestrated by a new incrementRequestDurationMetrics in telemetry/index.js and wired into reporter.js#finishRequest before the per-request store is cleared.

Motivation

These metrics were originally added in #5458 and reverted shortly after in #5534. The revert commit attributed the removal to the metrics themselves, but investigation (git history + cross-tracer comparison with dd-trace-py, which implements the equivalent correctly) showed the real defect was reporting frequency: the original implementation reported a partial cumulative sum on every individual WAF/RASP evaluation instead of once per request, producing cardinality/skew in the resulting distributions.

This PR fixes the reporting frequency rather than reintroducing the old per-eval pattern, restoring visibility into WAF/RASP evaluation duration in telemetry that has been missing since #5534.

Additional Notes

APPSEC-69055

@dd-octo-sts

dd-octo-sts Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.25 MB
Deduped: 8.92 MB
No deduping: 8.92 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 445.14 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

@CarlesDD CarlesDD self-assigned this Jul 10, 2026
@datadog-official

datadog-official Bot commented Jul 10, 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: 98.55% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e33508d | Docs | View more details | Give us feedback!

@codecov

codecov Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.54%. Comparing base (6d6dc98) to head (e33508d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9286   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         982      982           
  Lines      145106   145161   +55     
  Branches    12488    12461   -27     
=======================================
+ Hits       143000   143055   +55     
  Misses       2106     2106           
Flag Coverage Δ
aiguard 57.11% <16.36%> (-0.08%) ⬇️
aiguard-integration 55.20% <16.36%> (-0.05%) ⬇️
apm-bucket-0 57.28% <16.36%> (-0.08%) ⬇️
apm-bucket-1 62.44% <16.36%> (-0.08%) ⬇️
apm-bucket-2 61.26% <16.36%> (-0.08%) ⬇️
apm-bucket-3 58.92% <16.36%> (-0.08%) ⬇️
apm-capabilities-tracing 62.16% <16.36%> (-0.03%) ⬇️
apm-integrations-aerospike 55.00% <16.36%> (-0.08%) ⬇️
apm-integrations-confluentinc-kafka-javascript 60.22% <16.36%> (-0.11%) ⬇️
apm-integrations-couchbase 55.88% <16.36%> (-0.08%) ⬇️
apm-integrations-http 61.05% <34.54%> (-0.05%) ⬇️
apm-integrations-kafkajs 60.76% <16.36%> (-0.08%) ⬇️
apm-integrations-next 58.54% <16.36%> (-0.08%) ⬇️
apm-integrations-prisma 58.01% <16.36%> (-0.07%) ⬇️
appsec 71.23% <100.00%> (+0.01%) ⬆️
appsec-express_fastify_graphql 68.58% <34.54%> (-0.05%) ⬇️
appsec-integration 49.59% <100.00%> (+0.07%) ⬆️
appsec-kafka_ldapjs_lodash 62.53% <16.36%> (-0.08%) ⬇️
appsec-mongodb-core_mongoose_mysql 66.04% <34.54%> (-0.05%) ⬇️
appsec-next 55.99% <34.54%> (-0.05%) ⬇️
appsec-node-serialize_passport_postgres 65.45% <34.54%> (-0.05%) ⬇️
appsec-sourcing_stripe_template 63.89% <34.54%> (-0.05%) ⬇️
debugger 63.29% <16.36%> (-0.08%) ⬇️
instrumentations-bucket-0 50.96% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-1 58.78% <16.36%> (-0.08%) ⬇️
instrumentations-bucket-10 60.07% <34.54%> (-0.05%) ⬇️
instrumentations-bucket-11 60.73% <34.54%> (-0.05%) ⬇️
instrumentations-bucket-12 50.87% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-13 51.72% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-14 50.97% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-2 52.21% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-3 52.84% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-4 57.88% <16.36%> (-0.08%) ⬇️
instrumentations-bucket-5 48.60% <16.36%> (-0.06%) ⬇️
instrumentations-bucket-6 59.37% <16.36%> (-0.08%) ⬇️
instrumentations-bucket-7 51.16% <16.36%> (-0.07%) ⬇️
instrumentations-bucket-8 57.59% <16.36%> (-0.08%) ⬇️
instrumentations-bucket-9 56.44% <16.36%> (-0.08%) ⬇️
instrumentations-instrumentation-couchbase 49.74% <16.36%> (-0.07%) ⬇️
instrumentations-integration-esbuild 33.87% <ø> (ø)
llmobs-ai_anthropic_bedrock 62.02% <16.36%> (-0.07%) ⬇️
llmobs-bucket-1 60.56% <16.36%> (-0.07%) ⬇️
llmobs-openai 61.22% <16.36%> (-0.07%) ⬇️
llmobs-openai-agents_vertex-ai 59.28% <16.36%> (-0.07%) ⬇️
llmobs-sdk 67.48% <16.36%> (-0.09%) ⬇️
master-coverage 98.54% <100.00%> (?)
openfeature 55.22% <16.36%> (-0.05%) ⬇️
openfeature-unit 53.15% <16.36%> (-0.07%) ⬇️
platform-core_esbuild_instrumentations-misc 40.77% <16.36%> (-0.03%) ⬇️
platform-integration 59.60% <16.36%> (-0.05%) ⬇️
platform-shimmer_unit-guardrails_webpack 38.43% <16.36%> (-0.03%) ⬇️
plugins-browser-bunyan_bullmq_cassandra 60.65% <16.36%> (-0.08%) ⬇️
plugins-bucket-0 56.13% <16.36%> (-0.07%) ⬇️
plugins-bucket-1 53.25% <16.36%> (-0.05%) ⬇️
plugins-bucket-11 61.05% <16.36%> (-0.07%) ⬇️
plugins-bucket-18 60.61% <16.36%> (-0.07%) ⬇️
plugins-bucket-19 58.83% <16.36%> (-0.09%) ⬇️
plugins-bucket-20 60.75% <16.36%> (-0.08%) ⬇️
plugins-bucket-4 55.49% <16.36%> (-0.08%) ⬇️
plugins-cookie_cookie-parser_crypto 50.49% <16.36%> (-0.07%) ⬇️
plugins-fastify_fetch_fs 59.69% <16.36%> (-0.10%) ⬇️
plugins-generic-pool_google-cloud-pubsub_grpc 63.20% <16.36%> (-0.08%) ⬇️
plugins-handlebars_hapi_hono 57.71% <16.36%> (-0.08%) ⬇️
plugins-ioredis_knex_langgraph 56.18% <16.36%> (-0.08%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 57.40% <16.36%> (-0.09%) ⬇️
plugins-lodash_mariadb_memcached 57.11% <16.36%> (-0.08%) ⬇️
plugins-moleculer_mongodb_mongodb-core 60.53% <16.36%> (-0.08%) ⬇️
plugins-mongoose_multer_mysql 58.39% <16.36%> (-0.08%) ⬇️
plugins-mysql2_nats_node-serialize 59.99% <16.36%> (-0.08%) ⬇️
plugins-opensearch_passport-http_pino 58.26% <16.36%> (-0.08%) ⬇️
plugins-postgres_process_pug 57.41% <16.36%> (-0.08%) ⬇️
plugins-redis_router_sequelize 60.60% <16.36%> (-0.08%) ⬇️
plugins-test-and-upstream-rhea_undici_url 60.20% <16.36%> (-0.08%) ⬇️
plugins-valkey_vm_winston 56.85% <16.36%> (-0.08%) ⬇️
plugins-ws 58.38% <16.36%> (-0.08%) ⬇️
profiling 60.86% <16.36%> (-0.08%) ⬇️
serverless-aws-sdk-aws-sdk 54.14% <16.36%> (-0.06%) ⬇️
serverless-aws-sdk-base-inject-field 50.20% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-bedrockruntime 53.91% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-client 55.40% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-dynamodb 54.73% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-eventbridge 56.21% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 58.22% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-lambda 56.42% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-s3 54.82% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-serverless-peer-service 58.79% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-sns 59.00% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-sqs 59.42% <16.36%> (-0.11%) ⬇️
serverless-aws-sdk-stepfunctions 54.65% <16.36%> (-0.07%) ⬇️
serverless-aws-sdk-util 50.70% <16.36%> (-0.07%) ⬇️
serverless-bucket-0 52.87% <16.36%> (-0.05%) ⬇️
serverless-bucket-1 58.02% <16.36%> (-0.08%) ⬇️
test-optimization-cucumber 70.22% <16.36%> (-0.10%) ⬇️
test-optimization-cypress 64.48% <16.36%> (+<0.01%) ⬆️
test-optimization-jest 71.68% <16.36%> (-0.05%) ⬇️
test-optimization-mocha 71.73% <16.36%> (-0.02%) ⬇️
test-optimization-playwright-playwright-atr 59.30% <16.36%> (-0.06%) ⬇️
test-optimization-playwright-playwright-efd 59.44% <16.36%> (-0.06%) ⬇️
test-optimization-playwright-playwright-final-status 59.60% <16.36%> (-0.07%) ⬇️
test-optimization-playwright-playwright-impacted-tests 59.17% <16.36%> (+0.08%) ⬆️
test-optimization-playwright-playwright-reporting 60.62% <16.36%> (-0.11%) ⬇️
test-optimization-playwright-playwright-test-management 60.09% <16.36%> (-0.16%) ⬇️
test-optimization-playwright-playwright-test-span 59.34% <16.36%> (-0.12%) ⬇️
test-optimization-selenium 58.58% <16.36%> (-0.19%) ⬇️
test-optimization-testopt 57.24% <16.36%> (+0.03%) ⬆️
test-optimization-vitest 72.41% <16.36%> (-0.03%) ⬇️
test-optimization-vitest-browser 58.42% <16.36%> (-0.06%) ⬇️
test-optimization-webdriverio 64.61% <16.36%> (-0.01%) ⬇️

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.

@CarlesDD
CarlesDD marked this pull request as ready for review July 10, 2026 14:22
@CarlesDD
CarlesDD requested a review from a team as a code owner July 10, 2026 14:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9e4345209

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/dd-trace/src/appsec/reporter.js
@CarlesDD
CarlesDD marked this pull request as draft July 10, 2026 14:30
@pr-commenter

pr-commenter Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-20 07:22:52

Comparing candidate commit e33508d in PR branch ccapell/APPSEC-69055/rasp-metrics-telemetry with baseline commit 6d6dc98 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2282 metrics, 10 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-20

  • unstable max_rss_usage [-18.259MB; +5.760MB] or [-10.185%; +3.213%]

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

  • unstable max_rss_usage [-18.821MB; +9.259MB] or [-7.757%; +3.816%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-291.994ms; +435.525ms] or [-5.949%; +8.873%]
  • unstable execution_time [-293.959ms; +431.168ms] or [-5.903%; +8.658%]
  • unstable throughput [-151214.962op/s; +106310.795op/s] or [-8.961%; +6.300%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-7.463MB; +1.011MB] or [-10.702%; +1.451%]

scenario:plugin-aws-sdk-lambda-inject-with-context-24

  • unstable cpu_user_time [-214.297ms; +217.054ms] or [-5.547%; +5.618%]
  • unstable execution_time [-214.485ms; +219.725ms] or [-5.518%; +5.653%]
  • unstable throughput [-27199.809op/s; +27270.726op/s] or [-5.253%; +5.267%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-5546.738KB; +5628.405KB] or [-6.852%; +6.953%]

@CarlesDD
CarlesDD marked this pull request as ready for review July 13, 2026 09:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0330556e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/dd-trace/src/appsec/reporter.js

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor comment addressed

Comment thread packages/dd-trace/src/appsec/telemetry/rasp.js

@IlyasShabi IlyasShabi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that bring back duration metrics for RASP and WAF is not ready yet because they they should be sent as “sketch” and not as “distribution” metrics which is not the case yet on our tracer DataDog/libdatadog#268

@BridgeAR
BridgeAR marked this pull request as draft August 10, 2026 15:10
@BridgeAR

Copy link
Copy Markdown
Member

@IlyasShabi I believe that landed by now

@IlyasShabi

Copy link
Copy Markdown
Contributor

@BridgeAR Not yet, this PR #9434 is still Draft, the only thing I need is an e2e test to catch regressions.

@IlyasShabi

Copy link
Copy Markdown
Contributor

Ready to land 🚀

@BridgeAR
BridgeAR marked this pull request as ready for review August 19, 2026 13:35
BridgeAR
BridgeAR previously approved these changes Aug 19, 2026
IlyasShabi
IlyasShabi previously approved these changes Aug 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5992492cf0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/dd-trace/test/appsec/waf-metrics.integration.spec.js Outdated
@BridgeAR
BridgeAR marked this pull request as draft August 19, 2026 16:19
@CarlesDD
CarlesDD dismissed stale reviews from IlyasShabi and BridgeAR via 178ae1d August 19, 2026 16:43
@CarlesDD
CarlesDD marked this pull request as ready for review August 19, 2026 17:22
@CarlesDD
CarlesDD enabled auto-merge (squash) August 20, 2026 07:10
@CarlesDD
CarlesDD merged commit e5db61b into master Aug 20, 2026
678 of 679 checks passed
@CarlesDD
CarlesDD deleted the ccapell/APPSEC-69055/rasp-metrics-telemetry branch August 20, 2026 07:24
dd-octo-sts Bot pushed a commit that referenced this pull request Aug 21, 2026
Re-implements waf.duration, waf.duration_ext, rasp.duration and rasp.duration_ext
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Aug 21, 2026
dd-octo-sts Bot pushed a commit that referenced this pull request Aug 21, 2026
Re-implements waf.duration, waf.duration_ext, rasp.duration and rasp.duration_ext
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Aug 21, 2026
pabloerhard pushed a commit that referenced this pull request Aug 21, 2026
Re-implements waf.duration, waf.duration_ext, rasp.duration and rasp.duration_ext
pabloerhard pushed a commit that referenced this pull request Aug 21, 2026
Re-implements waf.duration, waf.duration_ext, rasp.duration and rasp.duration_ext
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.

3 participants