Skip to content

Add pre-validating to DSM and AppSec decoding of propagation data (quick perf fix) - #13643

Open
dougqh wants to merge 3 commits into
masterfrom
dougqh/strict-base64-decoding
Open

dougqh wants to merge 3 commits into
masterfrom
dougqh/strict-base64-decoding

Conversation

@dougqh

@dougqh dougqh commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Base64 values the tracer reads from propagation headers, message attributes and event payloads are validated before decoding, and invalid values are skipped without throwing an exception. Data Streams pathway contexts longer than any valid encoding, or too short to hold one, are ignored. Valid values decode exactly as before.

Motivation

The tracer decodes Base64 in several propagation and messaging paths, each calling the JDK decoder directly and catching IllegalArgumentException for malformed input. A shared helper gives these paths consistent validation, lets them handle bad input without exceptions, and gives future decode sites one API to use.

Performance

Base64DecodingBenchmark (added in this PR) compares Base64Decoding.decode() with the pattern it replaces at call sites: Base64.getDecoder().decode() with a catch that returns null. depth adds stack frames above the decode, since the cost of an exception grows with the stack it captures. The depth-64 rows include about 35–40 ns of recursion overhead on both sides.

Apple M1 Max (arm64), JDK 21.0.4 (Zulu), JMH 1.37, 2 forks, 3×1s warmup, 5×1s measurement:
./gradlew :internal-api:jmh -PtestJvm=21 -Pjmh.includes=Base64DecodingBenchmark -Pjmh.profilers=gc

Input Depth Before (ns/op) After (ns/op) Change Before (B/op) After (B/op)
badLength 0 909 ± 21 2.9 ± 0.1 −99.7% 768 0
badLength 64 2,437 ± 34 43 ± 1 −98% 2,144 0
badChar 0 910 ± 5 924 ± 10 +1.6% 1,008 1,008
badChar 64 2,496 ± 57 2,695 ± 114 +8% 2,384 2,384
valid 0 22.4 ± 0.5 23.7 ± 0.8 +6% 40 40
valid 64 58.2 ± 1.2 61.9 ± 2.1 +6% 40 40
validLarge 0 421 ± 11 432 ± 28 within error 3,088 3,088
validLarge 64 451 ± 8 453 ± 11 within error 3,088 3,088
  • Values with an invalid length or padding no longer throw: about 300× faster at depth 0 and 57× at depth 64, with no allocation instead of 0.8–2.1 KB per exception.
  • Values with an invalid character still reach the JDK decoder and throw inside the helper, so their cost is unchanged.
  • Valid header-sized values cost about 1–4 ns (6%) more for the up-front length and padding check, with identical allocation. For 4 KB values the difference is within error.

Longer runs on x86 are in progress and will be added here.

Additional Notes

  • Base64Decoding (internal-api) has decode overloads for byte[], String and ByteBuffer, each returning null for invalid input. Input whose length or trailing padding can't be valid Base64 is rejected without calling the JDK decoder; anything else is decoded with Base64.getDecoder().
  • Call sites: Data Streams pathway context, SQS v1 binary attribute, DatadogAttributeParser, both Kafka TextMapExtractAdapters, Functions.BASE64_DECODE, Lambda event and response bodies, and Spark. Each now checks for null instead of catching.
  • Data Streams: a valid pathway context is at most 36 characters with this encoder, or 40 with 10-byte varints, so values over 64 bytes are ignored.
  • Kafka adapters: the Base64.Decoder field became a boolean flag, with no behavior change.
  • Remote config and CI Visibility still use the JDK decoder directly, since they treat a bad payload as a hard failure.

🤖 Generated with Claude Code

Base64Decoding (internal-api) returns null for invalid input instead of
throwing. Input whose length or trailing padding can't be valid Base64 is
rejected before calling the JDK decoder; anything else is decoded with
Base64.getDecoder().

Propagation and message call sites (Data Streams pathway context, SQS and
Spring Messaging _datadog attributes, Kafka header decoding, Lambda event
bodies, Spark) now check for null and skip invalid values instead of
catching an exception. Data Streams also ignores pathway contexts longer
than any valid encoding or too short to hold one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: feature Enhancements and improvements comp: core Tracer core labels Nov 23, 2026
Compares Base64Decoding against the pattern it replaces at call sites,
Base64.getDecoder() with a catch that returns null, for valid and invalid
input at two stack depths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 84.44%
• Overall Coverage: 59.37% (-1.59%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6e1dac7 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.02 s 13.96 s [-0.2%; +1.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.88 s 13.01 s [-1.5%; -0.4%] (maybe better)
startup:petclinic:appsec:Agent 17.30 s 17.07 s [+0.6%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 17.08 s 16.97 s [-0.3%; +1.5%] (no difference)
startup:petclinic:profiling:Agent 16.24 s 16.76 s [-7.4%; +1.2%] (no difference)
startup:petclinic:sca:Agent 17.24 s 17.04 s [+0.2%; +2.1%] (maybe worse)
startup:petclinic:tracing:Agent 16.22 s 16.27 s [-1.2%; +0.6%] (no difference)

Commit: 6e1dac72 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh marked this pull request as ready for review November 23, 2026 14:45
@dougqh
dougqh requested review from a team as code owners November 23, 2026 14:45
@dougqh
dougqh requested review from PerfectSlayer, amarziali, bric3 and ygree and removed request for a team, PerfectSlayer and bric3 November 23, 2026 14:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T14:47:46.369482Z 6e1dac7 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dd-octo-sts dd-octo-sts Bot added the tag: ai generated Largely based on code generated by an AI or LLM label Nov 23, 2026
@dougqh dougqh changed the title Add strict Base64 decoding for propagation and message data Add pre-validating to DSM and AppSec decoding of propagation data Nov 23, 2026
@dougqh dougqh changed the title Add pre-validating to DSM and AppSec decoding of propagation data Add pre-validating to DSM and AppSec decoding of propagation data (quick perf fix) Nov 23, 2026

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

Static inspection supports compatibility for valid padded and unpadded Base64, with malformed values handled through the migrated callers’ null checks. The specialist reported no actionable regressions.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 6e1dac7

@pr-commenter

pr-commenter Bot commented Nov 23, 2026

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master dougqh/strict-base64-decoding
git_commit_date 1795385633 1795445082
git_commit_sha ef5f1d2 6e1dac7
See matching parameters
Baseline Candidate
ci_job_date 1795446061 1795446061
ci_job_id 2289557327 2289557327
ci_pipeline_id 155739687 155739687
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-3c4d2wng 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-3c4d2wng 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

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

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce same

@pr-commenter

pr-commenter Bot commented Nov 23, 2026

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master dougqh/strict-base64-decoding
git_commit_date 1795385633 1795445082
git_commit_sha ef5f1d2 6e1dac7
See matching parameters
Baseline Candidate
ci_job_date 1795446199 1795446199
ci_job_id 2289557329 2289557329
ci_pipeline_id 155739687 155739687
cpu_model Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-ey1etm6w 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-ey1etm6w 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

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

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume same

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant