Skip to content

Commit 1e53fd7

Browse files
authored
SLS-2070: Adds step function forwarding to forwarder (DataDog#546)
Adds step functions logs forwarding
1 parent fde8a24 commit 1e53fd7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

aws/logs_monitoring/parsing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def find_cloudwatch_source(log_group):
276276
):
277277
return "apigateway"
278278

279+
if log_group.startswith("/aws/vendedlogs/states"):
280+
return "stepfunction"
281+
279282
# e.g. dms-tasks-test-instance
280283
if log_group.startswith("dms-tasks"):
281284
return "dms"
@@ -482,6 +485,19 @@ def awslogs_handler(event, context, metadata):
482485
if metadata[DD_SOURCE] == "cloudwatch" or metadata.get(DD_HOST, None) == None:
483486
metadata[DD_HOST] = aws_attributes["aws"]["awslogs"]["logGroup"]
484487

488+
if metadata[DD_SOURCE] == "stepfunction" and logs["logStream"].startswith(
489+
"states/"
490+
):
491+
try:
492+
message = json.loads(logs["logEvents"][0]["message"])
493+
if message.get("execution_arn") is not None:
494+
execution_arn = message["execution_arn"]
495+
arn_tokens = execution_arn.split(":")
496+
arn_tokens[5] = "stateMachine"
497+
metadata[DD_HOST] = ":".join(arn_tokens[:-1])
498+
except Exception as e:
499+
logger.debug("Unable to set stepfunction host: %s" % e)
500+
485501
# When parsing rds logs, use the cloudwatch log group name to derive the
486502
# rds instance name, and add the log name of the stream ingested
487503
if metadata[DD_SOURCE] in ["rds", "mariadb", "mysql", "postgresql"]:

aws/logs_monitoring/tests/test_parsing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ def test_carbon_black_event(self):
271271
"carbonblack",
272272
)
273273

274+
def test_step_function_event(self):
275+
self.assertEqual(
276+
parse_event_source(
277+
{"awslogs": "logs"}, "/aws/vendedlogs/states/MyStateMachine-Logs"
278+
),
279+
"stepfunction",
280+
)
281+
274282
def test_cloudwatch_source_if_none_found(self):
275283
self.assertEqual(parse_event_source({"awslogs": "logs"}, ""), "cloudwatch")
276284

0 commit comments

Comments
 (0)