Attempts to get the lock using the given session.
        :param key: name of the lock
        :param session_id: the identifier of the Consul session that should try to hold the lock
        :param seconds_to_lock: the number of seconds it took to acquire the lock
        :param metadata: metadata to add to the lock information
        :return: details about the lock if acquired, else `None`
        :raises SessionLostConsulError: if the Consul session is lost

def _acquire_lock(self, key: str, session_id: str, seconds_to_lock: float, metadata: Any) \
            -> Optional[ConnectedConsulLockInformation]:
        """
        Attempts to get the lock using the given session.
        :param key: name of the lock
        :param session_id: the identifier of the Consul session that should try to hold the lock
        :param seconds_to_lock: the number of seconds it took to acquire the lock
        :param metadata: metadata to add to the lock information
        :return: details about the lock if acquired, else `None`
        :raises SessionLostConsulError: if the Consul session is lost
        """
        lock_information = ConnectedConsulLockInformation(
            self, key, session_id, datetime.utcnow(), seconds_to_lock, metadata)
        value = json.dumps(lock_information, cls=ConsulLockInformationJSONEncoder, indent=4, sort_keys=True)
        logger.debug(f"Attempting to acquire lock with value: {value}")
        try:
            success = self.consul_client.kv.put(key=key, value=value, acquire=session_id)
        except ConsulException as e:
            if "invalid session" in e.args[0]:
                raise SessionLostConsulError() from e
            raise e
        return lock_information if success else None