Skip to content
Merged
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
30 changes: 21 additions & 9 deletions aws/logs_monitoring/forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,27 @@ def _forward_logs(self, logs, key=None):
log = add_retry_tag(log)

evaluated_log = log
to_forward = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, this could be just a control boolean as we're checking evaluated_log anw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It contains the JSON dump (to avoid dumping it twice for cloudtrail, which is already a time consuming source of events)


# apply scrubbing rules to inner log message
if isinstance(log, dict) and log.get("message"):
try:
log["message"] = scrubber.scrub(log["message"])
evaluated_log = log["message"]
except Exception as e:
logger.error(
f"Exception while scrubbing log message {log['message']}: {e}"
)
if isinstance(log, dict):
if log.get("message"):
try:
log["message"] = scrubber.scrub(log["message"])
evaluated_log = log["message"]
except Exception as e:
logger.error(
f"Exception while scrubbing log message {log['message']}: {e}"
)
else:
to_forward = dump_event(log)
evaluated_log = to_forward

if matcher.match(evaluated_log):
logs_to_forward.append(json.dumps(log, ensure_ascii=False))
if to_forward is None:
logs_to_forward.append(dump_event(log))
else:
logs_to_forward.append(to_forward)

batcher = DatadogBatcher(512 * 1000, 4 * 1000 * 1000, 400)
cli = DatadogHTTPClient(
Expand Down Expand Up @@ -186,3 +194,7 @@ def _forward_traces(self, traces, key=None):
if key:
self.storage.delete_data(key)
send_event_metric("traces_forwarded", len(traces))


def dump_event(event):
return json.dumps(event, ensure_ascii=False)
Loading