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

Commit

Permalink
fix(event): adding env var to allow cutting exception data (#405)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sagivr2020 committed Apr 13, 2022
1 parent 30d1c62 commit 16761e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ Advanced options can be configured as a parameter to the init() method or as env
|- |DISABLE_EPSAGON_PATCH |Boolean|`False` |Disable the library patching (instrumentation) |
|- |EPSAGON_LAMBDA_TIMEOUT_THRESHOLD_MS |Integer|`200` |The threshold in millieseconds to send the trace before a Lambda timeout occurs |
|- |EPSAGON_PAYLOADS_TO_IGNORE |List |- |Array of dictionaries to not instrument. Example: `'[{"source": "serverless-plugin-warmup"}]'` |
|- |EPSAGON_REMOVE_EXCEPTION_FRAMES|Boolean|`False` |Disable the automatic capture of exception frames data |



## Getting Help
Expand Down
5 changes: 5 additions & 0 deletions epsagon/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
# List of ignored endpoints for web frameworks.
IGNORED_ENDPOINTS = []

# Indicates whether to skip collection of the exception frames part
SHOULD_REMOVE_EXCEPTION_FRAMES = (
os.getenv('EPSAGON_REMOVE_EXCEPTION_FRAMES', 'false').lower() == 'true'
)

EPSAGON_MARKER = '__EPSAGON'
EPSAGON_HEADER = 'epsagon-trace-id'
# In some web frameworks, there is an automated capitalization
Expand Down
26 changes: 15 additions & 11 deletions epsagon/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import inspect
import uuid
from .common import ErrorCode
from .constants import (
SHOULD_REMOVE_EXCEPTION_FRAMES,
)


class BaseEvent(object):
Expand Down Expand Up @@ -152,19 +155,20 @@ def set_exception(
traceback_data
)
self.exception['time'] = time.time()

# Check if to collect the frames
# Adding python frames (input data of functions in stack) in python 3.
# Ignoring filenames with /epsagon since they are ours.
if sys.version_info.major == 3:
self.exception['frames'] = {
'/'.join([
frame.filename,
frame.function,
str(frame.lineno)
]): frame.frame.f_locals
for frame in inspect.trace()
if '/epsagon' not in frame.filename and frame.frame.f_locals
}
if not SHOULD_REMOVE_EXCEPTION_FRAMES:
if sys.version_info.major == 3:
self.exception['frames'] = {
'/'.join([
frame.filename,
frame.function,
str(frame.lineno)
]): frame.frame.f_locals
for frame in inspect.trace()
if '/epsagon' not in frame.filename and frame.frame.f_locals
}
self.exception.setdefault('additional_data', {})['handled'] = handled
if from_logs:
self.exception['additional_data']['from_logs'] = True

0 comments on commit 16761e9

Please sign in to comment.