Skip to content

chore(layer): minify the App and API Protection rules file - #904

Merged
purple4reina merged 1 commit into
mainfrom
dilly/layer-minify-appsec-rules
Dec 4, 2026
Merged

purple4reina merged 1 commit into
mainfrom
dilly/layer-minify-appsec-rules

Conversation

@astuyve

@astuyve astuyve commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Rewrites ddtrace/appsec/rules.json in the layer as minified JSON.

Motivation

The rules file ships pretty-printed: 454 kB, 278 kB minified. AppSecSpanProcessor reads the file as bytes and passes them to libddwaf, which parses the JSON, so whitespace makes no difference at runtime. A smaller file is also less to read on cold start. This is part of keeping the layer under the size check without raising the budget (see #901, #902, #903).

DD_APPSEC_RULES still points at a user's own file, which this doesn't touch.

Results (Python 3.15, amd64, dd-trace-py main pipeline 157654945)

unzipped zipped
main 25,466 kB 10,113 kB
this PR 25,291 kB (−175 kB) 10,110 kB

Testing Guidelines

  • Built the layer with UPSTREAM_PIPELINE_ID=157654945 PYTHON_VERSION=3.15 ARCH=amd64 ./scripts/build_layers.sh and ran check_layer_size.sh (numbers above).
  • Ran an AppSec check in public.ecr.aws/sam/build-python3.15:1 against this layer and against main. It sends an API Gateway event with a scanner User-Agent and a path-traversal query through datadog_lambda.handler, with DD_APPSEC_ENABLED=true. Both layers report WAF 2.2.1, rules 1.20.0, _dd.appsec.event_rules.loaded=224, error_count=0, and appsec.event=true on the aws.lambda span.
  • Ran the general smoke test with LLM Observability, AppSec, profiling and Exception Replay enabled. Same spans as main.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

🤖 Generated with Claude Code

ddtrace/appsec/rules.json ships pretty-printed (454 kB). ddtrace hands the
file's bytes to libddwaf, which parses the JSON, so minifying it changes
nothing at runtime and saves ~175 kB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@astuyve
astuyve requested review from a team as code owners December 4, 2026 02:56
@astuyve
astuyve requested a review from jcaparelli15 December 4, 2026 02:56

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

The focused command check supports JSON minification without changing parsed content, and the static reviewer reported no actionable defects. Full layer-build and AppSec integration validation were not rerun.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a6aa08c

@purple4reina
purple4reina merged commit 34871ad into main Dec 4, 2026
120 checks passed
@purple4reina
purple4reina deleted the dilly/layer-minify-appsec-rules branch December 4, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants