Skip to content

Commit

Permalink
Add tracer autoconfigure. (#847) (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
it-linnan committed Dec 13, 2022
1 parent d7f4dc1 commit d7e6a1d
Show file tree
Hide file tree
Showing 21 changed files with 1,182 additions and 0 deletions.
72 changes: 72 additions & 0 deletions sofa-boot-project/sofa-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,42 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-kafkamq-plugin</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-rabbitmq-plugin</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-rocketmq-plugin</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-springmessage-plugin</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-redis-plugin</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-mongodb-plugin</artifactId>
<optional>true</optional>
</dependency>

<!--provider-->
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand All @@ -120,6 +156,42 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<scope>provided</scope>
</dependency>
<!--Test-->
<dependency>
<groupId>org.jmockit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.autoconfigure.tracer;

import com.alipay.sofa.tracer.boot.kafka.processor.KafkaConsumerFactoryPostProcessor;
import com.alipay.sofa.tracer.boot.kafka.processor.KafkaProducerFactoryPostProcessor;
import com.sofa.alipay.tracer.plugins.kafkamq.aspect.KafkaListenerSofaTracerAspect;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.ProducerFactory;

/**
* @author chenchen6 2020/9/2 21:56
* @since 3.9.1
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(KafkaAutoConfiguration.class)
@ConditionalOnClass({ ProducerFactory.class, ConsumerFactory.class })
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ConditionalOnProperty(name = "com.alipay.tracer.kafka.enabled", havingValue = "true", matchIfMissing = true)
public class SofaTracerKafkaAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public KafkaConsumerFactoryPostProcessor kafkaConsumerFactoryPostProcessor() {
return new KafkaConsumerFactoryPostProcessor();
}

@Bean
@ConditionalOnMissingBean
public KafkaProducerFactoryPostProcessor kafkaProducerFactoryPostProcessor() {
return new KafkaProducerFactoryPostProcessor();
}

@Bean
@ConditionalOnMissingBean
public KafkaListenerSofaTracerAspect kafkaListenerSofaTracerAspect() {
return new KafkaListenerSofaTracerAspect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.autoconfigure.tracer;

import com.alipay.sofa.tracer.boot.mongodb.SofaTracerMongoClientSettingsBuilderCustomizer;
import com.mongodb.client.MongoClient;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* SofaTracerMongoAutoConfiguration
*
* @author linnan
* @since 3.9.1
**/
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore({ MongoAutoConfiguration.class })
@ConditionalOnClass({ MongoClient.class })
@ConditionalOnProperty(name = "com.alipay.tracer.mongodb.enabled", havingValue = "true", matchIfMissing = true)
public class SofaTracerMongoAutoConfiguration {

@Bean
@ConditionalOnMissingBean
SofaTracerMongoClientSettingsBuilderCustomizer sofaTracerMongoClientSettingsBuilderCustomizer() {
return new SofaTracerMongoClientSettingsBuilderCustomizer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.autoconfigure.tracer;

import com.alipay.sofa.tracer.boot.rabbitmq.processor.SofaTracerRabbitMqBeanPostProcessor;
import com.sofa.alipay.tracer.plugins.rabbitmq.aspect.SofaTracerSendMessageAspect;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
* SofaTracerRabbitMqAutoConfiguration.
*
* @author chenchen6 2020/8/09 20:44
* @since 3.9.1
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(RabbitAutoConfiguration.class)
@ConditionalOnClass({ Message.class, RabbitTemplate.class })
@ConditionalOnProperty(prefix = "com.alipay.sofa.tracer.rabbitmq", value = "enable", matchIfMissing = true)
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class SofaTracerRabbitMqAutoConfiguration {

@ConditionalOnBean(RabbitTemplate.class)
@Bean
public SofaTracerSendMessageAspect rabbitMqSendTracingAspect(RabbitTemplate rabbitTemplate) {
return new SofaTracerSendMessageAspect(rabbitTemplate.getExchange(),
rabbitTemplate.getRoutingKey(), rabbitTemplate.getMessageConverter(), rabbitTemplate);
}

@ConditionalOnMissingBean
@Bean
public SofaTracerRabbitMqBeanPostProcessor sofaTracerRabbitMqBeanPostProcessor() {
return new SofaTracerRabbitMqBeanPostProcessor();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.autoconfigure.tracer;

import com.sofa.alipay.tracer.plugins.spring.redis.SofaTracerRCFBeanPostProcessor;
import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisActionWrapperHelper;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
* @author guolei.sgl (guolei.sgl@antfin.com) 2019/11/19 8:03 PM
* @since 3.9.1
**/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ RedisConnectionFactory.class, RedisActionWrapperHelper.class })
@ConditionalOnProperty(name = "com.alipay.sofa.tracer.redis.enabled", havingValue = "true", matchIfMissing = true)
@AutoConfigureAfter(SofaTracerAutoConfiguration.class)
public class SofaTracerRedisAutoConfiguration {

@Bean
@ConditionalOnMissingBean
RedisActionWrapperHelper redisActionWrapperHelper() {
return new RedisActionWrapperHelper();
}

@Bean
@ConditionalOnMissingBean
SofaTracerRCFBeanPostProcessor sofaTracerRCFBeanPostProcessor(RedisActionWrapperHelper redisActionWrapperHelper) {
return new SofaTracerRCFBeanPostProcessor(redisActionWrapperHelper);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.autoconfigure.tracer;

import com.alipay.sofa.tracer.boot.rocketmq.processor.SofaTracerRocketMqConsumerPostProcessor;
import com.alipay.sofa.tracer.boot.rocketmq.processor.SofaTracerRocketMqProducerPostProcessor;
import org.apache.rocketmq.client.producer.MQProducer;
import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration;
import org.apache.rocketmq.spring.support.RocketMQListenerContainer;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* SofaTracerRocketMqAutoConfiguration.
*
* @author linnan
* @since 3.9.1
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(RocketMQAutoConfiguration.class)
@ConditionalOnClass({ MQProducer.class, RocketMQListenerContainer.class })
@ConditionalOnProperty(prefix = "com.alipay.sofa.tracer.rocketmq", value = "enable", matchIfMissing = true)
public class SofaTracerRocketMqAutoConfiguration {

@ConditionalOnMissingBean
@Bean
public SofaTracerRocketMqProducerPostProcessor sofaTracerRocketMqProducerPostProcessor() {
return new SofaTracerRocketMqProducerPostProcessor();
}

@ConditionalOnMissingBean
@Bean
public SofaTracerRocketMqConsumerPostProcessor sofaTracerRocketMqConsumerPostProcessor() {
return new SofaTracerRocketMqConsumerPostProcessor();
}
}
Loading

0 comments on commit d7e6a1d

Please sign in to comment.