Skip to content

Commit 10063a6

Browse files
authored
bugfix for tag_object (#390)
1 parent df70de2 commit 10063a6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

datadog_lambda/tag_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def tag_object(span, key, obj, depth=0):
1616
if obj is None:
1717
return span.set_tag(key, obj)
1818
if depth >= max_depth:
19-
return tag_object(span, key, _redact_val(key, str(obj)[0:5000]))
19+
return span.set_tag(key, _redact_val(key, str(obj)[0:5000]))
2020
depth += 1
2121
if _should_try_string(obj):
2222
parsed = None

tests/test_tag_object.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@ def test_tag_object_max_depth(self):
6262
True,
6363
)
6464

65+
def test_tag_object_max_depth_0(self):
66+
payload = {
67+
"hello": "world",
68+
"level1": {
69+
"level2_dict": {"level3": 3},
70+
"level2_list": [None, True, "nice", {"l3": "v3"}],
71+
"level2_bool": True,
72+
"level2_int": 2,
73+
},
74+
"vals": [{"thingOne": 1}, {"thingTwo": 2}],
75+
}
76+
spanMock = MagicMock()
77+
import datadog_lambda.tag_object as lib_ref
78+
79+
lib_ref.max_depth = 0 # setting up the test
80+
tag_object(spanMock, "function.request", payload)
81+
lib_ref.max_depth = 10 # revert the setup
82+
spanMock.set_tag.assert_has_calls(
83+
[
84+
call(
85+
"function.request",
86+
"{'hello': 'world', 'level1': {'level2_dict': {'level3': 3}, 'level2_list': [None, True, 'nice', {'l3': 'v3'}], 'level2_bool': True, 'level2_int': 2}, 'vals': [{'thingOne': 1}, {'thingTwo': 2}]}",
87+
),
88+
],
89+
True,
90+
)
91+
6592
def test_redacted_tag_object(self):
6693
payload = {
6794
"authorization": "world",

0 commit comments

Comments
 (0)