class RabbitMqBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName)
                                                                               throws BeansException {
        if (bean instanceof AbstractRabbitListenerContainerFactory factory) {
            registerTracingInterceptor(factory);
        } else if (bean instanceof AbstractMessageListenerContainer container) {
            registerTracingInterceptor(container);
        }
        return bean;
    }

    @SuppressWarnings("rawtypes")
    private void registerTracingInterceptor(AbstractRabbitListenerContainerFactory factory) {
        Advice[] chain = factory.getAdviceChain();
        Advice[] adviceChainWithTracing = getAdviceChainOrAddInterceptorToChain(chain);
        factory.setAdviceChain(adviceChainWithTracing);
    }

    private void registerTracingInterceptor(AbstractMessageListenerContainer container) {
        Field adviceChainField = ReflectionUtils.findField(AbstractMessageListenerContainer.class,
            "adviceChain");
        ReflectionUtils.makeAccessible(adviceChainField);
        Advice[] chain = (Advice[]) ReflectionUtils.getField(adviceChainField, container);
        Advice[] adviceChainWithTracing = getAdviceChainOrAddInterceptorToChain(chain);
        container.setAdviceChain(adviceChainWithTracing);
    }

    private Advice[] getAdviceChainOrAddInterceptorToChain(Advice... existingAdviceChain) {<FILL_FUNCTION_BODY>}

    @Override
    public int getOrder() {
        return LOWEST_PRECEDENCE;
    }
}

        if (existingAdviceChain == null) {
            return new Advice[] { new SofaTracerConsumeInterceptor() };
        }

        for (Advice advice : existingAdviceChain) {
            if (advice instanceof SofaTracerConsumeInterceptor) {
                return existingAdviceChain;
            }
        }

        Advice[] newChain = new Advice[existingAdviceChain.length + 1];
        System.arraycopy(existingAdviceChain, 0, newChain, 0, existingAdviceChain.length);
        newChain[existingAdviceChain.length] = new SofaTracerConsumeInterceptor();

        return newChain;
    
<no_super_class>