You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When capturing errors, the Sentry stack traces only contain the frames from when an error happens. It does not contain any frames from the beginning of the execution.
This screenshot shows that only lines 25 and 17 are tracked (see [1] for full code; link to event). Lines 11 and 29 are missing:
You can also notice that all breadcrumbs are missing [2].
You can check how I hacked a script [3] to give those extra missing frames by using traceback.extract_stack(); if you're curious. link to event
[1]
importosimporttracebackimportsentry_sdkfromsentry_sdkimportcapture_exceptionsentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"))
defmain():
foo() # line 11deffoo():
try:
print("Message before exception")
bar() # line 17exceptException:
print("Message after capturing exception")
traceback.print_exc()
capture_exception()
defbar():
raiseException("This is a test exception") # line 25if__name__=="__main__":
main() # line 29
[2] Output
Message before exception
Message after capturing exception
Traceback (most recent call last):
File "/Users/armenzg/code/learning/scripts/foo.py", line 16, in foo
bar()
File "/Users/armenzg/code/learning/scripts/foo.py", line 23, in bar
raise Exception("This is a test exception")
Exception: This is a test exception
[3]
importosimportsysimporttracebackimportsentry_sdkfromsentry_sdkimportcapture_exception# For Python 3.11+ifsys.version_info>= (3, 11):
frombuiltinsimportExceptionGroupelse:
# For Python versions before 3.11fromexceptiongroupimportExceptionGroupsentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"))
classCustomException(Exception):
def__init__(self, message, tb_frames):
super().__init__(message)
self.tb_frames=tb_framesdef__str__(self):
frames= []
forfinself.tb_frames[:-1]:
# File "sentry_capture_exception.py", line 34, in fooline1=f' File "{f[0]}", line {f[1]}, in {f[2]}'line2=f" {f[3]}"frames.append("\n".join([line1, line2]))
tb_str="\n".join(frames)
# Sample:# Exception: This is a test exception# File "sentry_capture_exception.py", line 40, in foo# bar()# File "sentry_capture_exception.py", line 58, in bar# raise Exception("This is a test exception")returnf"{self.__class__.__name__}: foo\n{tb_str}"defmain():
foo()
deffoo():
try:
bar()
exceptExceptionasoriginal_error:
stack_trace=traceback.extract_stack()
stack_exception=CustomException("An error occurred", stack_trace)
# Create an ExceptionGroup with the original error and traceback exceptionexception_group=ExceptionGroup(
"Error occurred in foo()", [original_error, stack_exception]
)
# Capture the ExceptionGroupcapture_exception(exception_group)
defbar():
raiseException("This is a test exception")
if__name__=="__main__":
main()
The text was updated successfully, but these errors were encountered:
When capturing errors, the Sentry stack traces only contain the frames from when an error happens. It does not contain any frames from the beginning of the execution.
This screenshot shows that only lines 25 and 17 are tracked (see [1] for full code; link to event). Lines 11 and 29 are missing:
You can also notice that all breadcrumbs are missing [2].
You can check how I hacked a script [3] to give those extra missing frames by using
traceback.extract_stack()
; if you're curious.link to event
[1]
[2] Output
[3]
The text was updated successfully, but these errors were encountered: