打印特定函数中的所有子方法调用和参数



我正在尝试遵循示例,但找不到一个有形的示例来帮助我了解如何跟踪所有方法调用及其在特定方法中的参数(基于 elementMatcher(

我想跟踪的方法是getCustomer,并打算使用ByteBuddy获取getCustomer中调用的所有方法的元数据,并访问传递给每个方法的所有参数

例如。想打印出方法

i( customerRepository.findOne ,以 customerId 值作为参数

ii( 以客户价值为论据 log.info

等等...带返回值

public Customer getCustomer(@PathVariable("customerId") Long customerId) {
        /* validate customer Id parameter */
        if (null == customerId) {
            throw new InvalidCustomerRequestException();
        }
        Customer customer = customerRepository.findOne(customerId);
        if (null == customer) {
            throw new CustomerNotFoundException();
        }
        log.info("Customer Data is {}", customer);
        try {
            dispatchEventToSalesForce(String.format(" Customer %s Logged into SalesForce", customer));
        } catch (Exception e) {
            log.error("Failed to Dispatch Event to SalesForce . Details {} ", e.getLocalizedMessage());
        }
        return customer;
    }

有人可以帮我处理拦截器代码片段,以便我可以按照指导进行操作吗

现在,这在Byte Buddy上并不容易完成。您要查找的组件称为MemberSubstitution,它允许您替换方法中的方法调用和字段访问。您要做的是添加一个方法调用,用于捕获当前正在开发的参数,作为上述 API 的附加功能。

或者,如果您知道所有正在调用的方法,则可以截获它们,并浏览堆栈跟踪以验证它们是否从相关方法调用。

最新更新