Skip to content

Commit a1bf836

Browse files
majorgreysbrettlangdon
authored andcommitted
[aws] Blacklist arguments stored as tags (#761)
* Add blacklist for params argument of function * Remove unnecessary import * Add blacklist to aiobotocore * Check params * Fix tests * Add blacklisted for s3 * Remove commented-out line
1 parent 681d14e commit a1bf836

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

ddtrace/ext/aws.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from ..utils.formats import flatten_dict
22

33

4-
BLACKLIST_ENDPOINT = ["kms", "sts"]
4+
BLACKLIST_ENDPOINT = ['kms', 'sts']
5+
BLACKLIST_ENDPOINT_TAGS = {
6+
's3': ['params.Body'],
7+
}
58

69

710
def truncate_arg_value(value, max_len=1024):
@@ -16,13 +19,18 @@ def truncate_arg_value(value, max_len=1024):
1619

1720
def add_span_arg_tags(span, endpoint_name, args, args_names, args_traced):
1821
if endpoint_name not in BLACKLIST_ENDPOINT:
22+
blacklisted = BLACKLIST_ENDPOINT_TAGS.get(endpoint_name, [])
1923
tags = dict(
2024
(name, value)
2125
for (name, value) in zip(args_names, args)
2226
if name in args_traced
2327
)
2428
tags = flatten_dict(tags)
25-
tags = {k: truncate_arg_value(v) for k, v in tags.items()}
29+
tags = {
30+
k: truncate_arg_value(v)
31+
for k, v in tags.items()
32+
if k not in blacklisted
33+
}
2634
span.set_tags(tags)
2735

2836

tests/contrib/aiobotocore/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_s3_put(self):
8080
self.assertEqual(spans[1].resource, 's3.putobject')
8181
self.assertEqual(spans[1].get_tag('params.Key'), stringify(params['Key']))
8282
self.assertEqual(spans[1].get_tag('params.Bucket'), stringify(params['Bucket']))
83-
self.assertEqual(spans[1].get_tag('params.Body'), stringify(params['Body']))
83+
self.assertIsNone(spans[1].get_tag('params.Body'))
8484

8585
@mark_asyncio
8686
def test_s3_client_error(self):

tests/contrib/botocore/test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# stdlib
2-
import unittest
2+
from unittest import TestCase
33

44
# 3p
55
import botocore.session
@@ -16,7 +16,7 @@
1616
from ...test_tracer import get_dummy_tracer
1717

1818

19-
class BotocoreTest(unittest.TestCase):
19+
class BotocoreTest(TestCase):
2020
"""Botocore integration testsuite"""
2121

2222
TEST_SERVICE = "test-botocore-tracing"
@@ -104,7 +104,8 @@ def test_s3_put(self):
104104
self.assertEqual(spans[1].resource, 's3.putobject')
105105
self.assertEqual(spans[1].get_tag('params.Key'), stringify(params['Key']))
106106
self.assertEqual(spans[1].get_tag('params.Bucket'), stringify(params['Bucket']))
107-
self.assertEqual(spans[1].get_tag('params.Body'), stringify(params['Body']))
107+
# confirm blacklisted
108+
self.assertIsNone(spans[1].get_tag('params.Body'))
108109

109110
@mock_sqs
110111
def test_sqs_client(self):

0 commit comments

Comments
 (0)