feat: extract trace context from MSK events - #830
Open
lucassarcanjo wants to merge 3 commits into
Open
Conversation
purple4reina
reviewed
Sep 8, 2026
BridgeAR
reviewed
Sep 10, 2026
BridgeAR
left a comment
Member
There was a problem hiding this comment.
Thank you for the PR! I just left a few suggestions to make the code a bit faster :)
- Guard event.records with an early return instead of an empty fallback - Wrap the record loop in a single try/catch so errors log once - Return null from getParsedRecordHeaders when nothing decodes, lazily creating the headers map - Drop per-byte validation and rely on Buffer.from
lucassarcanjo
force-pushed
the
feat/msk-trace-extraction
branch
from
September 10, 2026 17:20
34ffa90 to
c552877
Compare
BridgeAR
reviewed
Sep 10, 2026
BridgeAR
left a comment
Member
There was a problem hiding this comment.
Thank you for the quick follow-ups!
Code wise it seems fine to me.
Author
|
Hi @lym953, could you take a look at this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds automatic trace context extraction for MSK-triggered Lambdas. Kafka header byte arrays are decoded as UTF-8 and passed to the existing tracer, preserving Datadog and W3C propagation context.
For batches, the Lambda span uses the first record with valid trace context across the topic-partition groups. Malformed headers are skipped, and headers from different records are never combined.
Motivation
Fixes #829. An instrumented producer's trace headers reach the Lambda event, but the existing dispatcher does not extract them, so the Lambda starts a separate trace.
Testing Guidelines
yarn test --runInBand: 691 tests and 3 snapshots passed on Node.js 22.yarn lintand formatting checks passed.dd-trace@5.118.0: the Lambda tracing lifecycle preserves the producer parent ID, sampling priority, and 128-bit trace ID with Datadog-only, W3C-only, and combined headers. The same reproduction fails with the original dispatcher.Types of Changes
Check all that apply