Skip to content

Commit eac52a8

Browse files
authored
apply processors to chained exceptions (#604)
1 parent 1f4c363 commit eac52a8

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
[Check the diff](https://github.com/elastic/apm-agent-python/compare/v5.2.0...master)
5+
6+
### Bugfixes
7+
* fixed an issue with DroppedSpans and logging integration (#602)
8+
* fixed an issue with processors not being applied to chained exceptions (#604)
9+
310
## v5.2.0
411
[Check the diff](https://github.com/elastic/apm-agent-python/compare/v5.1.2...v5.2.0)
512

elasticapm/processors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ def _process_stack_frames(event, func):
283283
if "exception" in event and "stacktrace" in event["exception"]:
284284
for frame in event["exception"]["stacktrace"]:
285285
func(frame)
286+
# check for chained exceptions
287+
cause = event["exception"].get("cause", None)
288+
while cause:
289+
if "stacktrace" in cause[0]:
290+
for frame in cause[0]["stacktrace"]:
291+
func(frame)
292+
cause = cause[0].get("cause", None)
286293
if "log" in event and "stacktrace" in event["log"]:
287294
for frame in event["log"]["stacktrace"]:
288295
func(frame)

tests/processors/tests.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,51 @@ def test_stacktrace():
8888
"exception": {
8989
"stacktrace": [
9090
{"vars": {"foo": "bar", "password": "hello", "the_secret": "hello", "a_password_here": "hello"}}
91-
]
91+
],
92+
"cause": [
93+
{
94+
"stacktrace": [
95+
{"vars": {"foo": "bar", "password": "hello", "the_secret": "hello", "a_password_here": "hello"}}
96+
],
97+
"cause": [
98+
{
99+
"stacktrace": [
100+
{
101+
"vars": {
102+
"foo": "bar",
103+
"password": "hello",
104+
"the_secret": "hello",
105+
"a_password_here": "hello",
106+
}
107+
}
108+
]
109+
}
110+
],
111+
}
112+
],
92113
}
93114
}
94115

95116
result = processors.sanitize_stacktrace_locals(None, data)
96117

97118
assert "stacktrace" in result["exception"]
98-
stack = result["exception"]["stacktrace"]
99-
assert len(stack) == 1
100-
frame = stack[0]
101-
assert "vars" in frame
102-
vars = frame["vars"]
103-
assert "foo" in vars
104-
assert vars["foo"] == "bar"
105-
assert "password" in vars
106-
assert vars["password"] == processors.MASK
107-
assert "the_secret" in vars
108-
assert vars["the_secret"] == processors.MASK
109-
assert "a_password_here" in vars
110-
assert vars["a_password_here"] == processors.MASK
119+
for stacktrace in (
120+
result["exception"]["stacktrace"],
121+
result["exception"]["cause"][0]["stacktrace"],
122+
result["exception"]["cause"][0]["cause"][0]["stacktrace"],
123+
):
124+
assert len(stacktrace) == 1
125+
frame = stacktrace[0]
126+
assert "vars" in frame
127+
vars = frame["vars"]
128+
assert "foo" in vars
129+
assert vars["foo"] == "bar"
130+
assert "password" in vars
131+
assert vars["password"] == processors.MASK
132+
assert "the_secret" in vars
133+
assert vars["the_secret"] == processors.MASK
134+
assert "a_password_here" in vars
135+
assert vars["a_password_here"] == processors.MASK
111136

112137

113138
def test_remove_http_request_body(http_test_data):

0 commit comments

Comments
 (0)