From af5f129c9e2a0d4bbcdb2d586ea6e6ffd478576d Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Mon, 5 Oct 2026 15:13:58 +0200 Subject: [PATCH 1/4] chore: Remove include_local_variables, include_source_context --- MIGRATION_GUIDE.md | 3 +- sentry_sdk/client.py | 9 +- sentry_sdk/consts.py | 10 -- sentry_sdk/data_collection.py | 35 +----- sentry_sdk/integrations/logging.py | 3 - sentry_sdk/utils.py | 34 +----- .../integrations/pure_eval/test_pure_eval.py | 2 +- tests/test_client.py | 22 ++-- tests/test_data_collection.py | 19 --- tests/test_exceptiongroup.py | 18 --- tests/test_utils.py | 113 +----------------- 11 files changed, 31 insertions(+), 237 deletions(-) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 41bb93ff69..9cdbe9b9bc 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -165,7 +165,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh - The `stream_gen_ai_spans` option was removed. All spans are streamed now. - The experimental `record_sql_params` option was removed. Use the `database_query_data` setting of `data_collection` instead. - The `record_params` option of `AsyncPGIntegration` and `AioMySQLIntegration` was removed. Use the `database_query_data` setting of `data_collection` instead. - +- The `include_local_variables` option was removed. Use `data_collection`'s `stack_frame_variables` as a drop-in replacement. +- The `include_source_context` option was removed. Use `data_collection`'s `frame_context_lines` for more granular control over the source context reported by specifying the number of lines to include around the failing line, or set `frame_context_lines=0` to disable source context entirely. ## Deprecated diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 7692427fa3..f38f17a68e 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -377,11 +377,7 @@ def _record_lost_event( # data_collection explicitly). if not self.options["data_collection"]["provided_by_user"]: self.options["data_collection"] = _map_from_send_default_pii( - send_default_pii=True, - include_local_variables=self.options["include_local_variables"] - is not False, - include_source_context=self.options["include_source_context"] - is not False, + send_default_pii=True ) self.session_flusher = SessionFlusher(capture_func=_capture_envelope) @@ -524,9 +520,6 @@ def _prepare_event( "values": [ { "stacktrace": current_stacktrace( - include_local_variables=self.options.get( - "include_local_variables", True - ), max_value_length=self.options.get( "max_value_length", DEFAULT_MAX_VALUE_LENGTH ), diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index dd8b2ef775..cefad4b634 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -1379,8 +1379,6 @@ def __init__( _experiments: "Experiments" = {}, # noqa: B006 proxy_headers: "Optional[Dict[str, str]]" = None, project_root: "Optional[str]" = None, - include_local_variables: "Optional[bool]" = True, - include_source_context: "Optional[bool]" = True, trace_propagation_targets: "Optional[Sequence[str]]" = [ # noqa: B006 MATCH_ALL ], @@ -1517,14 +1515,6 @@ def __init__( See https://docs.sentry.io/platforms/python/configuration/options/#data_collection for more details. - :param include_source_context: When enabled, source context will be included in events sent to Sentry. - - This source context includes the five lines of code above and below the line of code where an error - happened. - - :param include_local_variables: When enabled, the SDK will capture a snapshot of local variables to send with - the event to help with debugging. - :param add_full_stack: When capturing errors, Sentry stack traces typically only include frames that start the moment an error occurs. diff --git a/sentry_sdk/data_collection.py b/sentry_sdk/data_collection.py index 1cc92a2763..a7511c1a1a 100644 --- a/sentry_sdk/data_collection.py +++ b/sentry_sdk/data_collection.py @@ -149,12 +149,7 @@ def _apply_key_value_collection_filtering( return result -def _map_from_send_default_pii( - *, - send_default_pii: bool, - include_local_variables: bool, - include_source_context: bool, -) -> "DataCollection": +def _map_from_send_default_pii(*, send_default_pii: bool) -> "DataCollection": """ Build a fully-resolved ``DataCollection`` dict that mirrors the data ``send_default_pii`` collects today. Used when ``data_collection`` is not @@ -179,10 +174,8 @@ def _map_from_send_default_pii( "gen_ai": {"inputs": send_default_pii, "outputs": send_default_pii}, "database_query_data": send_default_pii, "queues": send_default_pii, - "stack_frame_variables": include_local_variables, - "frame_context_lines": ( - _DEFAULT_FRAME_CONTEXT_LINES if include_source_context else 0 - ), + "stack_frame_variables": True, + "frame_context_lines": (_DEFAULT_FRAME_CONTEXT_LINES), } @@ -287,9 +280,8 @@ def _resolve_data_collection(options: "Dict[str, Any]") -> "DataCollection": """ Resolve the effective ``DataCollection`` dict from client ``options``. - Reads ``data_collection``, ``send_default_pii``, ``include_local_variables`` - and ``include_source_context`` and returns a fully-resolved dict with - concrete values for every field. + Reads ``data_collection``, ``send_default_pii`` and returns a fully-resolved + dict with concrete values for every field. ``data_collection`` must be a plain ``dict``. @@ -305,17 +297,6 @@ def _resolve_data_collection(options: "Dict[str, Any]") -> "DataCollection": send_default_pii = options.get("send_default_pii") - include_local_variables = ( - bool(options.get("include_local_variables")) - if options.get("include_local_variables") is not None - else True - ) - include_source_context = ( - bool(options.get("include_source_context")) - if options.get("include_source_context") is not None - else True - ) - if user_dc is not None: if not isinstance(user_dc, dict): raise TypeError( @@ -332,8 +313,4 @@ def _resolve_data_collection(options: "Dict[str, Any]") -> "DataCollection": user_dc, ) - return _map_from_send_default_pii( - send_default_pii=bool(send_default_pii), - include_local_variables=include_local_variables, - include_source_context=include_source_context, - ) + return _map_from_send_default_pii(send_default_pii=bool(send_default_pii)) diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py index e272787888..787cdbd1f2 100644 --- a/sentry_sdk/integrations/logging.py +++ b/sentry_sdk/integrations/logging.py @@ -303,9 +303,6 @@ def _emit(self, record: "LogRecord") -> None: "values": [ { "stacktrace": current_stacktrace( - include_local_variables=client_options[ - "include_local_variables" - ], max_value_length=client_options["max_value_length"], ), "crashed": False, diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 37b12f36dc..acdc06bd63 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -589,8 +589,6 @@ def filename_for_module( def serialize_frame( frame: "FrameType", tb_lineno: "Optional[int]" = None, - include_local_variables: bool = True, - include_source_context: bool = True, max_value_length: "Optional[int]" = None, custom_repr: "Optional[Callable[..., Optional[str]]]" = None, ) -> "Dict[str, Any]": @@ -624,21 +622,15 @@ def serialize_frame( "lineno": tb_lineno, } - client_options = sentry_sdk.get_client().options - if has_data_collection_enabled(client_options): - include_source_context = bool( - client_options["data_collection"]["frame_context_lines"] - ) + data_collection = sentry_sdk.get_client().options["data_collection"] + include_source_context = bool(data_collection["frame_context_lines"]) if include_source_context: rv["pre_context"], rv["context_line"], rv["post_context"] = get_source_context( frame, tb_lineno, max_value_length ) - if has_data_collection_enabled(client_options): - dc_stack_frame_vars_config = client_options["data_collection"][ - "stack_frame_variables" - ] + dc_stack_frame_vars_config = data_collection["stack_frame_variables"] if isinstance(dc_stack_frame_vars_config, bool): if dc_stack_frame_vars_config: @@ -658,19 +650,10 @@ def serialize_frame( rv["vars"] = serialized_variables - elif include_local_variables: - rv["vars"] = serialize( - dict(frame.f_locals), is_vars=True, custom_repr=custom_repr - ) - return rv -def current_stacktrace( - include_local_variables: bool = True, - include_source_context: bool = True, - max_value_length: "Optional[int]" = None, -) -> "Dict[str, Any]": +def current_stacktrace(max_value_length: "Optional[int]" = None) -> "Dict[str, Any]": __tracebackhide__ = True frames = [] @@ -680,8 +663,6 @@ def current_stacktrace( frames.append( serialize_frame( f, - include_local_variables=include_local_variables, - include_source_context=include_source_context, max_value_length=max_value_length, ) ) @@ -770,13 +751,9 @@ def single_exception_from_error_tuple( exception_value["value"] = get_error_message(exc_value) if client_options is None: - include_local_variables = True - include_source_context = True max_value_length = None # fallback custom_repr = None else: - include_local_variables = client_options["include_local_variables"] - include_source_context = client_options["include_source_context"] max_value_length = client_options["max_value_length"] custom_repr = client_options.get("custom_repr") @@ -784,8 +761,6 @@ def single_exception_from_error_tuple( serialize_frame( tb.tb_frame, tb_lineno=tb.tb_lineno, - include_local_variables=include_local_variables, - include_source_context=include_source_context, max_value_length=max_value_length, custom_repr=custom_repr, ) @@ -1176,7 +1151,6 @@ def event_from_exception( if client_options and client_options.get("add_full_stack", DEFAULT_ADD_FULL_STACK): full_stack = current_stacktrace( - include_local_variables=client_options["include_local_variables"], max_value_length=client_options["max_value_length"], )["frames"] else: diff --git a/tests/integrations/pure_eval/test_pure_eval.py b/tests/integrations/pure_eval/test_pure_eval.py index 057960693c..2c81295503 100644 --- a/tests/integrations/pure_eval/test_pure_eval.py +++ b/tests/integrations/pure_eval/test_pure_eval.py @@ -7,7 +7,7 @@ @pytest.mark.parametrize("integrations", [[], [PureEvalIntegration()]]) -def test_include_local_variables_enabled(sentry_init, capture_events, integrations): +def test_stack_frame_variables_enabled(sentry_init, capture_events, integrations): sentry_init( data_collection={"stack_frame_variables": True}, integrations=integrations ) diff --git a/tests/test_client.py b/tests/test_client.py index 09f6a5e2d5..11d0f409ce 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -411,8 +411,8 @@ def e(exc): assert events[0]["exception"]["values"][0]["type"] == "ValueError" -def test_include_local_variables_enabled(sentry_init, capture_events): - sentry_init(include_local_variables=True) +def test_stack_frame_variables_enabled(sentry_init, capture_events): + sentry_init(data_collection={"stack_frame_variables": True}) events = capture_events() try: 1 / 0 @@ -427,8 +427,8 @@ def test_include_local_variables_enabled(sentry_init, capture_events): ) -def test_include_local_variables_disabled(sentry_init, capture_events): - sentry_init(include_local_variables=False) +def test_stack_frame_variables_disabled(sentry_init, capture_events): + sentry_init(data_collection={"stack_frame_variables": False}) events = capture_events() try: 1 / 0 @@ -443,8 +443,8 @@ def test_include_local_variables_disabled(sentry_init, capture_events): ) -def test_include_source_context_enabled(sentry_init, capture_events): - sentry_init(include_source_context=True) +def test_frame_source_context_enabled(sentry_init, capture_events): + sentry_init(data_collection={"frame_context_lines": 5}) events = capture_events() try: 1 / 0 @@ -459,8 +459,8 @@ def test_include_source_context_enabled(sentry_init, capture_events): assert "context_line" in frame -def test_include_source_context_disabled(sentry_init, capture_events): - sentry_init(include_source_context=False) +def test_frame_source_context_disabled(sentry_init, capture_events): + sentry_init(data_collection={"frame_context_lines": False}) events = capture_events() try: 1 / 0 @@ -542,8 +542,10 @@ def bar(): assert functions[-2:] == ["foo", "bar"] -def test_attach_stacktrace_enabled_no_locals(sentry_init, capture_events): - sentry_init(attach_stacktrace=True, include_local_variables=False) +def test_attach_stacktrace_enabled_no_stack_trace_vars(sentry_init, capture_events): + sentry_init( + attach_stacktrace=True, data_collection={"stack_frame_variables": False} + ) events = capture_events() def foo(): diff --git a/tests/test_data_collection.py b/tests/test_data_collection.py index ff1eed11e0..fa8b04a571 100644 --- a/tests/test_data_collection.py +++ b/tests/test_data_collection.py @@ -151,15 +151,6 @@ def _get(dc, path): }, id="explicit_partial_fills_omitted_with_spec_defaults", ), - pytest.param( - { - "data_collection": {}, - "include_local_variables": False, - "include_source_context": False, - }, - {"stack_frame_variables": True, "frame_context_lines": 5}, - id="explicit_data_collection_ignores_legacy_include_local_variables", - ), pytest.param( { "data_collection": { @@ -311,16 +302,6 @@ def _get(dc, path): {"frame_context_lines": 5}, id="frame_context_lines_none_falls_back_to_spec_default", ), - pytest.param( - {"include_local_variables": False, "include_source_context": False}, - {"stack_frame_variables": False, "frame_context_lines": 0}, - id="legacy_include_local_variables_off_disables_stack_frame_variables", - ), - pytest.param( - {"include_local_variables": True, "include_source_context": True}, - {"stack_frame_variables": True, "frame_context_lines": 5}, - id="legacy_include_local_variables_on_enables_stack_frame_variables", - ), ], ) def test_initialize_client_data_collection(sentry_init, options, expected): diff --git a/tests/test_exceptiongroup.py b/tests/test_exceptiongroup.py index ae476f9c33..ea777feefa 100644 --- a/tests/test_exceptiongroup.py +++ b/tests/test_exceptiongroup.py @@ -45,8 +45,6 @@ def test_exceptiongroup(): (event, _) = event_from_exception( exception_group, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -161,8 +159,6 @@ def test_exceptiongroup_simple(): (event, _) = event_from_exception( exception_group, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -206,8 +202,6 @@ def test_exception_chain_cause(): (event, _) = event_from_exception( exception_chain_cause, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -250,8 +244,6 @@ def test_exception_chain_context(): (event, _) = event_from_exception( exception_chain_context, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -293,8 +285,6 @@ def test_simple_exception(): (event, _) = event_from_exception( simple_excpetion, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -342,8 +332,6 @@ def test_exception_group_chained_with_context(): (event, _) = event_from_exception( exc, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -445,8 +433,6 @@ def test_exceptiongroup_starlette_collapse(): (event, _) = event_from_exception( exception_group, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -516,8 +502,6 @@ def test_cyclic_exception_group_cause(): (event, _) = event_from_exception( group, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, @@ -554,8 +538,6 @@ def test_deeply_nested_cyclic_exception_group(): (event, _) = event_from_exception( outer_group, client_options={ - "include_local_variables": True, - "include_source_context": True, "max_value_length": 1024, }, mechanism={"type": "test_suite", "handled": False}, diff --git a/tests/test_utils.py b/tests/test_utils.py index 7f740f299e..75e9925c86 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -478,44 +478,6 @@ def test_warns_on_invalid_sample_rate(rate, StringContaining): # noqa: N803 assert result is False -@pytest.mark.parametrize( - "options,include_source_context,expected_source_context", - [ - pytest.param({}, True, True, id="no_data_collection-include_true"), - pytest.param({}, False, False, id="no_data_collection-include_false"), - pytest.param( - {"data_collection": {}}, - False, - True, - id="data_collection-spec_default_overrides_include_false", - ), - pytest.param( - {"data_collection": {"frame_context_lines": 3}}, - True, - True, - id="data_collection-frame_context_lines_3", - ), - pytest.param( - {"data_collection": {"frame_context_lines": 0}}, - True, - False, - id="data_collection-frame_context_lines_0_overrides_include_true", - ), - ], -) -def test_include_source_context_when_serializing_frame( - sentry_init, options, include_source_context, expected_source_context -): - sentry_init(**options) - - frame = sys._getframe() - result = serialize_frame(frame, include_source_context=include_source_context) - - assert ("pre_context" in result) is expected_source_context - assert ("context_line" in result) is expected_source_context - assert ("post_context" in result) is expected_source_context - - def _frame_with_locals(): safe_value = "not sensitive" # noqa: F841 password = "ada123" # noqa: F841 @@ -525,36 +487,31 @@ def _frame_with_locals(): @pytest.mark.parametrize( - "data_collection,include_local_variables,expected_vars", + "data_collection,expected_vars", [ pytest.param( {"stack_frame_variables": True}, - False, True, - id="data_collection_stack_frame_variables_true_overrides_include_false", + id="data_collection_stack_frame_variables_true", ), pytest.param( {"stack_frame_variables": False}, - True, False, - id="data_collection_stack_frame_variables_false_overrides_include_true", + id="data_collection_stack_frame_variables_false", ), pytest.param( {}, - False, True, id="data_collection_stack_frame_variables_spec_default_is_true", ), ], ) def test_stack_frame_variables_bool_when_serializing_frame( - sentry_init, data_collection, include_local_variables, expected_vars + sentry_init, data_collection, expected_vars ): sentry_init(data_collection=data_collection) - result = serialize_frame( - _frame_with_locals(), include_local_variables=include_local_variables - ) + result = serialize_frame(_frame_with_locals()) assert ("vars" in result) is expected_vars @@ -654,58 +611,6 @@ def custom_repr(value): assert result["vars"]["password"] == "'[Filtered]'" -@pytest.mark.parametrize( - "options,include_local_variables,expected_vars", - [ - pytest.param( - {}, - True, - True, - id="no_data_collection-include_local_variables_true", - ), - pytest.param( - {}, - False, - False, - id="no_data_collection-include_local_variables_false", - ), - ], -) -def test_include_local_variables_when_data_collection_is_unset( - sentry_init, options, include_local_variables, expected_vars -): - sentry_init(**options) - - result = serialize_frame( - _frame_with_locals(), include_local_variables=include_local_variables - ) - - assert ("vars" in result) is expected_vars - - -def test_data_collection_stack_frame_variables_overrides_include_local_variables_option( - sentry_init, capture_events -): - sentry_init( - include_local_variables=False, - data_collection={"stack_frame_variables": True}, - ) - events = capture_events() - - def raise_with_locals(): - safe_value = "not sensitive" # noqa: F841 - raise ValueError("boom") - - try: - raise_with_locals() - except ValueError: - sentry_sdk.capture_exception() - - (event,) = events - frame = event["exception"]["values"][0]["stacktrace"]["frames"][-1] - assert frame["vars"]["safe_value"] == "'not sensitive'" - - def test_data_collection_stack_frame_variables_filtering_applies_to_captured_exception( sentry_init, capture_events ): @@ -1335,14 +1240,6 @@ def fake_getlines(filename): 0, id="data_collection-frame_context_lines_0", ), - pytest.param( - { - "data_collection": {}, - "include_source_context": False, - }, - 5, - id="data_collection-spec_default_overrides_include_source_context_false", - ), ], ) def test_get_lines_from_file_frame_context_lines( From deb4abb96e29aa2e7d517a9c1d76f5c86c6422b4 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 6 Oct 2026 08:25:25 +0200 Subject: [PATCH 2/4] init sdk to init data collection --- tests/test_exceptiongroup.py | 12 ++++++++---- tests/test_transport.py | 15 ++++++++++----- tests/utils/test_general.py | 3 ++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/test_exceptiongroup.py b/tests/test_exceptiongroup.py index ea777feefa..18d3aac3c3 100644 --- a/tests/test_exceptiongroup.py +++ b/tests/test_exceptiongroup.py @@ -18,7 +18,8 @@ @minimum_python_311 -def test_exceptiongroup(): +def test_exceptiongroup(sentry_init): + sentry_init() exception_group = None try: @@ -143,7 +144,8 @@ def test_exceptiongroup(): @minimum_python_311 -def test_exceptiongroup_simple(): +def test_exceptiongroup_simple(sentry_init): + sentry_init() exception_group = None try: @@ -308,7 +310,8 @@ def test_simple_exception(): @minimum_python_311 -def test_exception_group_chained_with_context(): +def test_exception_group_chained_with_context(sentry_init): + sentry_init() try: try: raise ExceptionGroup( @@ -390,7 +393,7 @@ def test_exception_group_chained_with_context(): @minimum_python_311 -def test_exceptiongroup_starlette_collapse(): +def test_exceptiongroup_starlette_collapse(sentry_init): """ Simulates the Starlette collapse_excgroups() pattern where a single-exception ExceptionGroup is caught and the inner exception is unwrapped and re-raised. @@ -410,6 +413,7 @@ def test_exceptiongroup_starlette_collapse(): Without cycle detection in exceptions_from_error(), this causes infinite recursion and a silent RecursionError that drops the event. """ + sentry_init() exception_group = None try: diff --git a/tests/test_transport.py b/tests/test_transport.py index a21ff3b1e2..2ae25458ce 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -456,7 +456,8 @@ def test_parse_rate_limits(input, expected): assert dict(_parse_rate_limits(input, now=NOW)) == expected -def test_envelope_too_large_response(capturing_server, make_client): +def test_envelope_too_large_response(sentry_init, capturing_server, make_client): + sentry_init() client = make_client() capturing_server.respond_with(code=413) @@ -476,7 +477,8 @@ def test_envelope_too_large_response(capturing_server, make_client): capturing_server.clear_captured() -def test_simple_rate_limits(capturing_server, make_client): +def test_simple_rate_limits(sentry_init, capturing_server, make_client): + sentry_init() client = make_client() capturing_server.respond_with(code=429, headers={"Retry-After": "4"}) @@ -498,8 +500,9 @@ def test_simple_rate_limits(capturing_server, make_client): @pytest.mark.parametrize("response_code", [200, 429]) def test_data_category_limits( - capturing_server, response_code, make_client, monkeypatch + sentry_init, capturing_server, response_code, make_client, monkeypatch ): + sentry_init() client = make_client(send_client_reports=False) captured_outcomes = [] @@ -557,8 +560,9 @@ def record_lost_event(reason, data_category=None, item=None): @pytest.mark.parametrize("response_code", [200, 429]) def test_data_category_limits_reporting( - capturing_server, response_code, make_client, monkeypatch + sentry_init, capturing_server, response_code, make_client, monkeypatch ): + sentry_init() client = make_client(send_client_reports=True) capturing_server.respond_with( @@ -671,8 +675,9 @@ def intercepting_fetch(*args, **kwargs): @pytest.mark.parametrize("response_code", [200, 429]) def test_complex_limits_without_data_category( - capturing_server, response_code, make_client + sentry_init, capturing_server, response_code, make_client ): + sentry_init() client = make_client() capturing_server.respond_with( code=response_code, diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index ed0df8b3b5..d518717729 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -52,10 +52,11 @@ def test_safe_repr_non_printable(prefix, character): assert character not in safe_repr(string.encode("utf-8")) -def test_abs_path(): +def test_abs_path(sentry_init): """Check if abs_path is actually an absolute path. This can happen either with eval/exec like here, or when the file in the frame is relative to __main__""" + sentry_init() code = compile("1/0", "test.py", "exec") try: From b708f7f170bf1ef454f4f170253fe0a13a67f886 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 6 Oct 2026 09:24:27 +0200 Subject: [PATCH 3/4] format fix --- sentry_sdk/data_collection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/data_collection.py b/sentry_sdk/data_collection.py index a7511c1a1a..fbac357a18 100644 --- a/sentry_sdk/data_collection.py +++ b/sentry_sdk/data_collection.py @@ -175,7 +175,7 @@ def _map_from_send_default_pii(*, send_default_pii: bool) -> "DataCollection": "database_query_data": send_default_pii, "queues": send_default_pii, "stack_frame_variables": True, - "frame_context_lines": (_DEFAULT_FRAME_CONTEXT_LINES), + "frame_context_lines": _DEFAULT_FRAME_CONTEXT_LINES, } From 1cd0cab5ee799f9ec1cd77829c82a9abdcc1698d Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 6 Oct 2026 10:39:35 +0200 Subject: [PATCH 4/4] ref: Remove client_options from event_from_exception --- sentry_sdk/integrations/aiohttp.py | 1 - sentry_sdk/integrations/anthropic.py | 1 - sentry_sdk/integrations/ariadne.py | 2 -- sentry_sdk/integrations/arq.py | 1 - sentry_sdk/integrations/asgi.py | 1 - sentry_sdk/integrations/asyncio.py | 1 - sentry_sdk/integrations/aws_lambda.py | 4 --- sentry_sdk/integrations/beam.py | 3 --- sentry_sdk/integrations/bottle.py | 1 - sentry_sdk/integrations/celery/__init__.py | 1 - sentry_sdk/integrations/chalice.py | 2 -- sentry_sdk/integrations/cohere.py | 1 - sentry_sdk/integrations/django/__init__.py | 1 - sentry_sdk/integrations/dramatiq.py | 1 - sentry_sdk/integrations/excepthook.py | 1 - sentry_sdk/integrations/falcon.py | 1 - sentry_sdk/integrations/flask.py | 1 - sentry_sdk/integrations/gcp.py | 1 - sentry_sdk/integrations/google_genai/utils.py | 1 - sentry_sdk/integrations/gql.py | 1 - sentry_sdk/integrations/graphene.py | 4 --- sentry_sdk/integrations/huey.py | 1 - sentry_sdk/integrations/huggingface_hub.py | 1 - sentry_sdk/integrations/langchain.py | 1 - sentry_sdk/integrations/litellm.py | 1 - sentry_sdk/integrations/litestar.py | 1 - sentry_sdk/integrations/logging.py | 1 - sentry_sdk/integrations/mcp.py | 1 - sentry_sdk/integrations/openai.py | 1 - .../integrations/openai_agents/utils.py | 1 - sentry_sdk/integrations/otlp.py | 1 - sentry_sdk/integrations/pydantic_ai/utils.py | 1 - sentry_sdk/integrations/pyramid.py | 1 - sentry_sdk/integrations/quart.py | 1 - sentry_sdk/integrations/ray.py | 3 --- sentry_sdk/integrations/rq.py | 3 --- sentry_sdk/integrations/sanic.py | 1 - sentry_sdk/integrations/serverless.py | 1 - sentry_sdk/integrations/starlette.py | 1 - sentry_sdk/integrations/starlite.py | 1 - sentry_sdk/integrations/strawberry.py | 1 - sentry_sdk/integrations/sys_exit.py | 1 - sentry_sdk/integrations/threading.py | 1 - sentry_sdk/integrations/tornado.py | 1 - sentry_sdk/integrations/trytond.py | 2 -- sentry_sdk/integrations/typer.py | 1 - sentry_sdk/integrations/unraisablehook.py | 1 - sentry_sdk/integrations/wsgi.py | 1 - sentry_sdk/scope.py | 4 +-- sentry_sdk/utils.py | 6 ++--- tests/test_exceptiongroup.py | 27 ------------------- 51 files changed, 3 insertions(+), 97 deletions(-) diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index 64729ccd4a..3db71388b7 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -503,7 +503,6 @@ def _capture_exception() -> "ExcInfo": exc_info = sys.exc_info() event, hint = event_from_exception( exc_info, - client_options=sentry_sdk.get_client().options, mechanism={"type": "aiohttp", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 40f439f36e..79c47a571c 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -266,7 +266,6 @@ def setup_once() -> None: def _capture_exception(exc: "Any") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "anthropic", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/ariadne.py b/sentry_sdk/integrations/ariadne.py index e52ca76505..1214ba434a 100644 --- a/sentry_sdk/integrations/ariadne.py +++ b/sentry_sdk/integrations/ariadne.py @@ -80,7 +80,6 @@ def _sentry_patched_handle_graphql_errors( for error in errors: event, hint = event_from_exception( error, - client_options=client.options, mechanism={ "type": AriadneIntegration.identifier, "handled": False, @@ -105,7 +104,6 @@ def _sentry_patched_handle_query_result( for error in result.errors or []: event, hint = event_from_exception( error, - client_options=client.options, mechanism={ "type": AriadneIntegration.identifier, "handled": False, diff --git a/sentry_sdk/integrations/arq.py b/sentry_sdk/integrations/arq.py index 295c3eff0e..5cdbf9892d 100644 --- a/sentry_sdk/integrations/arq.py +++ b/sentry_sdk/integrations/arq.py @@ -127,7 +127,6 @@ def _capture_exception(exc_info: "ExcInfo") -> None: event, hint = event_from_exception( exc_info, - client_options=sentry_sdk.get_client().options, mechanism={"type": ArqIntegration.identifier, "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 33a7f0ed43..3880fee875 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -64,7 +64,6 @@ def _capture_exception(exc: "Any", mechanism_type: str = "asgi") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": mechanism_type, "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py index 2443808f23..e4a5b174e8 100644 --- a/sentry_sdk/integrations/asyncio.py +++ b/sentry_sdk/integrations/asyncio.py @@ -202,7 +202,6 @@ def _capture_exception() -> "ExcInfo": if integration is not None: event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "asyncio", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 8f2676ff52..9bd174d01d 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -65,8 +65,6 @@ def _get_user_from_event(aws_event: "dict[str, Any]") -> "dict[str, Any]": def _wrap_init_error(init_error: "F") -> "F": @ensure_integration_enabled(AwsLambdaIntegration, init_error) def sentry_init_error(*args: "Any", **kwargs: "Any") -> "Any": - client = sentry_sdk.get_client() - with capture_internal_exceptions(): sentry_sdk.get_isolation_scope().clear_breadcrumbs() @@ -74,7 +72,6 @@ def sentry_init_error(*args: "Any", **kwargs: "Any") -> "Any": if exc_info and all(exc_info): sentry_event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "aws_lambda", "handled": False}, ) sentry_sdk.capture_event(sentry_event, hint=hint) @@ -231,7 +228,6 @@ def sentry_handler( exc_info = sys.exc_info() sentry_event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "aws_lambda", "handled": False}, ) sentry_sdk.capture_event(sentry_event, hint=hint) diff --git a/sentry_sdk/integrations/beam.py b/sentry_sdk/integrations/beam.py index 4bce445075..48e76ce239 100644 --- a/sentry_sdk/integrations/beam.py +++ b/sentry_sdk/integrations/beam.py @@ -136,11 +136,8 @@ def _capture_exception(exc_info: "ExcInfo") -> None: """ Send Beam exception to Sentry. """ - client = sentry_sdk.get_client() - event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "beam", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/bottle.py b/sentry_sdk/integrations/bottle.py index 9868c87227..4e23dabbc2 100644 --- a/sentry_sdk/integrations/bottle.py +++ b/sentry_sdk/integrations/bottle.py @@ -208,7 +208,6 @@ def event_processor(event: "Event", hint: "dict[str, Any]") -> "Event": def _capture_exception(exception: BaseException, handled: bool) -> None: event, hint = event_from_exception( exception, - client_options=sentry_sdk.get_client().options, mechanism={"type": "bottle", "handled": handled}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 0338a8499e..4e2be4d808 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -115,7 +115,6 @@ def _capture_exception(task: "Any", exc_info: "ExcInfo") -> None: event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "celery", "handled": False}, ) diff --git a/sentry_sdk/integrations/chalice.py b/sentry_sdk/integrations/chalice.py index 57e6e06f46..3916f182bf 100644 --- a/sentry_sdk/integrations/chalice.py +++ b/sentry_sdk/integrations/chalice.py @@ -52,7 +52,6 @@ def __call__(self, event: "Any", context: "Any") -> "Any": exc_info = sys.exc_info() event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "chalice", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) @@ -120,7 +119,6 @@ def wrapped_view_function(**function_args: "Any") -> "Any": segment.status = SpanStatus.ERROR.value sentry_event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "chalice", "handled": False}, ) sentry_sdk.capture_event(sentry_event, hint=hint) diff --git a/sentry_sdk/integrations/cohere.py b/sentry_sdk/integrations/cohere.py index 6cbbe9d4fb..64e7f19157 100644 --- a/sentry_sdk/integrations/cohere.py +++ b/sentry_sdk/integrations/cohere.py @@ -91,7 +91,6 @@ def setup_once() -> None: def _capture_exception(exc: "Any") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "cohere", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index d336c2ea2c..a5ca77759e 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -593,7 +593,6 @@ def _capture_exception( event, hint = event_from_exception( exc_info, - client_options=sentry_sdk.get_client().options, mechanism={"type": "django", "handled": handled}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/dramatiq.py b/sentry_sdk/integrations/dramatiq.py index 615fb18668..07c8130172 100644 --- a/sentry_sdk/integrations/dramatiq.py +++ b/sentry_sdk/integrations/dramatiq.py @@ -183,7 +183,6 @@ def after_process_message( event, hint = event_from_exception( exception, # type: ignore[arg-type] - client_options=sentry_sdk.get_client().options, mechanism={ "type": DramatiqIntegration.identifier, "handled": False, diff --git a/sentry_sdk/integrations/excepthook.py b/sentry_sdk/integrations/excepthook.py index 6bbc61000d..9d7d6cf63e 100644 --- a/sentry_sdk/integrations/excepthook.py +++ b/sentry_sdk/integrations/excepthook.py @@ -54,7 +54,6 @@ def sentry_sdk_excepthook( with capture_internal_exceptions(): event, hint = event_from_exception( (type_, value, traceback), - client_options=sentry_sdk.get_client().options, mechanism={"type": "excepthook", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/falcon.py b/sentry_sdk/integrations/falcon.py index 5ee687ea9b..4383530fe7 100644 --- a/sentry_sdk/integrations/falcon.py +++ b/sentry_sdk/integrations/falcon.py @@ -163,7 +163,6 @@ def sentry_patched_handle_exception(self: "falcon.API", *args: "Any") -> "Any": if _exception_leads_to_http_5xx(ex, response): event, hint = event_from_exception( ex, - client_options=sentry_sdk.get_client().options, mechanism={"type": "falcon", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index be1f958548..3fddff2d3c 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -212,7 +212,6 @@ def _capture_exception( ) -> None: event, hint = event_from_exception( exception, - client_options=sentry_sdk.get_client().options, mechanism={"type": "flask", "handled": False}, ) diff --git a/sentry_sdk/integrations/gcp.py b/sentry_sdk/integrations/gcp.py index 6e6883e7df..c9271cfa45 100644 --- a/sentry_sdk/integrations/gcp.py +++ b/sentry_sdk/integrations/gcp.py @@ -150,7 +150,6 @@ def sentry_func( exc_info = sys.exc_info() sentry_event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "gcp", "handled": False}, ) sentry_sdk.capture_event(sentry_event, hint=hint) diff --git a/sentry_sdk/integrations/google_genai/utils.py b/sentry_sdk/integrations/google_genai/utils.py index 560b3748c7..c9cb1e3f51 100644 --- a/sentry_sdk/integrations/google_genai/utils.py +++ b/sentry_sdk/integrations/google_genai/utils.py @@ -153,7 +153,6 @@ def _capture_exception(exc: "Any") -> None: """Capture exception with Google GenAI mechanism.""" event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "google_genai", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/gql.py b/sentry_sdk/integrations/gql.py index 10112a6951..6913c23a23 100644 --- a/sentry_sdk/integrations/gql.py +++ b/sentry_sdk/integrations/gql.py @@ -122,7 +122,6 @@ def sentry_patched_execute( except TransportQueryError as e: event, hint = event_from_exception( e, - client_options=sentry_sdk.get_client().options, mechanism={"type": "gql", "handled": False}, ) diff --git a/sentry_sdk/integrations/graphene.py b/sentry_sdk/integrations/graphene.py index 86bf930ea9..acf205f9e2 100644 --- a/sentry_sdk/integrations/graphene.py +++ b/sentry_sdk/integrations/graphene.py @@ -58,11 +58,9 @@ def _sentry_patched_graphql_sync( result = old_graphql_sync(schema, source, *args, **kwargs) with capture_internal_exceptions(): - client = sentry_sdk.get_client() for error in result.errors or []: event, hint = event_from_exception( error, - client_options=client.options, mechanism={ "type": GrapheneIntegration.identifier, "handled": False, @@ -89,11 +87,9 @@ async def _sentry_patched_graphql_async( result = await old_graphql_async(schema, source, *args, **kwargs) with capture_internal_exceptions(): - client = sentry_sdk.get_client() for error in result.errors or []: event, hint = event_from_exception( error, - client_options=client.options, mechanism={ "type": GrapheneIntegration.identifier, "handled": False, diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index 409fad491c..d36b0566e1 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -152,7 +152,6 @@ def _capture_exception(exc_info: "ExcInfo") -> None: event, hint = event_from_exception( exc_info, - client_options=sentry_sdk.get_client().options, mechanism={"type": HueyIntegration.identifier, "handled": False}, ) scope.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/huggingface_hub.py b/sentry_sdk/integrations/huggingface_hub.py index bb5b1df186..64c134c13f 100644 --- a/sentry_sdk/integrations/huggingface_hub.py +++ b/sentry_sdk/integrations/huggingface_hub.py @@ -57,7 +57,6 @@ def setup_once() -> None: def _capture_exception(exc: "Any") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "huggingface_hub", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 486d554a7b..b3623659c2 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -180,7 +180,6 @@ def setup_once() -> None: def _capture_exception(exc: "Any", scope: "Optional[Any]" = None) -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "langchain", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint, scope=scope) diff --git a/sentry_sdk/integrations/litellm.py b/sentry_sdk/integrations/litellm.py index de058f34f3..63e491ddee 100644 --- a/sentry_sdk/integrations/litellm.py +++ b/sentry_sdk/integrations/litellm.py @@ -263,7 +263,6 @@ def _failure_callback( # Capture the exception event, hint = event_from_exception( exception, - client_options=sentry_sdk.get_client().options, mechanism={"type": "litellm", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/litestar.py b/sentry_sdk/integrations/litestar.py index fe94b51760..cc0e8e1efc 100644 --- a/sentry_sdk/integrations/litestar.py +++ b/sentry_sdk/integrations/litestar.py @@ -335,7 +335,6 @@ def exception_handler(exc: Exception, scope: "LitestarScope") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": LitestarIntegration.identifier, "handled": False}, ) diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py index 787cdbd1f2..d505c33517 100644 --- a/sentry_sdk/integrations/logging.py +++ b/sentry_sdk/integrations/logging.py @@ -292,7 +292,6 @@ def _emit(self, record: "LogRecord") -> None: if record.exc_info and record.exc_info[0] is not None: event, hint = event_from_exception( record.exc_info, - client_options=client_options, mechanism={"type": "logging", "handled": True}, ) elif (record.exc_info and record.exc_info[0] is None) or record.stack_info: diff --git a/sentry_sdk/integrations/mcp.py b/sentry_sdk/integrations/mcp.py index 69c75f3a5b..351ddda514 100644 --- a/sentry_sdk/integrations/mcp.py +++ b/sentry_sdk/integrations/mcp.py @@ -65,7 +65,6 @@ def setup_once() -> None: def _capture_exception(exc: "Any") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "mcp", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index e09203e46f..83dea90c07 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -153,7 +153,6 @@ def count_tokens(self: "OpenAIIntegration", s: str) -> int: def _capture_exception(exc: "Any") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "openai", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/openai_agents/utils.py b/sentry_sdk/integrations/openai_agents/utils.py index 5253573faa..9a241618b3 100644 --- a/sentry_sdk/integrations/openai_agents/utils.py +++ b/sentry_sdk/integrations/openai_agents/utils.py @@ -31,7 +31,6 @@ def _capture_exception(exc: "Any") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "openai_agents", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/otlp.py b/sentry_sdk/integrations/otlp.py index ed1658d156..bbf3ffb9cf 100644 --- a/sentry_sdk/integrations/otlp.py +++ b/sentry_sdk/integrations/otlp.py @@ -120,7 +120,6 @@ def _sentry_patched_record_exception( with capture_internal_exceptions(): event, hint = event_from_exception( exception, - client_options=get_client().options, mechanism={"type": OTLPIntegration.identifier, "handled": False}, ) capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/pydantic_ai/utils.py b/sentry_sdk/integrations/pydantic_ai/utils.py index af3d449029..837c16a171 100644 --- a/sentry_sdk/integrations/pydantic_ai/utils.py +++ b/sentry_sdk/integrations/pydantic_ai/utils.py @@ -99,7 +99,6 @@ def _set_available_tools(span: "Span", agent: "Optional[Agent[Any, Any]]") -> No def _capture_exception(exc: "Any", handled: bool = False) -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": "pydantic_ai", "handled": handled}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index a7e5f60734..8231e1fb94 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -146,7 +146,6 @@ def _capture_exception(exc_info: "ExcInfo") -> None: event, hint = event_from_exception( exc_info, - client_options=sentry_sdk.get_client().options, mechanism={"type": "pyramid", "handled": False}, ) diff --git a/sentry_sdk/integrations/quart.py b/sentry_sdk/integrations/quart.py index 22b5cd5416..7230f619c6 100644 --- a/sentry_sdk/integrations/quart.py +++ b/sentry_sdk/integrations/quart.py @@ -249,7 +249,6 @@ async def _capture_exception( event, hint = event_from_exception( exception, - client_options=sentry_sdk.get_client().options, mechanism={"type": "quart", "handled": False}, ) diff --git a/sentry_sdk/integrations/ray.py b/sentry_sdk/integrations/ray.py index b7029685c3..108a90dfc9 100644 --- a/sentry_sdk/integrations/ray.py +++ b/sentry_sdk/integrations/ray.py @@ -177,11 +177,8 @@ def _remote_method_with_header_propagation( def _capture_exception(exc_info: "ExcInfo", **kwargs: "Any") -> None: - client = sentry_sdk.get_client() - event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={ "handled": False, "type": RayIntegration.identifier, diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index 1b49f64c61..c656c19cf0 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -181,11 +181,8 @@ def event_processor(event: "Event", hint: "dict[str, Any]") -> "Event": def _capture_exception(exc_info: "ExcInfo", **kwargs: "Any") -> None: - client = sentry_sdk.get_client() - event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "rq", "handled": False}, ) diff --git a/sentry_sdk/integrations/sanic.py b/sentry_sdk/integrations/sanic.py index a0279e9be4..8fd0f7cc35 100644 --- a/sentry_sdk/integrations/sanic.py +++ b/sentry_sdk/integrations/sanic.py @@ -241,7 +241,6 @@ def _capture_exception(exception: "Union[ExcInfo, BaseException]") -> None: with capture_internal_exceptions(): event, hint = event_from_exception( exception, - client_options=sentry_sdk.get_client().options, mechanism={"type": "sanic", "handled": False}, ) diff --git a/sentry_sdk/integrations/serverless.py b/sentry_sdk/integrations/serverless.py index 16f91b28ae..ce150fc9f6 100644 --- a/sentry_sdk/integrations/serverless.py +++ b/sentry_sdk/integrations/serverless.py @@ -57,7 +57,6 @@ def _capture_and_reraise() -> None: if client.is_active(): event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "serverless", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index 8f4ecdf22a..c55303478e 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -226,7 +226,6 @@ def _default(value: "Any") -> "Any": def _capture_exception(exception: BaseException, handled: "Any" = False) -> None: event, hint = event_from_exception( exception, - client_options=sentry_sdk.get_client().options, mechanism={"type": StarletteIntegration.identifier, "handled": handled}, ) diff --git a/sentry_sdk/integrations/starlite.py b/sentry_sdk/integrations/starlite.py index 54e0922876..584ff0a7e8 100644 --- a/sentry_sdk/integrations/starlite.py +++ b/sentry_sdk/integrations/starlite.py @@ -309,7 +309,6 @@ def exception_handler(exc: Exception, scope: "StarliteScope", _: "State") -> Non event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": StarliteIntegration.identifier, "handled": False}, ) diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index da3e2f0b63..76f4d8b111 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -344,7 +344,6 @@ def _sentry_patched_handle_errors( for error in errors: event, hint = event_from_exception( error, - client_options=sentry_sdk.get_client().options, mechanism={ "type": StrawberryIntegration.identifier, "handled": False, diff --git a/sentry_sdk/integrations/sys_exit.py b/sentry_sdk/integrations/sys_exit.py index 4927c0e885..55aacd909f 100644 --- a/sentry_sdk/integrations/sys_exit.py +++ b/sentry_sdk/integrations/sys_exit.py @@ -59,7 +59,6 @@ def sentry_patched_exit(__status: "Union[str, int, None]" = 0) -> "NoReturn": def _capture_exception(exc: "SystemExit") -> None: event, hint = event_from_exception( exc, - client_options=sentry_sdk.get_client().options, mechanism={"type": SysExitIntegration.identifier, "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/threading.py b/sentry_sdk/integrations/threading.py index 3c299deef0..49989232bd 100644 --- a/sentry_sdk/integrations/threading.py +++ b/sentry_sdk/integrations/threading.py @@ -172,7 +172,6 @@ def _capture_exception() -> "ExcInfo": if client.get_integration(ThreadingIntegration) is not None: event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "threading", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/tornado.py b/sentry_sdk/integrations/tornado.py index 369b1983cb..9c9ccf7e8f 100644 --- a/sentry_sdk/integrations/tornado.py +++ b/sentry_sdk/integrations/tornado.py @@ -226,7 +226,6 @@ def _capture_exception(ty: type, value: BaseException, tb: "Any") -> None: event, hint = event_from_exception( (ty, value, tb), - client_options=sentry_sdk.get_client().options, mechanism={"type": "tornado", "handled": False}, ) diff --git a/sentry_sdk/integrations/trytond.py b/sentry_sdk/integrations/trytond.py index 2c574d0fa0..2293dc226c 100644 --- a/sentry_sdk/integrations/trytond.py +++ b/sentry_sdk/integrations/trytond.py @@ -39,10 +39,8 @@ def error_handler(e: Exception) -> None: if isinstance(e, TrytonException): return else: - client = sentry_sdk.get_client() event, hint = event_from_exception( e, - client_options=client.options, mechanism={"type": "trytond", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/typer.py b/sentry_sdk/integrations/typer.py index 4b714b5d76..180cda8b7a 100644 --- a/sentry_sdk/integrations/typer.py +++ b/sentry_sdk/integrations/typer.py @@ -53,7 +53,6 @@ def sentry_sdk_excepthook( with capture_internal_exceptions(): event, hint = event_from_exception( (type_, value, traceback), - client_options=sentry_sdk.get_client().options, mechanism={"type": "typer", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/unraisablehook.py b/sentry_sdk/integrations/unraisablehook.py index 2c7280a1f2..6cadaeafdb 100644 --- a/sentry_sdk/integrations/unraisablehook.py +++ b/sentry_sdk/integrations/unraisablehook.py @@ -40,7 +40,6 @@ def sentry_sdk_unraisablehook(unraisable: "sys.UnraisableHookArgs") -> None: unraisable.exc_value, unraisable.exc_traceback, ), - client_options=sentry_sdk.get_client().options, mechanism={"type": "unraisablehook", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index 26825b190e..74336cba33 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -280,7 +280,6 @@ def _capture_exception() -> "ExcInfo": if not should_skip_capture: event, hint = event_from_exception( exc_info, - client_options=sentry_sdk.get_client().options, mechanism={"type": "wsgi", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 4a0fbcac28..d9afacbd0c 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -1243,9 +1243,7 @@ def capture_exception( else: exc_info = sys.exc_info() - event, hint = event_from_exception( - exc_info, client_options=self.get_client().options - ) + event, hint = event_from_exception(exc_info) try: return self.capture_event(event, hint=hint, scope=scope, **scope_kwargs) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index acdc06bd63..6f8142d942 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1143,13 +1143,13 @@ def merge_stack_frames( def event_from_exception( exc_info: "Union[BaseException, ExcInfo]", - client_options: "Optional[Dict[str, Any]]" = None, mechanism: "Optional[Dict[str, Any]]" = None, ) -> "Tuple[Event, Dict[str, Any]]": exc_info = exc_info_from_error(exc_info) hint = event_hint_with_exc_info(exc_info) + client_options = sentry_sdk.get_client().options - if client_options and client_options.get("add_full_stack", DEFAULT_ADD_FULL_STACK): + if client_options.get("add_full_stack", DEFAULT_ADD_FULL_STACK): full_stack = current_stacktrace( max_value_length=client_options["max_value_length"], )["frames"] @@ -1394,10 +1394,8 @@ def stop(self) -> None: def _capture_exception(self) -> "ExcInfo": exc_info = sys.exc_info() - client = sentry_sdk.get_client() event, hint = event_from_exception( exc_info, - client_options=client.options, mechanism={"type": "threading", "handled": False}, ) sentry_sdk.capture_event(event, hint=hint) diff --git a/tests/test_exceptiongroup.py b/tests/test_exceptiongroup.py index 18d3aac3c3..9926cbefc9 100644 --- a/tests/test_exceptiongroup.py +++ b/tests/test_exceptiongroup.py @@ -45,9 +45,6 @@ def test_exceptiongroup(sentry_init): (event, _) = event_from_exception( exception_group, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -160,9 +157,6 @@ def test_exceptiongroup_simple(sentry_init): (event, _) = event_from_exception( exception_group, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -203,9 +197,6 @@ def test_exception_chain_cause(): (event, _) = event_from_exception( exception_chain_cause, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -245,9 +236,6 @@ def test_exception_chain_context(): (event, _) = event_from_exception( exception_chain_context, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -286,9 +274,6 @@ def test_simple_exception(): (event, _) = event_from_exception( simple_excpetion, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -334,9 +319,6 @@ def test_exception_group_chained_with_context(sentry_init): (event, _) = event_from_exception( exc, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -436,9 +418,6 @@ def test_exceptiongroup_starlette_collapse(sentry_init): (event, _) = event_from_exception( exception_group, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -505,9 +484,6 @@ def test_cyclic_exception_group_cause(): # is called directly (not walk_exception_chain which has cycle detection). (event, _) = event_from_exception( group, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, ) @@ -541,9 +517,6 @@ def test_deeply_nested_cyclic_exception_group(): (event, _) = event_from_exception( outer_group, - client_options={ - "max_value_length": 1024, - }, mechanism={"type": "test_suite", "handled": False}, )