Skip to content

Commit fc1c286

Browse files
authored
feat: Pretty print JSON for python. Fix missing regular expressions for masking out ephemeral information (#215)
* feat: Pretty print JSON for python. Fix missing regular expressions for masking out ephemeral information * feat: Fix backticks in test script. Pin serverless to 3.7 * feat: Mask init duration * fix: remember to actually commit the removed duration * feat: update test app to use sls v3
1 parent 469ece6 commit fc1c286

12 files changed

+11142
-479
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
pip install .[dev]
9999
100100
- name: Install Serverless Framework
101-
run: sudo yarn global add serverless@^2.72.2 --prefix /usr/local
101+
run: sudo yarn global add serverless@^3.7.0 --prefix /usr/local
102102
- name: Install Crossbuild Deps
103103
run: |
104104
sudo apt-get update --allow-releaseinfo-change --fix-missing

scripts/run_integration_tests.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,15 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
175175
# Replace invocation-specific data like timestamps and IDs with XXXX to normalize logs across executions
176176
logs=$(
177177
echo "$raw_logs" |
178+
node parse-json.js |
178179
# Filter serverless cli errors
179180
sed '/Serverless: Recoverable error occurred/d' |
180181
# Remove RequestsDependencyWarning from botocore/vendored/requests/__init__.py
181182
sed '/RequestsDependencyWarning/d' |
182183
# Remove blank lines
183184
sed '/^$/d' |
184185
# Normalize Lambda runtime REPORT logs
185-
sed -E 's/(RequestId|TraceId|SegmentId|Duration|Memory Used|"e"): [a-z0-9\.\-]+/\1: XXXX/g' |
186+
sed -E 's/(RequestId|TraceId|SegmentId|Duration|init|Memory Used|"e"): [a-z0-9\.\-]+/\1: XXXX/g' |
186187
# Normalize HTTP headers
187188
sed -E "s/(x-datadog-parent-id:|x-datadog-trace-id:|Content-Length:)[0-9]+/\1XXXX/g" |
188189
# Remove Account ID
@@ -204,12 +205,29 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
204205
sed -E "s/(\"span_id\"\: \")[A-Z0-9\.\-]+/\1XXXX/g" |
205206
sed -E "s/(\"parent_id\"\: \")[A-Z0-9\.\-]+/\1XXXX/g" |
206207
sed -E "s/(\"request_id\"\: \")[a-z0-9\.\-]+/\1XXXX/g" |
208+
sed -E "s/(\"http.source_ip\"\: \")[a-z0-9\.\-]+/\1XXXX/g" |
209+
sed -E "s/(\"http.user_agent\"\: \")[a-z0-9\.\-]+/\1XXXX/g" |
210+
sed -E "s/(\"function_trigger.event_source_arn\"\: \")[A-Za-z0-9\/\.\:\-]+/\1XXXX/g" |
207211
sed -E "s/(\"duration\"\: )[0-9\.\-]+/\1\"XXXX\"/g" |
208212
sed -E "s/(\"start\"\: )[0-9\.\-]+/\1\"XXXX\"/g" |
209213
sed -E "s/(\"system\.pid\"\: )[0-9\.\-]+/\1\"XXXX\"/g" |
210214
sed -E "s/(\"runtime-id\"\: \")[a-z0-9\.\-]+/\1XXXX/g" |
215+
sed -E "s/([a-zA-Z0-9]+)(\.execute-api\.[a-z0-9\-]+\.amazonaws\.com)/XXXX\2/g" |
216+
sed -E "s/(\"apiid\"\: \")[a-z0-9\.\-]+/\1XXXX/g" |
217+
sed -E "s/(\"apiname\"\: \")[a-z0-9\.\-]+/\1XXXX/g" |
218+
sed -E "s/(\"function_trigger.event_source_arn\"\: \")[a-z0-9\.\-\:]+/\1XXXX/g" |
219+
sed -E "s/(\"event_id\"\: \")[a-zA-Z0-9\:\-]+/\1XXXX/g" |
220+
sed -E "s/(\"message_id\"\: \")[a-zA-Z0-9\:\-]+/\1XXXX/g" |
221+
sed -E "s/(\"request_id\"\:\ \")[a-zA-Z0-9\-\=]+/\1XXXX/g" |
222+
sed -E "s/(\"connection_id\"\:\ \")[a-zA-Z0-9\-]+/\1XXXX/g" |
223+
sed -E "s/(\"shardId\-)([0-9]+)\:([a-zA-Z0-9]+)[a-zA-Z0-9]/\1XXXX:XXXX/g" |
224+
sed -E "s/(\"shardId\-)[0-9a-zA-Z]+/\1XXXX/g" |
211225
sed -E "s/(\"datadog_lambda\"\: \")([0-9]+\.[0-9]+\.[0-9])/\1X.X.X/g" |
226+
sed -E "s/(\"partition_key\"\:\ \")[a-zA-Z0-9\-]+/\1XXXX/g" |
227+
sed -E "s/(\"object_etag\"\:\ \")[a-zA-Z0-9\-]+/\1XXXX/g" |
212228
sed -E "s/(\"dd_trace\"\: \")([0-9]+\.[0-9]+\.[0-9])/\1X.X.X/g" |
229+
# Parse out account ID in ARN
230+
sed -E "s/([a-zA-Z0-9]+):([a-zA-Z0-9]+):([a-zA-Z0-9]+):([a-zA-Z0-9\-]+):([a-zA-Z0-9\-\:]+)/\1:\2:\3:\4:XXXX:\4/g" |
213231
sed -E "/init complete at epoch/d" |
214232
sed -E "/main started at epoch/d"
215233
)
@@ -240,7 +258,7 @@ set -e
240258
if [ "$mismatch_found" = true ]; then
241259
echo "FAILURE: A mismatch between new data and a snapshot was found and printed above."
242260
echo "If the change is expected, generate new snapshots by running 'UPDATE_SNAPSHOTS=true DD_API_KEY=XXXX ./scripts/run_integration_tests.sh'"
243-
echo "Make sure https://httpstat.us/400/ is UP for `http_error` test case"
261+
echo "Make sure https://httpstat.us/400/ is UP for 'http_error' test case"
244262
exit 1
245263
fi
246264

tests/integration/parse-json.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
var readline = require('readline');
4+
var rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
terminal: false
8+
});
9+
10+
rl.on('line', function(line){
11+
try {
12+
const obj = JSON.parse(line)
13+
console.log(JSON.stringify(obj, null, 2))
14+
} catch (e) {
15+
console.log(line)
16+
}
17+
})

