Skip to content

Propagate Data Streams context from EventBridge events to SQS consumers - #13585

Open
robcarlan-datadog wants to merge 8 commits into
masterfrom
eventbridge-sqs-consume-checkpoints
Open

robcarlan-datadog wants to merge 8 commits into
masterfrom
eventbridge-sqs-consume-checkpoints

Conversation

@robcarlan-datadog

Copy link
Copy Markdown
Contributor

What Does This Do

When a received SQS message has no _datadog message attribute, the SQS v2 consumer instrumentation now parses the body as an EventBridge envelope. If the event carries detail._datadog, the trace and Data Streams pathway context are extracted from it and the consume checkpoint is set with EventBridge edge tags (direction:in, type:eventbridge, exchange:<bus>, topic:<detail-type>) instead of the plain SQS ones, so the consumer's checkpoint chains onto the publisher's pathway rather than starting a new one.

Motivation

Publishers to EventBridge inject the Data Streams pathway into detail._datadog of each event. Events routed to an SQS target arrive with that context in the message body only — EventBridge does not set SQS message attributes — so the SQS consumer instrumentation never saw it and the pathway ended at the bus.

Additional Notes

The parse only runs when the _datadog attribute is absent and cheap prefix/substring checks pass, and fails silently back to plain SQS tags, so the consume hot path only pays for messages that can actually carry the context. DatadogAttributeParser gains a map-based overload so the envelope's parsed attributes reuse the same key handling as the string form. The bus name in x-datadog-resource-name is normalized the same way the publisher normalizes its own tags, so producer and consumer edges agree on exchange.

Testing

LocalStack integration test in aws-java-eventbridge-2.0 publishing through a bus with an SQS target, asserting the consumer stats group parentHash equals the producer's hash with the EventBridge tags; unit tests for the envelope parser (valid envelope, ARN normalization, default bus fallback, attribute short-circuit, non-EventBridge bodies). Existing SQS and agent-bootstrap suites pass unchanged. Also verified end to end with a producer and consumer app against a real Datadog Agent: the consumer reports direction:in, type:eventbridge, parent_hash equal to the producer's hash, with sane latency.

🤖 Generated with Claude Code

@robcarlan-datadog robcarlan-datadog added type: feature Enhancements and improvements inst: aws eventbridge AWS EventBridge instrumentation inst: aws sdk AWS SDK instrumentation labels Nov 20, 2026 — with ddtool CLI
@datadog-official

