Skip to content

Commit d507e14

Browse files
authored
Enable step function tracing at forwarder level (#831)
* Initial logic to add fetch and add the lambda tag * Set tag in env var to avoid fetching everytime * Moved tag to cloudformation param * Fixed readme, moved param under advanced param * Removed context passing * Removed unused import * Fixed template condition * Update readme language for consistency * Moved tagging outside of just lambda * black formatting * Updated language to specify all step functions * Updated language to call it tracing instead of l2t * Moved step functions specific logic to handle_step_function_source() * Updated tests to check for new tag * renamed to 'Step Functions', missing 's' before
1 parent 7b57e08 commit d507e14

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

aws/logs_monitoring/README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Starting version 3.107.0 a new feature is added to enable Lambda function to sto
148148

149149
### Upgrade an older version to +3.106.0
150150

151-
Starting version 3.106.0 Lambda function has been updated to add a prefix to cache filenames stored in the S3 bucket configured in `DD_S3_BUCKET_NAME`. This allows to use the same bucket to store cache files from several functions.
151+
Starting version 3.106.0 Lambda function has been updated to add a prefix to cache filenames stored in the S3 bucket configured in `DD_S3_BUCKET_NAME`. This allows to use the same bucket to store cache files from several functions.
152152
Additionally, starting this version, the forwarder will attach custom S3 bucket tags by default to all logs exported to S3. For example, if a service is configured to send logs to a destiantion S3 bucket, the forwarder will add the bucket's tags to the logs while pulling and forwarding the logs.
153153

154154
### Upgrade an older version to +3.99.0
@@ -388,15 +388,6 @@ SSL encrypted TCP connection, set this parameter to true.
388388
`DdForwardLog`
389389
: Set to false to disable log forwarding, while continuing to forward other observability data, such as metrics and traces from Lambda functions.
390390

391-
`DdFetchLambdaTags`
392-
: Let the Forwarder fetch Lambda tags using GetResources API calls and apply them to logs, metrics, and traces. If set to true, permission `tag:GetResources` will be automatically added to the Lambda execution IAM role.
393-
394-
`DdFetchLogGroupTags`
395-
: Let the forwarder fetch Log Group tags using ListTagsLogGroup and apply them to logs, metrics, and traces. If set to true, permission `logs:ListTagsLogGroup` will be automatically added to the Lambda execution IAM role.
396-
397-
`DdFetchStepFunctionsTags`
398-
: Let the Forwarder fetch Step Functions tags using GetResources API calls and apply them to logs and traces (if Step Functions tracing is enabled). If set to true, permission `tag:GetResources` will be automatically added to the Lambda execution IAM role.
399-
400391
### Log scrubbing (optional)
401392

402393
`RedactIp`
@@ -433,6 +424,18 @@ To test different patterns against your logs, turn on [debug logs](#troubleshoot
433424

434425
### Advanced (optional)
435426

427+
`DdFetchLambdaTags`
428+
: Let the Forwarder fetch Lambda tags using GetResources API calls and apply them to logs, metrics, and traces. If set to true, permission `tag:GetResources` will be automatically added to the Lambda execution IAM role.
429+
430+
`DdFetchLogGroupTags`
431+
: Let the forwarder fetch Log Group tags using ListTagsLogGroup and apply them to logs, metrics, and traces. If set to true, permission `logs:ListTagsLogGroup` will be automatically added to the Lambda execution IAM role.
432+
433+
`DdFetchStepFunctionsTags`
434+
: Let the Forwarder fetch Step Functions tags using GetResources API calls and apply them to logs and traces (if Step Functions tracing is enabled). If set to true, permission `tag:GetResources` will be automatically added to the Lambda execution IAM role.
435+
436+
`DdStepFunctionTraceEnabled`
437+
: Set to true to enable tracing for all Step Functions.
438+
436439
`SourceZipUrl`
437440
: Do not change unless you know what you are doing. Override the default location of the function source code.
438441

aws/logs_monitoring/steps/handlers/awslogs_handler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ def handle_step_function_source(self):
184184
+ ",".join(formatted_stepfunctions_tags)
185185
)
186186

187+
if os.environ.get("DD_STEP_FUNCTIONS_TRACE_ENABLED", "false").lower() == "true":
188+
self.metadata[DD_CUSTOM_TAGS] = ",".join(
189+
[self.metadata.get(DD_CUSTOM_TAGS, [])]
190+
+ ["dd_step_functions_trace_enabled:true"]
191+
)
192+
187193
def handle_verified_access_source(self):
188194
try:
189195
message = json.loads(self.aws_attributes.get_log_events()[0].get("message"))

aws/logs_monitoring/template.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ Parameters:
161161
- true
162162
- false
163163
Description: Set to false to disable log forwarding, while continuing to forward other observability data, such as metrics and traces from Lambda functions.
164+
DdStepFunctionsTraceEnabled:
165+
Type: String
166+
Default: false
167+
AllowedValues:
168+
- true
169+
- false
170+
Description: Set to true to enable tracing for all Step Functions.
164171
DdUseCompression:
165172
Type: String
166173
Default: true
@@ -391,6 +398,10 @@ Conditions:
391398
Fn::Equals:
392399
- Ref: DdForwardLog
393400
- false
401+
SetDdStepFunctionsTraceEnabled:
402+
Fn::Equals:
403+
- Ref: DdStepFunctionsTraceEnabled
404+
- true
394405
SetDdUseCompression:
395406
Fn::Equals:
396407
- Ref: DdUseCompression
@@ -615,6 +626,11 @@ Resources:
615626
- SetDdForwardLog
616627
- Ref: DdForwardLog
617628
- Ref: AWS::NoValue
629+
DD_STEP_FUNCTIONS_TRACE_ENABLED:
630+
Fn::If:
631+
- SetDdStepFunctionsTraceEnabled
632+
- Ref: DdStepFunctionsTraceEnabled
633+
- Ref: AWS::NoValue
618634
DD_USE_COMPRESSION:
619635
Fn::If:
620636
- SetDdUseCompression
@@ -1148,6 +1164,7 @@ Metadata:
11481164
- DdFetchLambdaTags
11491165
- DdFetchLogGroupTags
11501166
- DdFetchStepFunctionsTags
1167+
- DdStepFunctionsTraceEnabled
11511168
- TagsCacheTTLSeconds
11521169
- SourceZipUrl
11531170
- InstallAsLayer
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ddsource": "stepfunction",
3-
"ddtags": "env:dev,test_tag_key:test_tag_value",
3+
"ddtags": "env:dev,test_tag_key:test_tag_value,dd_step_functions_trace_enabled:true",
44
"host": "/aws/vendedlogs/states/logs-to-traces-sequential-Logs",
55
"service": "stepfunction"
66
}

aws/logs_monitoring/tests/test_awslogs_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_awslogs_handler_rds_postgresql(self, mock_cache_init):
7171

7272
@patch("caching.cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.__init__")
7373
@patch("caching.cloudwatch_log_group_cache.send_forwarder_internal_metrics")
74+
@patch.dict("os.environ", {"DD_STEP_FUNCTIONS_TRACE_ENABLED": "true"})
7475
def test_awslogs_handler_step_functions_tags_added_properly(
7576
self,
7677
mock_forward_metrics,

0 commit comments

Comments
 (0)