tests/integration/serverless.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# IAM permissions require service name to begin with 'integration-tests'
22
service: integration-tests-python
33

4-
# As of mid-August 2021, the Serverless framework does not support Python 3.9
5-
# and complains about an invalid configuration when we deploy Python 3.9 functions.
6-
# This option suppresses the warning.
7-
# Remove this when the Serverless framework supports Python 3.9.
8-
configValidationMode: off
9-
104
provider:
115
name: aws
126
region: sa-east-1
@@ -17,8 +11,6 @@ provider:
1711
DD_TRACE_ENABLED: true
1812
DD_API_KEY: ${env:DD_API_KEY}
1913
DD_TRACE_MANAGED_SERVICES: true
20-
DD_CAPTURE_LAMBDA_PAYLOAD: true
21-
lambdaHashingVersion: 20201221
2214
timeout: 15
2315
deploymentBucket:
2416
name: integration-tests-deployment-bucket

tests/integration/snapshots/logs/async-metrics_python36.log

Lines changed: 1334 additions & 63 deletions
Large diffs are not rendered by default.

tests/integration/snapshots/logs/async-metrics_python37.log

Lines changed: 1334 additions & 63 deletions
Large diffs are not rendered by default.

tests/integration/snapshots/logs/async-metrics_python38.log

Lines changed: 1334 additions & 63 deletions
Large diffs are not rendered by default.

tests/integration/snapshots/logs/async-metrics_python39.log

Lines changed: 1334 additions & 63 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)