-
Notifications
You must be signed in to change notification settings - Fork 440
feat(dsm): context support for sns #13605
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,17 +141,28 @@ def get_datastreams_context(message): | |
- message.MessageAttributes._datadog.StringValue (SNS -> SQS) | ||
- message.MessageAttributes._datadog.BinaryValue.decode() (SNS -> SQS, raw) | ||
- message.messageAttributes._datadog.stringValue (SQS -> lambda) | ||
- message.Sns.MessageAttributes._datadog.Value.decode() (SNS -> lambda) | ||
- message.messageAttributes._datadog.binaryValue.decode() (SNS -> SQS -> lambda, raw) | ||
- message.body.MessageAttributes._datadog.Value.decode() (SNS -> SQS -> lambda) | ||
""" | ||
context_json = None | ||
message_body = message | ||
try: | ||
body = message.get("Body") | ||
if body: | ||
message_body = json.loads(body) | ||
except (ValueError, TypeError): | ||
log.debug("Unable to parse message body as JSON, treat as non-json") | ||
|
||
message_attributes = message_body.get("MessageAttributes") or message_body.get("messageAttributes") | ||
if "Sns" in message: | ||
message_body = message["Sns"] | ||
else: | ||
try: | ||
body = message.get("Body") or message.get("body") | ||
if body: | ||
message_body = json.loads(body) | ||
except (ValueError, TypeError): | ||
log.debug("Unable to parse message body as JSON, treat as non-json") | ||
|
||
message_attributes = ( | ||
message_body.get("MessageAttributes") | ||
or message_body.get("messageAttributes") | ||
or message.get("MessageAttributes") | ||
or message.get("messageAttributes") | ||
) | ||
if not message_attributes: | ||
log.debug("DataStreams skipped message: %r", message) | ||
return None | ||
|
@@ -170,11 +181,13 @@ def get_datastreams_context(message): | |
# The message originated from SQS | ||
context_json = json.loads(datadog_attr["StringValue"]) | ||
elif "stringValue" in datadog_attr: | ||
# The message originated from Lambda | ||
context_json = json.loads(datadog_attr["stringValue"]) | ||
elif "BinaryValue" in datadog_attr: | ||
# Raw message delivery | ||
context_json = json.loads(datadog_attr["BinaryValue"].decode()) | ||
elif "binaryValue" in datadog_attr: | ||
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. Is it actually valid to expect both this and line 185? Seems like they could be condensed into a single condition. 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. I can confirm that binaryValue is needed for sns -> sqs -> lambda but am worried about getting rid of the previous condition of BinaryValue, there are too many configurations that could result in the other state being accurate, if possible I would appreciate keeping both conditions |
||
# Raw message delivery to lambda | ||
context_json = json.loads(base64.b64decode(datadog_attr["binaryValue"]).decode()) | ||
else: | ||
log.debug("DataStreams did not handle message: %r", message) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
features: | ||
- | | ||
DSM: Add support for context extraction for SNS -> Lambda, SNS -> SQS -> Lambda. |
Uh oh!
There was an error while loading. Please reload this page.