File tree 3 files changed +43
-3
lines changed
3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,7 @@ def __init__(
185
185
project_root = None , # type: Optional[str]
186
186
enable_tracing = None , # type: Optional[bool]
187
187
include_local_variables = True , # type: Optional[bool]
188
+ include_source_context = True , # type: Optional[bool]
188
189
trace_propagation_targets = [ # noqa: B006
189
190
MATCH_ALL
190
191
], # type: Optional[Sequence[str]]
Original file line number Diff line number Diff line change @@ -632,16 +632,20 @@ def serialize_frame(
632
632
return rv
633
633
634
634
635
- def current_stacktrace (include_local_variables = True ):
636
- # type: (bool) -> Any
635
+ def current_stacktrace (include_local_variables = True , include_source_context = True ):
636
+ # type: (bool, bool ) -> Any
637
637
__tracebackhide__ = True
638
638
frames = []
639
639
640
640
f = sys ._getframe () # type: Optional[FrameType]
641
641
while f is not None :
642
642
if not should_hide_frame (f ):
643
643
frames .append (
644
- serialize_frame (f , include_local_variables = include_local_variables )
644
+ serialize_frame (
645
+ f ,
646
+ include_local_variables = include_local_variables ,
647
+ include_source_context = include_source_context ,
648
+ )
645
649
)
646
650
f = f .f_back
647
651
@@ -677,14 +681,17 @@ def single_exception_from_error_tuple(
677
681
678
682
if client_options is None :
679
683
include_local_variables = True
684
+ include_source_context = True
680
685
else :
681
686
include_local_variables = client_options ["include_local_variables" ]
687
+ include_source_context = client_options ["include_source_context" ]
682
688
683
689
frames = [
684
690
serialize_frame (
685
691
tb .tb_frame ,
686
692
tb_lineno = tb .tb_lineno ,
687
693
include_local_variables = include_local_variables ,
694
+ include_source_context = include_source_context ,
688
695
)
689
696
for tb in iter_stacks (tb )
690
697
]
Original file line number Diff line number Diff line change @@ -365,6 +365,38 @@ def test_include_local_variables_disabled(sentry_init, capture_events):
365
365
)
366
366
367
367
368
+ def test_include_source_context_enabled (sentry_init , capture_events ):
369
+ sentry_init (include_source_context = True )
370
+ events = capture_events ()
371
+ try :
372
+ 1 / 0
373
+ except Exception :
374
+ capture_exception ()
375
+
376
+ (event ,) = events
377
+
378
+ frame = event ["exception" ]["values" ][0 ]["stacktrace" ]["frames" ][0 ]
379
+ assert "post_context" in frame
380
+ assert "pre_context" in frame
381
+ assert "context_line" in frame
382
+
383
+
384
+ def test_include_source_context_disabled (sentry_init , capture_events ):
385
+ sentry_init (include_source_context = False )
386
+ events = capture_events ()
387
+ try :
388
+ 1 / 0
389
+ except Exception :
390
+ capture_exception ()
391
+
392
+ (event ,) = events
393
+
394
+ frame = event ["exception" ]["values" ][0 ]["stacktrace" ]["frames" ][0 ]
395
+ assert "post_context" not in frame
396
+ assert "pre_context" not in frame
397
+ assert "context_line" not in frame
398
+
399
+
368
400
@pytest .mark .parametrize ("integrations" , [[], [ExecutingIntegration ()]])
369
401
def test_function_names (sentry_init , capture_events , integrations ):
370
402
sentry_init (integrations = integrations )
You can’t perform that action at this time.
0 commit comments