Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit 16761e9

Browse files
authored
fix(event): adding env var to allow cutting exception data (#405)
* fix(event): adding environment variable to allow cutting exception data - frames part * fix(lint): handle exception type specified * fix(event): rename environment variable and add to readme
1 parent 30d1c62 commit 16761e9

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ Advanced options can be configured as a parameter to the init() method or as env
481481
|- |DISABLE_EPSAGON_PATCH |Boolean|`False` |Disable the library patching (instrumentation) |
482482
|- |EPSAGON_LAMBDA_TIMEOUT_THRESHOLD_MS |Integer|`200` |The threshold in millieseconds to send the trace before a Lambda timeout occurs |
483483
|- |EPSAGON_PAYLOADS_TO_IGNORE |List |- |Array of dictionaries to not instrument. Example: `'[{"source": "serverless-plugin-warmup"}]'` |
484+
|- |EPSAGON_REMOVE_EXCEPTION_FRAMES|Boolean|`False` |Disable the automatic capture of exception frames data |
485+
484486

485487

486488
## Getting Help

epsagon/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
# List of ignored endpoints for web frameworks.
4343
IGNORED_ENDPOINTS = []
4444

45+
# Indicates whether to skip collection of the exception frames part
46+
SHOULD_REMOVE_EXCEPTION_FRAMES = (
47+
os.getenv('EPSAGON_REMOVE_EXCEPTION_FRAMES', 'false').lower() == 'true'
48+
)
49+
4550
EPSAGON_MARKER = '__EPSAGON'
4651
EPSAGON_HEADER = 'epsagon-trace-id'
4752
# In some web frameworks, there is an automated capitalization

epsagon/event.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import inspect
99
import uuid
1010
from .common import ErrorCode
11+
from .constants import (
12+
SHOULD_REMOVE_EXCEPTION_FRAMES,
13+
)
1114

1215

1316
class BaseEvent(object):
@@ -152,19 +155,20 @@ def set_exception(
152155
traceback_data
153156
)
154157
self.exception['time'] = time.time()
155-
158+
# Check if to collect the frames
156159
# Adding python frames (input data of functions in stack) in python 3.
157160
# Ignoring filenames with /epsagon since they are ours.
158-
if sys.version_info.major == 3:
159-
self.exception['frames'] = {
160-
'/'.join([
161-
frame.filename,
162-
frame.function,
163-
str(frame.lineno)
164-
]): frame.frame.f_locals
165-
for frame in inspect.trace()
166-
if '/epsagon' not in frame.filename and frame.frame.f_locals
167-
}
161+
if not SHOULD_REMOVE_EXCEPTION_FRAMES:
162+
if sys.version_info.major == 3:
163+
self.exception['frames'] = {
164+
'/'.join([
165+
frame.filename,
166+
frame.function,
167+
str(frame.lineno)
168+
]): frame.frame.f_locals
169+
for frame in inspect.trace()
170+
if '/epsagon' not in frame.filename and frame.frame.f_locals
171+
}
168172
self.exception.setdefault('additional_data', {})['handled'] = handled
169173
if from_logs:
170174
self.exception['additional_data']['from_logs'] = True

0 commit comments

Comments
 (0)