Skip to content
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

an actual fix #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions aws/logs_monitoring/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,18 +658,8 @@ def normalize_events(events, metadata):
normalized = []
for event in events:
if isinstance(event, dict):
merged_event = merge_dicts(event, metadata)
if merged_event.get("dd.span_id"):
merged_event["dd.span_id"] = int(merged_event.get("dd.span_id"))
if merged_event.get("dd.trace_id"):
merged_event["dd.trace_id"] = int(merged_event.get("dd.trace_id"))
normalized.append(merged_event)
normalized.append(merge_dicts(event, metadata))
elif isinstance(event, str):
merged_event = merge_dicts({"message": event}, metadata)
if merged_event.get("dd.span_id"):
merged_event["dd.span_id"] = int(merged_event.get("dd.span_id"))
if merged_event.get("dd.trace_id"):
merged_event["dd.trace_id"] = int(merged_event.get("dd.trace_id"))
normalized.append(merge_dicts({"message": event}, metadata))
else:
# drop this log
Expand Down Expand Up @@ -742,14 +732,26 @@ def s3_handler(event, context, metadata):

# Send lines to Datadog
for line in split_data:
# Create structured object and send it
try:
line = process_line(line)
except Exception:
pass
structured_line = {
"aws": {"s3": {"bucket": bucket, "key": key}},
"message": line,
}
yield structured_line


def process_line(line):
line = json.loads(line)
log = json.loads(line["log"])
log['dd.span_id'] = int(log['dd.span_id'], 0)
log['dd.trace_id'] = int(log['dd.trace_id'], 0)
line["log"] = json.dumps(log)
return json.dumps(line)


# Handle CloudWatch logs from Kinesis
def kinesis_awslogs_handler(event, context, metadata):
def reformat_record(record):
Expand Down