Repository navigation
Conversation
There was a problem hiding this comment.
PerfectSlayer
left a comment
There was a problem hiding this comment.
❔ question: About design, why is StripInjectedContext in dd-trace-core when is seems only used in lambda instrumentation?
|
@PerfectSlayer Thank you for taking a look at it. Yes, it could be moved. The main reason it lives in |
|
Why can’t it be imported if declared as an helper? |
832808b to
df708d0
Compare
This comment has been minimized.
This comment has been minimized.
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
|
@PerfectSlayer Thanks! I moved it to helper! :) Could you please take a look at it again? |
mhlidd
left a comment
There was a problem hiding this comment.
Config portion looks good to me. Leaving the rest of the review for the Serverless team
df708d0 to
d0cb94b
Compare
There was a problem hiding this comment.
When context stripping is enabled, the scanner can rename customer property names, and a stream-read failure can leave the handler with truncated input. Both violate the intended preservation of customer payloads.
🤖 Bits Code Review · Commit d0cb94b
52b43bb to
a0450cf
Compare
|
The option But it's a bit inconsistent with the other AWS integration flags in this tracer, which all follow the
Each of those also ships a non-TRACE alias (e.g. Can we keep |
a0450cf to
3347b6b
Compare
|
Hello @ValentinZakharov, |
What Does This Do
Strips the
_datadogtrace propagation carrier that Datadog injects into AWS Lambda event payloads (EventBridge, SQS, SNS) before the payload reaches the customer's handler. Disabled by default and gated by a new config flagDD_LAMBDA_STRIP_INJECTED_CONTEXT.DD_LAMBDA_STRIP_INJECTED_CONTEXT(defaultfalse) toGeneralConfig/Config/supported-configurations.json.StripInjectedContextas a helper inaws-java-lambda-handler-1.2. It usesdatadog.json(already on the bootstrap classpath), so there are no Moshi orCoreTracer/AgentTracerAPI changes.LambdaHandlerInstrumentationcallsnotifyLambdaStartwith the original stream first, so the Datadog Extension still extracts trace context from the unmodified event. When the flag is enabled, the advice then replaces the handler'sInputStreamargument with the stripped payload.How stripping works
"_datadog"key with an object value is cut out together with one adjacent comma, so the result stays valid JSON._datadogthat looks like a JSON object (starts with{, ends with}) is decoded, stripped recursively up to 3 levels (SNSMessage, SQSbody, SNS-to-SQS fan-out) and re-encoded._datadogkey with any other value is treated as customer data and kept.Fail-open: the original payload is used whenever stripping could alter customer data
ByteArrayInputStreamis handled, read with mark/reset likeLambdaAppSecHandler/LambdaEventParser. Other stream types are passed through unread.RuntimeExceptionfalls back to the original bytes.Motivation
When Lambda tracing injects
_datadogpropagation context into an event payload, the extra key leaks into the customer's business payload and can break strict schema validation or unexpected-field checks on the consumer side. This strips the injected context before the handler sees it, matching the Go implementation in dd-trace-go#5054.Testing
StripInjectedContextTest: unit tests for comma placement, whitespace, nested and string-encoded carriers, non-object values, object keys, unsupported streams, invalid UTF-8, free text, and a parameterized suite with the 24 test cases from the Go PR (23 identical results, see the difference below).StripInjectedContextFuzzTest: Go-style fuzz test with a seed corpus, a regression corpus, and three randomized properties (never throws and always removes carriers; valid JSON stays valid and stripping is idempotent; arbitrary carriers are removed and sibling values are unchanged). The seed is logged and can be replayed withFUZZ_SEED, andFUZZ_ITERATIONSscales the run. Locally passed 30 runs x 100k iterations with different seeds.LambdaHandlerInstrumentationTest: end-to-end check that the handler receives the stripped EventBridge payload.ConfigTest: default value and enabling the flag.Benchmark Results (JMH, avgt, us/op)
The no-carrier path, which is the common case, returns after a single byte scan for
_datadog.Additional Notes
DD_LAMBDA_STRIP_INJECTED_CONTEXT=true._datadogfrom the event inside the handler (for exampleDDLambda(SQSEvent, Context)from datadog-lambda-java used without the Extension) will no longer see it when the flag is enabled."_datadog" : {...}) is also stripped./are escaped as\uXXXXand\/(semantically identical JSON).datais base64 encoded, so the carrier is not visible in the event JSON.jackson-databindfor strict JSON validity checks in the fuzz test.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [APMSVLS-313]