Skip to content

Commit ced7d5c

Browse files
committed
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
1 parent 2ce26d1 commit ced7d5c

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

sentry_sdk/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,14 @@ def _setup_instrumentation(
507507
for function in functions_to_trace:
508508
class_name = None
509509
function_qualname = function["qualified_name"]
510+
511+
if "." not in function_qualname:
512+
logger.warning(
513+
"Can not enable tracing for '%s'. Please provide the fully qualified name including the module (e.g. 'mymodule.my_function').",
514+
function_qualname,
515+
)
516+
continue
517+
510518
module_name, function_name = function_qualname.rsplit(".", 1)
511519

512520
try:

tests/test_basics.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,14 @@ def test_classmethod_instance_tracing(sentry_init, capture_events):
10901090
assert span["description"] == "tests.test_basics.TracingTestClass.class_"
10911091

10921092

1093+
def test_functions_to_trace_no_dot_does_not_crash(sentry_init):
1094+
# A qualified_name with no dot should not raise ValueError during sentry_sdk.init()
1095+
sentry_init(
1096+
traces_sample_rate=1.0,
1097+
functions_to_trace=[{"qualified_name": "my_function"}],
1098+
)
1099+
1100+
10931101
def test_last_event_id(sentry_init):
10941102
sentry_init(traces_sample_rate=1.0)
10951103

0 commit comments

Comments
 (0)