Skip to content

[SLES-2961] fix(traces): extract Binary _datadog attribute from SQS records - #1314

Open
litianningdatadog wants to merge 3 commits into
mainfrom
tianning.li/SLES-2961
Open

[SLES-2961] fix(traces): extract Binary _datadog attribute from SQS records#1314
litianningdatadog wants to merge 3 commits into
mainfrom
tianning.li/SLES-2961

Conversation

@litianningdatadog

Copy link
Copy Markdown
Contributor

https://datadoghq.atlassian.net/browse/SLES-2961

Overview

SNS→SQS→Lambda trace propagation breaks when the _datadog context attribute reaches SQS as a Binary message attribute (e.g. via SNS raw message delivery). The consumer Lambda starts a new trace instead of continuing the publisher's.

SqsRecord::get_carrier() only checked string_value on the _datadog attribute. When the attribute was Binary-typed, that check silently failed and the code fell through to parsing the SQS body as an SNS envelope — which doesn't exist under raw delivery — so it returned an empty carrier. The SNS-native path (SnsRecord::get_carrier()) already branches on the attribute's type and base64-decodes Binary values; the SQS-native path never got the same treatment.

Fix: branch on data_type in SqsRecord::get_carrier(), base64-decoding the Binary case before parsing the carrier JSON, matching sns_event.rs.

Testing

  • Added sqs_event_binary.json fixture and test_get_carrier_binary, reproducing the bug (fails without the fix, passes with it).
  • cargo test --lib — 145 trigger tests pass.
  • cargo clippy --lib -- -D warnings — clean.

…ecords

SqsRecord::get_carrier() only checked string_value on the _datadog
message attribute, so a Binary-typed attribute (as delivered by SNS
raw message delivery) was silently ignored and the trace context was
never extracted. Branch on data_type instead, base64-decoding the
Binary case, matching the existing SnsRecord::get_carrier() behavior.
Copilot AI review requested due to automatic review settings July 29, 2026 18:29
@litianningdatadog
litianningdatadog requested a review from a team as a code owner July 29, 2026 18:29

Copilot AI 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.

Pull request overview

Fixes Datadog trace context propagation for SNS→SQS→Lambda when the _datadog message attribute is delivered as a Binary SQS message attribute (e.g., via SNS raw message delivery), by decoding and parsing the carrier rather than falling back to SNS-envelope parsing.

Changes:

  • Update SqsRecord::get_carrier() to branch on SQS message attribute dataType and base64-decode Binary _datadog values before parsing carrier JSON.
  • Add a new SQS Binary-attribute fixture plus a unit test to reproduce the issue and validate the fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs Adds Binary dataType handling for _datadog carrier extraction and a corresponding unit test.
bottlecap/tests/payloads/sqs_event_binary.json Adds a fixture representing an SQS record with _datadog as a Binary message attribute.

Comment thread bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs Outdated

@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: a134be5094

ℹ️ 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 bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs Outdated
@datadog-official

datadog-official Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 2 Pipeline jobs failed

DataDog/datadog-lambda-extension | e2e-test-status (amd64)   View in Datadog   GitLab

DataDog/datadog-lambda-extension | e2e-test-status (amd64, fips)   View in Datadog   GitLab

ℹ️ Info

🔄 Datadog auto-retried 3 jobs - 1 passed on retry View in Datadog

Useful? React with 👍 / 👎

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

@litianningdatadog
litianningdatadog marked this pull request as draft July 29, 2026 18:40
Match "String"/"Binary" on ma.data_type via starts_with instead of
exact equality, since SQS/SNS dataType values may carry a custom
label suffix (e.g. "String.foo"). Exact matching silently dropped
the carrier for any custom-labeled attribute, regressing behavior
that worked before this PR (previously stringValue was used whenever
present, regardless of dataType).
@litianningdatadog
litianningdatadog requested review from lym953 and removed request for duncanista July 29, 2026 18:48
@litianningdatadog
litianningdatadog marked this pull request as ready for review July 29, 2026 19:11
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