diff --git a/datadog_lambda/tag_object.py b/datadog_lambda/tag_object.py index b8e26934..ec1c5a66 100644 --- a/datadog_lambda/tag_object.py +++ b/datadog_lambda/tag_object.py @@ -16,7 +16,7 @@ def tag_object(span, key, obj, depth=0): if obj is None: return span.set_tag(key, obj) if depth >= max_depth: - return tag_object(span, key, _redact_val(key, str(obj)[0:5000])) + return span.set_tag(key, _redact_val(key, str(obj)[0:5000])) depth += 1 if _should_try_string(obj): parsed = None diff --git a/tests/test_tag_object.py b/tests/test_tag_object.py index eac84f7c..77512164 100644 --- a/tests/test_tag_object.py +++ b/tests/test_tag_object.py @@ -62,6 +62,33 @@ def test_tag_object_max_depth(self): True, ) + def test_tag_object_max_depth_0(self): + payload = { + "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}], + } + spanMock = MagicMock() + import datadog_lambda.tag_object as lib_ref + + lib_ref.max_depth = 0 # setting up the test + tag_object(spanMock, "function.request", payload) + lib_ref.max_depth = 10 # revert the setup + spanMock.set_tag.assert_has_calls( + [ + call( + "function.request", + "{'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}]}", + ), + ], + True, + ) + def test_redacted_tag_object(self): payload = { "authorization": "world",