datadog-official Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 64.71%
• Overall Coverage: 59.95% (-1.39%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 20, 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.91 s 14.77 s [+0.1%; +1.9%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.70 s 13.71 s [-0.7%; +0.6%] (no difference)
startup:petclinic:appsec:Agent 17.90 s 17.63 s [+0.7%; +2.4%] (maybe worse)
startup:petclinic:iast:Agent 17.64 s 17.75 s [-1.5%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 17.38 s 17.47 s [-1.5%; +0.5%] (no difference)
startup:petclinic:sca:Agent 17.20 s 17.80 s [-7.8%; +1.0%] (no difference)
startup:petclinic:tracing:Agent 16.84 s 16.94 s [-1.6%; +0.4%] (no difference)

Commit: 6d7d32aa · 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.

@robcarlan-datadog
robcarlan-datadog marked this pull request as ready for review November 20, 2026 20:29
@robcarlan-datadog
robcarlan-datadog requested review from a team as code owners November 20, 2026 20:29
@robcarlan-datadog
robcarlan-datadog requested review from PerfectSlayer and jandro996 and removed request for a team November 20, 2026 20:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-24T16:21:31.864515Z 75e30ae Manual request
ℹ️ 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 20, 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: eedcfadb3f

ℹ️ 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".

@datadog-official datadog-official 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: FAIL

Batched EventBridge messages can inherit the wrong producer pathway, and envelope extraction drops usable X-Ray system headers. Deeply nested message bodies can also let a stack overflow escape into the consumer application.

Open Bits AI session

🤖 Bits Code Review · Commit 96b3a3b

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 75e30aecf8

ℹ️ 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".

@datadog-official datadog-official 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 was unable to complete this review. View session

Please try again by commenting @datadog review.

@datadog-official datadog-official 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: FAIL

The PR propagates EventBridge trace and Data Streams context to SQS consumers.
EventBridge-only batches now extract each message's context independently.
X-Ray header preservation, unnecessary parsing, and queue-time ancestry are fixed.
Mixed EventBridge/SQS batches can still report the wrong producer pathway.
Malformed bodies can still bypass the nesting guard and let a stack overflow escape into the application.

Open Bits AI session

🤖 Bits Code Review · Commit 8c4e062

@datadog-official datadog-official 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 PR propagates EventBridge trace and Data Streams context through SQS message bodies.
With DSM enabled, mixed batches now extract independent contexts after an EventBridge-derived parent.
Parser stack overflows now fall back to ordinary SQS handling.
Earlier X-Ray propagation, unnecessary parsing, and queue-time ancestry issues remain fixed.
No review findings remain open.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f53dd78

robcarlan-datadog and others added 7 commits November 30, 2026 10:02
EventBridge publishers inject the Data Streams pathway into detail._datadog
of each event, but events delivered to an SQS target arrive with that context
in the message body only. The SQS consumer instrumentation reads the
_datadog message attribute, which EventBridge does not set, so the pathway
ended at the bus and the consumer's checkpoint started a fresh one.

Parse the EventBridge envelope from the body when the message has no
_datadog attribute, extract the trace and pathway context from
detail._datadog, and set the consume checkpoint with EventBridge edge tags
(direction:in, type:eventbridge, exchange:bus, topic:detail-type) so the
edge attaches to the bus. Messages carrying the _datadog attribute keep the
existing SQS path; the parse only runs when the attribute is absent and
cheap checks pass, and fails silently back to plain SQS tags.

Environment: Datadog workspace

Co-Authored-By: Claude Code <noreply@anthropic.com>
The module tests only load instrumentations reachable from their declared
dependencies, so receiving from SQS never went through the consumer
instrumentation and the data streams groups never appeared. Enable data
streams at the harness level and add the SQS instrumentation as a test
dependency so the checkpoint test observes the real consume path.

Environment: Datadog workspace

Co-Authored-By: Claude Code <noreply@anthropic.com>
Reformat the new SQS consumer classes to the repo style; no semantic
change.

Environment: Datadog workspace

Co-Authored-By: Claude Code <noreply@anthropic.com>
Bound the JSON nesting depth of EventBridge envelope bodies before
parsing, so a deeply nested SQS message body can no longer overflow
the stack while the tracer inspects it; such bodies now fall back to
plain SQS handling.

Parse the envelope only when its result can be used: when data streams
monitoring is enabled, or before the batch context has been extracted.

Extract EventBridge message context through the regular SQS message
visitor combined with the envelope attributes, so SQS system trace
headers (such as the X-Ray AWSTraceHeader) keep working, and extract
each message's own context within a receive batch instead of
inheriting the first message's.

Environment: Datadog workspace

Co-Authored-By: Claude Code <noreply@anthropic.com>
…messages

The _datadog parser gated pathway forwarding on the startup Config, so
enabling DSM through remote config produced EventBridge checkpoints
without the producer's pathway. It now reads traceConfig(), like
TracingIterator.

EventBridge messages after the first in a batch extract their own
context, which skipped the Sqs.DeliverMessage span. The time-in-queue
span is now started for every message that extracts its own context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The repo no longer accepts new Groovy test files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…flow

When an EventBridge event came first in a receive batch, later plain SQS
messages inherited its context and reported the EventBridge pathway as
their parent. With DSM on, they now extract their own context when the
batch context came from an EventBridge message. Batches with only plain
SQS messages behave as before.

The envelope depth scan can undercount on malformed bodies, so
tryParseFrom also catches StackOverflowError and falls back to plain SQS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robcarlan-datadog
robcarlan-datadog force-pushed the eventbridge-sqs-consume-checkpoints branch from f53dd78 to 3f71ff6 Compare November 30, 2026 15:04

@datadog-official datadog-official 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: FAIL

EventBridge context extraction materializes the entire application payload on the consumer thread, making tracer allocation scale with message contents rather than propagation metadata. Selective parsing would avoid the unnecessary allocations.

Open Bits AI session

🤖 Bits Code Review · Commit 3f71ff6

Add JsonReader.skipValue so EventBridgeMessage reads only detail-type and
detail._datadog, mirroring the v1 SQS body extractor, instead of building
maps, lists and strings for the entire application payload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@datadog-official datadog-official 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 PR propagates EventBridge trace and Data Streams context to SQS consumers, linking consumer checkpoints to their publishers. Selective parsing fixes the earlier full-payload allocation finding by skipping unrelated values; the incremental review identified no new reportable issues, leaving no open findings.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 6d7d32a

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

inst: aws eventbridge AWS EventBridge instrumentation inst: aws sdk AWS SDK instrumentation 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