I suspect this is not possible but no harm in trying: it would be great if the error log about some DB query timing out due to a lock could automatically include what was the other query that caused the lock. DB error logs contain a bunch of information about the failing query (stack trace, sanitized query text) but in the case of lock timeouts, more often than not it's the locking query and not the locked query that's problematic, and there is no information about that at all, so identifying it tends to take a considerable amount of time.
Maybe something like SHOW ENGINE INNODB STATUS or innodb_print_all_deadlocks could be used to get locking query info into the error logs?
See also: T195792: Add support for setting individual query timeout in wikimedia/rdbms