Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
31283c83
Commit
31283c83
authored
Jan 07, 2020
by
杨锐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto config ElasticJobAspect
parent
94279625
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
pom.xml
brave-spring-boot-starter/pom.xml
+5
-0
BraveAutoConfiguration.java
...roup/tech/brave/configuration/BraveAutoConfiguration.java
+44
-9
No files found.
brave-spring-boot-starter/pom.xml
View file @
31283c83
...
@@ -40,6 +40,11 @@
...
@@ -40,6 +40,11 @@
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<artifactId>
httpclient
</artifactId>
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/configuration/BraveAutoConfiguration.java
View file @
31283c83
package
cn
.
quantgroup
.
tech
.
brave
.
configuration
;
package
cn
.
quantgroup
.
tech
.
brave
.
configuration
;
import
brave.Tracer
;
import
brave.Tracing
;
import
brave.Tracing
;
import
brave.http.HttpTracing
;
import
brave.http.HttpTracing
;
import
brave.httpclient.TracingHttpClientBuilder
;
import
brave.httpclient.TracingHttpClientBuilder
;
...
@@ -29,6 +30,9 @@ import okhttp3.Dispatcher;
...
@@ -29,6 +30,9 @@ import okhttp3.Dispatcher;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
@@ -40,11 +44,9 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
...
@@ -40,11 +44,9 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.filter.CharacterEncodingFilter
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
zipkin2.Span
;
import
zipkin2.Span
;
...
@@ -53,6 +55,7 @@ import zipkin2.reporter.AsyncReporter;
...
@@ -53,6 +55,7 @@ import zipkin2.reporter.AsyncReporter;
import
zipkin2.reporter.Sender
;
import
zipkin2.reporter.Sender
;
import
zipkin2.reporter.kafka11.KafkaSender
;
import
zipkin2.reporter.kafka11.KafkaSender
;
import
javax.annotation.Resource
;
import
javax.servlet.Filter
;
import
javax.servlet.Filter
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -93,8 +96,8 @@ public class BraveAutoConfiguration {
...
@@ -93,8 +96,8 @@ public class BraveAutoConfiguration {
/**
/**
* 提供HttpClientBuilderBean
* 提供HttpClientBuilderBean
*
*
* @see ITechHttpClient
* @return
* @return
* @see ITechHttpClient
*/
*/
@Deprecated
@Deprecated
@Bean
(
name
=
"techHttpClientBuilder"
)
@Bean
(
name
=
"techHttpClientBuilder"
)
...
@@ -113,8 +116,8 @@ public class BraveAutoConfiguration {
...
@@ -113,8 +116,8 @@ public class BraveAutoConfiguration {
/**
/**
* 提供OkHttpClientBean
* 提供OkHttpClientBean
*
*
* @see ITechOkHttpClient
* @return
* @return
* @see ITechOkHttpClient
*/
*/
@Deprecated
@Deprecated
@Bean
(
name
=
"techOkHttpClientBuilder"
)
@Bean
(
name
=
"techOkHttpClientBuilder"
)
...
@@ -132,8 +135,8 @@ public class BraveAutoConfiguration {
...
@@ -132,8 +135,8 @@ public class BraveAutoConfiguration {
/**
/**
* 提供RestTemplate
* 提供RestTemplate
*
*
* @see ITechRestTemplateBuilder
* @return
* @return
* @see ITechRestTemplateBuilder
*/
*/
@Deprecated
@Deprecated
@Bean
(
name
=
"techRestTemplate"
)
@Bean
(
name
=
"techRestTemplate"
)
...
@@ -296,9 +299,9 @@ public class BraveAutoConfiguration {
...
@@ -296,9 +299,9 @@ public class BraveAutoConfiguration {
/**
/**
* 提供HttpClientBuilderBean
* 提供HttpClientBuilderBean
*
*
* @see ITechHttpClient
* @param tracing
* @param tracing
* @return
* @return
* @see ITechHttpClient
*/
*/
@Deprecated
@Deprecated
@Bean
(
name
=
"techHttpClientBuilder"
)
@Bean
(
name
=
"techHttpClientBuilder"
)
...
@@ -316,9 +319,9 @@ public class BraveAutoConfiguration {
...
@@ -316,9 +319,9 @@ public class BraveAutoConfiguration {
/**
/**
* 提供OkHttpClientBean
* 提供OkHttpClientBean
*
*
* @see ITechOkHttpClient
* @param httpTracing
* @param httpTracing
* @return
* @return
* @see ITechOkHttpClient
*/
*/
@Deprecated
@Deprecated
@Bean
(
name
=
"techOkHttpClientBuilder"
)
@Bean
(
name
=
"techOkHttpClientBuilder"
)
...
@@ -343,8 +346,8 @@ public class BraveAutoConfiguration {
...
@@ -343,8 +346,8 @@ public class BraveAutoConfiguration {
/**
/**
* 提供RestTemplate
* 提供RestTemplate
*
*
* @see ITechRestTemplateBuilder
* @return
* @return
* @see ITechRestTemplateBuilder
*/
*/
@Deprecated
@Deprecated
@Bean
(
name
=
"techRestTemplate"
)
@Bean
(
name
=
"techRestTemplate"
)
...
@@ -412,6 +415,38 @@ public class BraveAutoConfiguration {
...
@@ -412,6 +415,38 @@ public class BraveAutoConfiguration {
}
}
@Configuration
@ConditionalOnProperty
(
name
=
"elastic.job.enabled"
,
havingValue
=
"true"
)
public
static
class
ElasticJobEnabled
{
@Aspect
@Component
public
class
ElasticJobAspect
{
@Resource
private
Tracing
tracing
;
@Around
(
"target(com.dangdang.ddframe.job.api.ElasticJob)"
)
public
Object
dynamicTrace
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
Tracer
tracer
=
tracing
.
tracer
();
/* 防止应用层非法使用(上下文中存在span),不生成root span。 */
if
(
tracer
.
currentSpan
()
==
null
)
{
brave
.
Span
span
=
tracer
.
newTrace
();
try
(
Tracer
.
SpanInScope
ws
=
tracer
.
withSpanInScope
(
span
))
{
return
pjp
.
proceed
();
// note: try-with-resources closes the scope *before* the catch block
}
catch
(
RuntimeException
|
Error
e
)
{
span
.
error
(
e
);
throw
e
;
}
catch
(
Throwable
e1
)
{
throw
e1
;
}
finally
{
span
.
finish
();
}
}
return
pjp
.
proceed
();
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment