Sourcecode not visible when using PyInstaller
See original GitHub issueImportant Details
How are you running Sentry? Frozen python app created with PyInstaller
On-Premise w/ Docker, version x.y.z
Saas (sentry.io)
Other, version x.y.z, [briefly describe your environment]
Description
When my app is frozen with pyinstaller, the error context lines are not captured.
Added a couple print statements in sentry_sdk/utils.py
:
def get_lines_from_file(
filename, # type: str
lineno, # type: int
loader=None, # type: Optional[Any]
module=None, # type: Optional[str]
):
# type: (...) -> Tuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]
context_lines = 5
source = None
if loader is not None and hasattr(loader, "get_source"):
try:
source_str = loader.get_source(module) # type: Optional[str]
except (ImportError, IOError):
source_str = None
if source_str is not None:
source = source_str.splitlines()
print(f'filename: {filename}, module: {module}')
print(f'source is None: {source is None}')
if source is None:
try:
source = linecache.getlines(filename)
print(f'source: {source}')
except (OSError, IOError):
return [], None, []
and at the end of sentry_sdk\client.py
at line 216 in _prepare_event
, i just printed print(event['exception'])
to see the final event exception passed out. (trimmed some extra non imporant stuff off this)
App not frozen (working):
filename: Y:\OneDrive\Python\SMS\smseventlog\gui\gui.py, module: smseventlog.gui.gui
source is None: False
{'filename': 'smseventlog\\gui\\gui.py',
'abs_path': 'Y:\\OneDrive\\Python\\SMS\\smseventlog\\gui\\gui.py',
'function': 'test_error',
'module': 'smseventlog.gui.gui',
'lineno': 257,
'pre_context': ['', ' def test_error(self):', ' a = 5', ' b = 6', ''],
'context_line': ' return a / 0',
'post_context': ['', ' def create_actions(self):', ' # Menu/shortcuts', ' t = self.active_table_widget', ''],
'vars': {'self': '<smseventlog.gui.gui.MainWindow object at 0x000002CD9D0DFAF0>', 'a': '5', 'b': '6'},
'in_app': True}]}
App frozen (not working):
filename: smseventlog\gui\gui.py, module: smseventlog.gui.gui
source is None: True
source: []
{'filename': 'smseventlog\\gui\\gui.py',
'abs_path': 'C:\\Users\\Jayme\\Documents\\smseventlog\\dist\\smseventlog_win\\smseventlog\\gui\\gui.py',
'function': 'test_error',
'module': 'smseventlog.gui.gui',
'lineno': 257,
'pre_context': [],
'context_line': None,
'post_context': [],
'vars': {'self': '<smseventlog.gui.gui.MainWindow object at 0x0000022638C4A280>', 'a': '5', 'b': '6'},
'in_app': True}]}}]}
the difference seems to be that in the non frozen app, the full filename is recognized Y:\OneDrive\Python\SMS\smseventlog\gui\gui.py
, while in the frozen app its only recoginzed as smseventlog\gui\gui.py
and the module can’t be propery read to find the lines specified in the traceback.
Steps to Reproduce
What you expected to happen
Pre and post context should be captured, even in a frozen app.
Possible Solution
[If you have an idea on how this could be solved include that detail here.]
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Any progress on this one? would be super helpful to have working thx!!! 😃
That’s a known issue in the Python SDK. Moving there.