-
Notifications
You must be signed in to change notification settings - Fork 36
feat: lambda support for DSM #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
michael-zhao459
wants to merge
21
commits into
main
Choose a base branch
from
michael.zhao/lambda-dsm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d0764da
set checkpoint for all supported dsm queue types
michael-zhao459 5d4da9f
removed not needed checkpoint set
michael-zhao459 4ea0470
clean
michael-zhao459 c2cefc2
clearer return type
michael-zhao459 2626672
add tests
michael-zhao459 ca9edb9
add the manual checkpoint parameter
michael-zhao459 d0e71e6
Correct approach to ensure public api is used
michael-zhao459 197abd0
remove unused variable
michael-zhao459 c9d6c23
match logging patterns of repo
michael-zhao459 75e976f
lint
michael-zhao459 a12d0ac
lint
michael-zhao459 99f1c67
add False manual_checkpoint false
michael-zhao459 7b4c4aa
fix formatting
michael-zhao459 5059c5c
optimization
michael-zhao459 7d3fdba
clean
michael-zhao459 c49e96f
add prettier ignore
michael-zhao459 e422375
add optional chaining
michael-zhao459 893d391
add log debug for no arn case
michael-zhao459 e44b6a7
Merge remote-tracking branch 'origin/main' into michael.zhao/lambda-dsm
michael-zhao459 bc8cb73
merge commit
michael-zhao459 70c5824
add checkpoints for headers
michael-zhao459 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,19 @@ export class KinesisEventTraceExtractor implements EventTraceExtractor { | |
constructor(private tracerWrapper: TracerWrapper) {} | ||
|
||
extract(event: KinesisStreamEvent): SpanContextWrapper | null { | ||
let sourceARN = ""; | ||
const kinesisData = event?.Records?.[0]?.kinesis.data; | ||
if (kinesisData === undefined) return null; | ||
|
||
sourceARN = event.Records[0].eventSourceARN; | ||
|
||
try { | ||
const decodedData = Buffer.from(kinesisData, "base64").toString("ascii"); | ||
const parsedBody = JSON.parse(decodedData); | ||
const headers = parsedBody?._datadog; | ||
if (headers) { | ||
const traceContext = this.tracerWrapper.extract(headers); | ||
this.tracerWrapper.setConsumeCheckpoint(headers, "kinesis", sourceARN); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we fail to capture the sourceARN, we probably want a debug log & not set a checkpoint |
||
if (traceContext === null) return null; | ||
|
||
logDebug(`Extracted trace context from Kinesis event`, { traceContext, headers }); | ||
|
@@ -28,6 +32,8 @@ export class KinesisEventTraceExtractor implements EventTraceExtractor { | |
} | ||
} | ||
|
||
// Still want to set a DSM checkpoint even if DSM context not propagated | ||
this.tracerWrapper.setConsumeCheckpoint(null, "kinesis", sourceARN); | ||
return null; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,12 @@ export class SNSSQSEventTraceExtractor implements EventTraceExtractor { | |
constructor(private tracerWrapper: TracerWrapper) {} | ||
|
||
extract(event: SQSEvent): SpanContextWrapper | null { | ||
let sourceARN = ""; | ||
|
||
try { | ||
// First try to extract trace context from message attributes | ||
if (event?.Records?.[0]?.body) { | ||
sourceARN = event.Records[0].eventSourceARN; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments as for Kinesis |
||
const parsedBody = JSON.parse(event?.Records?.[0]?.body) as SNSMessage; | ||
const messageAttribute = parsedBody?.MessageAttributes?._datadog; | ||
if (messageAttribute?.Value) { | ||
|
@@ -24,6 +27,7 @@ export class SNSSQSEventTraceExtractor implements EventTraceExtractor { | |
} | ||
|
||
const traceContext = this.tracerWrapper.extract(headers); | ||
this.tracerWrapper.setConsumeCheckpoint(headers, "sqs", sourceARN); | ||
if (traceContext) { | ||
logDebug("Extracted trace context from SNS-SQS event"); | ||
return traceContext; | ||
|
@@ -48,7 +52,8 @@ export class SNSSQSEventTraceExtractor implements EventTraceExtractor { | |
logDebug("Unable to extract trace context from SNS-SQS event", error); | ||
} | ||
} | ||
|
||
// Still want to set a DSM checkpoint even if DSM context not propagated | ||
this.tracerWrapper.setConsumeCheckpoint(null, "sqs", sourceARN); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if event is null or Records is null or it has no records? i would use optional chaining like above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using records[0] (so the first message). Can a lambda be called with many messages? What do we want to do in that case? Set many checkpoints or just one for the first checkpoint ? What do we do in the Python lambda?