From ced7d5c0a99aa28b84bc29de0e2be0d3a2e87bb5 Mon Sep 17 00:00:00 2001 From: Aegis Dev Date: Sun, 31 May 2026 18:17:43 -0400 Subject: [PATCH] fix(client): guard against dotless qualified_name in _setup_instrumentation When a functions_to_trace entry's qualified_name contains no dot, the rsplit(".", 1) unpacking at line 510 raised ValueError outside the surrounding try/except, crashing sentry_sdk.init() entirely. Add an early check that skips the entry with a warning instead. Fixes #6451 --- sentry_sdk/client.py | 8 ++++++++ tests/test_basics.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 0f2ddfb640..07ac164e80 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -507,6 +507,14 @@ def _setup_instrumentation( for function in functions_to_trace: class_name = None function_qualname = function["qualified_name"] + + if "." not in function_qualname: + logger.warning( + "Can not enable tracing for '%s'. Please provide the fully qualified name including the module (e.g. 'mymodule.my_function').", + function_qualname, + ) + continue + module_name, function_name = function_qualname.rsplit(".", 1) try: diff --git a/tests/test_basics.py b/tests/test_basics.py index f628d139d1..01d518eee6 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -1090,6 +1090,14 @@ def test_classmethod_instance_tracing(sentry_init, capture_events): assert span["description"] == "tests.test_basics.TracingTestClass.class_" +def test_functions_to_trace_no_dot_does_not_crash(sentry_init): + # A qualified_name with no dot should not raise ValueError during sentry_sdk.init() + sentry_init( + traces_sample_rate=1.0, + functions_to_trace=[{"qualified_name": "my_function"}], + ) + + def test_last_event_id(sentry_init): sentry_init(traces_sample_rate=1.0)