diff --git a/ddtrace/debugging/_probe/registry.py b/ddtrace/debugging/_probe/registry.py index 32e8f443ea6..ec8e1239804 100644 --- a/ddtrace/debugging/_probe/registry.py +++ b/ddtrace/debugging/_probe/registry.py @@ -150,10 +150,10 @@ def log_probes_status(self) -> None: self._log_probe_status_unlocked(entry) def _remove_pending(self, probe: Probe) -> None: - location = _get_probe_location(probe) - - # Pending probes must have valid location information - assert location is not None, probe # nosec + if (location := _get_probe_location(probe)) is None: + # If the probe has no location information, then it cannot be + # pending. + return pending_probes = self._pending[location] try: diff --git a/releasenotes/notes/fix-unresolved-pending-probe-removal-80fbf85a9c068122.yaml b/releasenotes/notes/fix-unresolved-pending-probe-removal-80fbf85a9c068122.yaml new file mode 100644 index 00000000000..64356aed8d9 --- /dev/null +++ b/releasenotes/notes/fix-unresolved-pending-probe-removal-80fbf85a9c068122.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + dynamic instrumentation: prevent an exception when trying to remove a probe + that did not resolve to a valid source code location. diff --git a/tests/debugging/probe/test_registry.py b/tests/debugging/probe/test_registry.py index 49819f315ed..fd9aff4d024 100644 --- a/tests/debugging/probe/test_registry.py +++ b/tests/debugging/probe/test_registry.py @@ -56,6 +56,9 @@ def test_registry_location_error(): # Check that the probe is not pending assert not registry.get_pending(__file__) + # Check that unregistering the probe does not cause an exception + registry.unregister(probe) + # Check that we emitted the correct diagnostic error message for e in status_logger.queue: del e["timestamp"]