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
7c7536f5
Commit
7c7536f5
authored
May 25, 2020
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
brave 版本升级。支持 spring boot 2.0
parent
af14582f
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
52 additions
and
148 deletions
+52
-148
pom.xml
brave-spring-boot-starter/pom.xml
+7
-2
BraveAutoConfiguration.java
...roup/tech/brave/configuration/BraveAutoConfiguration.java
+29
-9
TechExecutorServiceBuilderTrace.java
...h/brave/service/impl/TechExecutorServiceBuilderTrace.java
+8
-3
MDCCurrentTraceContext.java
...n/quantgroup/tech/brave/slf4j/MDCCurrentTraceContext.java
+0
-126
pom.xml
commons-core/pom.xml
+1
-1
pom.xml
commons-spring/pom.xml
+1
-1
pom.xml
elastic-job-lite-spring-boot-starter/pom.xml
+1
-1
pom.xml
enoch-agent-spring-boot-starter/pom.xml
+1
-1
pom.xml
idgenerator-spring-boot-starter/pom.xml
+1
-1
pom.xml
pom.xml
+2
-2
pom.xml
shutdown-spring-boot-starter/pom.xml
+1
-1
No files found.
brave-spring-boot-starter/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<properties>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<brave.version>
4.19
.1
</brave.version>
<brave.version>
5.10
.1
</brave.version>
<zipkin-reporter2.version>
2.5.0
</zipkin-reporter2.version>
<zipkin-reporter2.version>
2.5.0
</zipkin-reporter2.version>
<zipkin.version>
2.6.1
</zipkin.version>
<zipkin.version>
2.6.1
</zipkin.version>
<okhttp.version>
3.10.0
</okhttp.version>
<okhttp.version>
3.10.0
</okhttp.version>
...
@@ -115,6 +115,11 @@
...
@@ -115,6 +115,11 @@
<artifactId>
brave-instrumentation-spring-rabbit
</artifactId>
<artifactId>
brave-instrumentation-spring-rabbit
</artifactId>
<version>
${brave.version}
</version>
<version>
${brave.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-context-slf4j
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/configuration/BraveAutoConfiguration.java
View file @
7c7536f5
...
@@ -2,19 +2,33 @@ package cn.quantgroup.tech.brave.configuration;
...
@@ -2,19 +2,33 @@ package cn.quantgroup.tech.brave.configuration;
import
brave.Tracer
;
import
brave.Tracer
;
import
brave.Tracing
;
import
brave.Tracing
;
import
brave.context.slf4j.MDCScopeDecorator
;
import
brave.http.HttpTracing
;
import
brave.http.HttpTracing
;
import
brave.httpclient.TracingHttpClientBuilder
;
import
brave.httpclient.TracingHttpClientBuilder
;
import
brave.okhttp3.TracingInterceptor
;
import
brave.okhttp3.TracingInterceptor
;
import
brave.propagation.B3Propagation
;
import
brave.propagation.B3Propagation
;
import
brave.propagation.ExtraFieldPropagation
;
import
brave.propagation.ExtraFieldPropagation
;
import
brave.propagation.ThreadLocalCurrentTraceContext
;
import
brave.spring.web.TracingClientHttpRequestInterceptor
;
import
brave.spring.web.TracingClientHttpRequestInterceptor
;
import
brave.spring.webmvc.SpanCustomizingAsyncHandlerInterceptor
;
import
brave.spring.webmvc.SpanCustomizingAsyncHandlerInterceptor
;
import
cn.quantgroup.tech.brave.filter.CustomDelegatingTracingFilter
;
import
cn.quantgroup.tech.brave.filter.CustomDelegatingTracingFilter
;
import
cn.quantgroup.tech.brave.properties.BraveProperties
;
import
cn.quantgroup.tech.brave.properties.BraveProperties
;
import
cn.quantgroup.tech.brave.properties.ServiceProperties
;
import
cn.quantgroup.tech.brave.properties.ServiceProperties
;
import
cn.quantgroup.tech.brave.service.*
;
import
cn.quantgroup.tech.brave.service.ITechExecutorServiceBuilder
;
import
cn.quantgroup.tech.brave.service.impl.*
;
import
cn.quantgroup.tech.brave.service.ITechHttpClient
;
import
cn.quantgroup.tech.brave.slf4j.MDCCurrentTraceContext
;
import
cn.quantgroup.tech.brave.service.ITechOkHttpClient
;
import
cn.quantgroup.tech.brave.service.ITechRabbitBuilder
;
import
cn.quantgroup.tech.brave.service.ITechRestTemplateBuilder
;
import
cn.quantgroup.tech.brave.service.impl.TechExecutorServiceBuilderNoTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechExecutorServiceBuilderTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechHttpClientNoTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechHttpClientTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechOkHttpClientNoTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechOkHttpClientTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechRabbitBuilderNoTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechRabbitBuilderTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechRestTemplateBuilderTrace
;
import
cn.quantgroup.tech.brave.service.impl.TechRestTemplateBuliderNoTrace
;
import
com.dangdang.ddframe.job.api.ElasticJob
;
import
com.dangdang.ddframe.job.api.ElasticJob
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.Dispatcher
;
import
okhttp3.Dispatcher
;
...
@@ -26,7 +40,10 @@ import org.aspectj.lang.annotation.Around;
...
@@ -26,7 +40,10 @@ import org.aspectj.lang.annotation.Around;
import
org.aspectj.lang.annotation.Aspect
;
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.*
;
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.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -219,11 +236,14 @@ public class BraveAutoConfiguration {
...
@@ -219,11 +236,14 @@ public class BraveAutoConfiguration {
@ConditionalOnMissingBean
@ConditionalOnMissingBean
Tracing
tracing
()
{
Tracing
tracing
()
{
return
Tracing
.
newBuilder
()
return
Tracing
.
newBuilder
()
.
sampler
(
brave
.
sampler
.
Sampler
.
create
(
braveProperties
.
getSample
()))
.
sampler
(
brave
.
sampler
.
Sampler
.
create
(
braveProperties
.
getSample
()))
.
localServiceName
(
serviceProperties
.
getName
())
.
localServiceName
(
serviceProperties
.
getName
())
.
propagationFactory
(
ExtraFieldPropagation
.
newFactory
(
B3Propagation
.
FACTORY
,
"user-name"
))
.
propagationFactory
(
ExtraFieldPropagation
.
newFactory
(
B3Propagation
.
FACTORY
,
"user-name"
))
.
currentTraceContext
(
MDCCurrentTraceContext
.
create
())
.
currentTraceContext
(
ThreadLocalCurrentTraceContext
.
newBuilder
()
.
spanReporter
(
spanReporter
()).
build
();
.
addScopeDecorator
(
MDCScopeDecorator
.
create
())
.
build
())
.
spanReporter
(
spanReporter
())
.
build
();
}
}
@Deprecated
@Deprecated
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/service/impl/TechExecutorServiceBuilderTrace.java
View file @
7c7536f5
package
cn
.
quantgroup
.
tech
.
brave
.
service
.
impl
;
package
cn
.
quantgroup
.
tech
.
brave
.
service
.
impl
;
import
brave.context.slf4j.MDCScopeDecorator
;
import
brave.propagation.CurrentTraceContext
;
import
brave.propagation.CurrentTraceContext
;
import
brave.propagation.ThreadLocalCurrentTraceContext
;
import
cn.quantgroup.tech.brave.service.ITechExecutorServiceBuilder
;
import
cn.quantgroup.tech.brave.service.ITechExecutorServiceBuilder
;
import
cn.quantgroup.tech.brave.slf4j.MDCCurrentTraceContext
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
...
@@ -19,7 +20,9 @@ public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuil
...
@@ -19,7 +20,9 @@ public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuil
@Override
@Override
public
ExecutorService
buildExecutorService
(
ExecutorService
executorService
)
{
public
ExecutorService
buildExecutorService
(
ExecutorService
executorService
)
{
log
.
info
(
"构建ExecutorServiceTrace"
);
log
.
info
(
"构建ExecutorServiceTrace"
);
CurrentTraceContext
mdcCurrentTraceContext
=
MDCCurrentTraceContext
.
create
();
CurrentTraceContext
mdcCurrentTraceContext
=
ThreadLocalCurrentTraceContext
.
newBuilder
()
.
addScopeDecorator
(
MDCScopeDecorator
.
create
())
.
build
();
return
mdcCurrentTraceContext
.
executorService
(
executorService
);
return
mdcCurrentTraceContext
.
executorService
(
executorService
);
}
}
...
@@ -32,7 +35,9 @@ public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuil
...
@@ -32,7 +35,9 @@ public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuil
@Override
@Override
public
Runnable
wrap
(
Runnable
task
)
{
public
Runnable
wrap
(
Runnable
task
)
{
log
.
info
(
"wrap Runnable 4 support trace"
);
log
.
info
(
"wrap Runnable 4 support trace"
);
CurrentTraceContext
mdcCurrentTraceContext
=
MDCCurrentTraceContext
.
create
();
CurrentTraceContext
mdcCurrentTraceContext
=
ThreadLocalCurrentTraceContext
.
newBuilder
()
.
addScopeDecorator
(
MDCScopeDecorator
.
create
())
.
build
();
return
mdcCurrentTraceContext
.
wrap
(
task
);
return
mdcCurrentTraceContext
.
wrap
(
task
);
}
}
}
}
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/slf4j/MDCCurrentTraceContext.java
deleted
100644 → 0
View file @
af14582f
package
cn
.
quantgroup
.
tech
.
brave
.
slf4j
;
import
brave.internal.HexCodec
;
import
brave.internal.Nullable
;
import
brave.propagation.CurrentTraceContext
;
import
brave.propagation.TraceContext
;
import
org.slf4j.MDC
;
import
static
brave
.
internal
.
HexCodec
.
lowerHexEqualsTraceId
;
import
static
brave
.
internal
.
HexCodec
.
lowerHexEqualsUnsignedLong
;
/**
* Adds {@linkplain MDC} properties TRACE_ID, PARENT_ID and SPAN_ID when a {@link
* brave.Tracer#currentSpan() span is current}. These can be used in log correlation.
*/
public
final
class
MDCCurrentTraceContext
extends
CurrentTraceContext
{
private
static
final
String
TRACE_ID
=
"X-B3-TraceId"
;
private
static
final
String
SPAN_ID
=
"X-B3-SpanId"
;
private
static
final
String
PARENT_ID
=
"X-B3-ParentId"
;
private
static
final
String
EXPORTABLE
=
"X-Span-Export"
;
public
static
MDCCurrentTraceContext
create
()
{
return
create
(
CurrentTraceContext
.
Default
.
inheritable
());
}
public
static
MDCCurrentTraceContext
create
(
CurrentTraceContext
delegate
)
{
return
new
MDCCurrentTraceContext
(
delegate
);
}
final
CurrentTraceContext
delegate
;
MDCCurrentTraceContext
(
CurrentTraceContext
delegate
)
{
if
(
delegate
==
null
)
throw
new
NullPointerException
(
"delegate == null"
);
this
.
delegate
=
delegate
;
}
@Override
public
TraceContext
get
()
{
return
delegate
.
get
();
}
@Override
public
Scope
newScope
(
@Nullable
TraceContext
currentSpan
)
{
return
newScope
(
currentSpan
,
MDC
.
get
(
TRACE_ID
),
MDC
.
get
(
SPAN_ID
),
MDC
.
get
(
EXPORTABLE
));
}
@Override
public
Scope
maybeScope
(
@Nullable
TraceContext
currentSpan
)
{
String
previousTraceId
=
MDC
.
get
(
TRACE_ID
);
String
previousSpanId
=
MDC
.
get
(
SPAN_ID
);
String
sampled
=
MDC
.
get
(
EXPORTABLE
);
if
(
currentSpan
==
null
)
{
if
(
previousTraceId
==
null
)
{
return
Scope
.
NOOP
;
}
return
newScope
(
null
,
previousTraceId
,
previousSpanId
,
sampled
);
}
if
(
lowerHexEqualsTraceId
(
previousTraceId
,
currentSpan
)
&&
lowerHexEqualsUnsignedLong
(
previousSpanId
,
currentSpan
.
spanId
()))
{
return
Scope
.
NOOP
;
}
return
newScope
(
currentSpan
,
previousTraceId
,
previousSpanId
,
sampled
);
}
// all input parameters are nullable
Scope
newScope
(
TraceContext
currentSpan
,
String
previousTraceId
,
String
previousSpanId
,
String
sampled
)
{
String
previousParentId
=
MDC
.
get
(
PARENT_ID
);
if
(
currentSpan
!=
null
)
{
maybeReplaceTraceContext
(
currentSpan
,
previousTraceId
,
previousParentId
,
previousSpanId
,
sampled
);
}
else
{
MDC
.
remove
(
TRACE_ID
);
MDC
.
remove
(
PARENT_ID
);
MDC
.
remove
(
SPAN_ID
);
MDC
.
remove
(
EXPORTABLE
);
}
Scope
scope
=
delegate
.
newScope
(
currentSpan
);
class
MDCCurrentTraceContextScope
implements
Scope
{
@Override
public
void
close
()
{
scope
.
close
();
replace
(
TRACE_ID
,
previousTraceId
);
replace
(
PARENT_ID
,
previousParentId
);
replace
(
SPAN_ID
,
previousSpanId
);
//true = 采样了. false = 未采样. null = 决定不了...等会再说
replace
(
EXPORTABLE
,
sampled
);
}
}
return
new
MDCCurrentTraceContextScope
();
}
void
maybeReplaceTraceContext
(
TraceContext
currentSpan
,
String
previousTraceId
,
@Nullable
String
previousParentId
,
String
previousSpanId
,
@Nullable
String
sampled
)
{
MDC
.
put
(
EXPORTABLE
,
String
.
valueOf
(
currentSpan
.
sampled
()));
boolean
sameTraceId
=
lowerHexEqualsTraceId
(
previousTraceId
,
currentSpan
);
if
(!
sameTraceId
)
{
MDC
.
put
(
TRACE_ID
,
currentSpan
.
traceIdString
());
}
long
parentId
=
currentSpan
.
parentIdAsLong
();
if
(
parentId
==
0L
)
{
MDC
.
remove
(
PARENT_ID
);
}
else
{
boolean
sameParentId
=
lowerHexEqualsUnsignedLong
(
previousParentId
,
parentId
);
if
(!
sameParentId
)
MDC
.
put
(
PARENT_ID
,
HexCodec
.
toLowerHex
(
parentId
));
}
boolean
sameSpanId
=
lowerHexEqualsUnsignedLong
(
previousSpanId
,
currentSpan
.
spanId
());
if
(!
sameSpanId
)
MDC
.
put
(
SPAN_ID
,
HexCodec
.
toLowerHex
(
currentSpan
.
spanId
()));
}
static
void
replace
(
String
key
,
@Nullable
String
value
)
{
if
(
value
!=
null
)
{
MDC
.
put
(
key
,
value
);
}
else
{
MDC
.
remove
(
key
);
}
}
}
commons-core/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
commons-spring/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
elastic-job-lite-spring-boot-starter/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
enoch-agent-spring-boot-starter/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
...
...
idgenerator-spring-boot-starter/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
pom.xml
View file @
7c7536f5
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<lombok.version>
1.16.20
</lombok.version>
<lombok.version>
1.16.20
</lombok.version>
<guava.version>
23.0
</guava.version>
<guava.version>
23.0
</guava.version>
<apollo.client.version>
0.10.2
</apollo.client.version>
<apollo.client.version>
0.10.2
</apollo.client.version>
<common.parent.version>
0.3.2
</common.parent.version>
<common.parent.version>
1.0.0
</common.parent.version>
</properties>
</properties>
<dependencies>
<dependencies>
...
...
shutdown-spring-boot-starter/pom.xml
View file @
7c7536f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.2
</version>
<version>
1.0.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
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