Skip to content

Commit 1691ff4

Browse files
authored
[AWSX] fix(logs forwarder): Override service tag from StepFunction tags (#1049)
* [AWSX] fix(logs forwarder): Override StepFunction service tag from StepFunction tags * black
1 parent 1a15b72 commit 1691ff4

11 files changed

Lines changed: 15 additions & 19 deletions

File tree

aws/logs_monitoring/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,10 @@ The value of the `service` tag is determined based on multiple inputs. These inp
828828
829829
1. Log message custom tags: If the log message has a `ddtags` key which contains a `service` tag value, it will be used to override the `service` tag in the log event.
830830
2. Lambda tags cache (applicable for Lambda logs only): Activating `DdFetchLambdaTags` will fetch and store all Lambda functions tags and will override the `service` tag if it wasn't set previously or was set to a default value i.e. `source` value.
831-
3. Cloudwatch log group tags cache (applicable for Cloudwatch logs only): Activating `DdFetchLogGroupTags` will fetch and store all Cloudwatch log groups tags which are added to the `ddtags` entry in the log event. If `service` tag value was set in the tags cache it will be used to set the `service` tag for the log event.
832-
4. Directly setting a `service` tag value in the forwarder's `ddtags` ENV var.
833-
5. Default value equal to the `source` tag.
831+
3. Directly setting a `service` tag value in the forwarder's `ddtags` ENV var.
832+
4. Step Function tags cache (applicable for step Functions logs only): Activating `DdFetchStepFunctionsTags` will fetch and store all Step Functions tags and override `service` tag if wasn't set previously.
833+
5. Cloudwatch log group tags cache (applicable for Cloudwatch logs only): Activating `DdFetchLogGroupTags` will fetch and store all Cloudwatch log groups tags which are added to the `ddtags` entry in the log event. If `service` tag value was set in the tags cache it will be used to set the `service` tag for the log event.
834+
6. Default value equal to the `source` tag.
834835

835836
## Further Reading
836837

aws/logs_monitoring/settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,10 @@ def is_api_key_valid():
242242

243243
# Check if the API key is the correct number of characters
244244
if len(DD_API_KEY) != 32:
245-
raise Exception(
246-
f"""
245+
raise Exception(f"""
247246
Invalid Datadog API key format. Expected 32 characters, received {len(DD_API_KEY)}.
248247
Verify your API key at https://app.{DD_SITE}/organization-settings/api-keys
249-
"""
250-
)
248+
""")
251249

252250
# Validate the API key
253251
logger.debug("Validating the Datadog API key")

aws/logs_monitoring/steps/handlers/awslogs_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def handle(self, event):
5151

5252
# Add custom tags from cache
5353
self.add_cloudwatch_tags_from_cache(metadata, aws_attributes)
54+
# Set host as log group where cloudwatch is source
55+
self.set_host(metadata, aws_attributes)
5456
# Set service from custom tags, which may include the tags set on the log group
5557
# Returns DD_SOURCE by default
5658
add_service_tag(metadata)
57-
# Set host as log group where cloudwatch is source
58-
self.set_host(metadata, aws_attributes)
5959
# For Lambda logs we want to extract the function name,
6060
# then rebuild the arn of the monitored lambda using that name.
6161
if metadata[DD_SOURCE] == str(AwsEventSource.LAMBDA):

aws/logs_monitoring/tests/approved_files/TestAWSLogsHandler.test_awslogs_handler_step_functions_tags_added_properly.approved.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
},
1111
"ddsource": "stepfunction",
1212
"ddsourcecategory": "aws",
13-
"ddtags": "forwardername:function_name,forwarder_version:<redacted>,test_tag_key:test_tag_value,dd_step_functions_trace_enabled:true",
13+
"ddtags": "forwardername:function_name,forwarder_version:<redacted>,test_tag_key:test_tag_value,service:customservice,dd_step_functions_trace_enabled:true",
1414
"host": "arn:aws:states:us-east-1:12345678910:stateMachine:StepFunction1",
1515
"id": "37199773595581154154810589279545129148442535997644275712",
1616
"message": "{\"id\": \"1\",\"type\": \"ExecutionStarted\",\"details\": {\"input\": \"{}\",\"inputDetails\": {\"truncated\": \"false\"},\"roleArn\": \"arn:aws:iam::12345678910:role/service-role/StepFunctions-test-role-a0iurr4pt\"},\"previous_event_id\": \"0\",\"event_timestamp\": \"1716992192441\",\"execution_arn\": \"arn:aws:states:us-east-1:12345678910:execution:StepFunction1:ccccccc-d1da-4c38-b32c-2b6b07d713fa\",\"redrive_count\": \"0\"}",
17-
"service": "stepfunction",
17+
"service": "customservice",
1818
"timestamp": 1668095539607
1919
}
2020
]

aws/logs_monitoring/tests/test_awslogs_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_awslogs_handler_step_functions_tags_added_properly(
195195
mock_cache_init.return_value = None
196196
cache_layer = CacheLayer("")
197197
cache_layer._step_functions_cache.get = MagicMock(
198-
return_value=["test_tag_key:test_tag_value"]
198+
return_value=["test_tag_key:test_tag_value", "service:customservice"]
199199
)
200200
cache_layer._cloudwatch_log_group_cache.get = MagicMock()
201201

aws/logs_monitoring/tools/integration_tests/recorder/pb/span_pb2.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/logs_monitoring/tools/integration_tests/recorder/pb/trace_payload_pb2.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/logs_monitoring/tools/integration_tests/recorder/pb/trace_pb2.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rds_enhanced_monitoring/lambda_function.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import botocore
1818
import boto3
1919

20-
2120
DD_SITE = os.getenv("DD_SITE", default="datadoghq.com")
2221

2322

aws/rds_enhanced_monitoring/tests/test_rds_metrics.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,7 @@
226226
"rss": 441652
227227
}]
228228
}
229-
""".replace(
230-
" ", ""
231-
).replace(
232-
"\n", ""
233-
)
229+
""".replace(" ", "").replace("\n", "")
234230

235231

236232
class TestRDSEnhancedMetrics(unittest.TestCase):

0 commit comments

Comments
 (0)