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
b9f07542
Commit
b9f07542
authored
Mar 14, 2022
by
孙 楠
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新 zipkin 版本
parent
7be1a2da
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
176 deletions
+25
-176
pom.xml
brave-spring-boot-starter/pom.xml
+8
-0
BraveAutoConfiguration.java
...roup/tech/brave/configuration/BraveAutoConfiguration.java
+3
-2
TechExecutorServiceBuilderTrace.java
...h/brave/service/impl/TechExecutorServiceBuilderTrace.java
+6
-3
MDCCurrentTraceContext.java
...n/quantgroup/tech/brave/slf4j/MDCCurrentTraceContext.java
+0
-126
pom.xml
pom.xml
+8
-45
No files found.
brave-spring-boot-starter/pom.xml
View file @
b9f07542
...
@@ -73,10 +73,18 @@
...
@@ -73,10 +73,18 @@
<groupId>
io.zipkin.brave
</groupId>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-spring-rabbit
</artifactId>
<artifactId>
brave-instrumentation-spring-rabbit
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-context-slf4j
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
<artifactId>
transmittable-thread-local
</artifactId>
<artifactId>
transmittable-thread-local
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/configuration/BraveAutoConfiguration.java
View file @
b9f07542
package
cn
.
quantgroup
.
tech
.
brave
.
configuration
;
package
cn
.
quantgroup
.
tech
.
brave
.
configuration
;
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
;
...
@@ -13,7 +15,6 @@ import cn.quantgroup.tech.brave.properties.BraveProperties;
...
@@ -13,7 +15,6 @@ 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.*
;
import
cn.quantgroup.tech.brave.service.impl.*
;
import
cn.quantgroup.tech.brave.service.impl.*
;
import
cn.quantgroup.tech.brave.slf4j.MDCCurrentTraceContext
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.Dispatcher
;
import
okhttp3.Dispatcher
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
...
@@ -220,7 +221,7 @@ public class BraveAutoConfiguration {
...
@@ -220,7 +221,7 @@ public class BraveAutoConfiguration {
.
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
().
addScopeDecorator
(
MDCScopeDecorator
.
get
()).
build
())
.
spanReporter
(
spanReporter
()).
build
();
.
spanReporter
(
spanReporter
()).
build
();
}
}
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/service/impl/TechExecutorServiceBuilderTrace.java
View file @
b9f07542
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,8 @@ public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuil
...
@@ -19,7 +20,8 @@ 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
.
get
()).
build
();
return
mdcCurrentTraceContext
.
executorService
(
executorService
);
return
mdcCurrentTraceContext
.
executorService
(
executorService
);
}
}
...
@@ -32,7 +34,8 @@ public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuil
...
@@ -32,7 +34,8 @@ 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
.
get
()).
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 @
7be1a2da
package
cn
.
quantgroup
.
tech
.
brave
.
slf4j
;
import
brave.internal.codec.HexCodec
;
import
brave.internal.Nullable
;
import
brave.propagation.CurrentTraceContext
;
import
brave.propagation.TraceContext
;
import
org.slf4j.MDC
;
import
static
brave
.
internal
.
codec
.
HexCodec
.
lowerHexEqualsTraceId
;
import
static
brave
.
internal
.
codec
.
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
);
}
}
}
pom.xml
View file @
b9f07542
...
@@ -106,31 +106,6 @@
...
@@ -106,31 +106,6 @@
</dependency>
</dependency>
<!-- zipkin -->
<!-- zipkin -->
<dependency>
<groupId>
io.zipkin.reporter2
</groupId>
<artifactId>
zipkin-reporter
</artifactId>
<version>
${zipkin-reporter2.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.zipkin2
</groupId>
<artifactId>
zipkin
</artifactId>
<version>
${zipkin.version}
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
${okhttp.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-spring-beans
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
io.zipkin.reporter2
</groupId>
<groupId>
io.zipkin.reporter2
</groupId>
<artifactId>
zipkin-sender-kafka11
</artifactId>
<artifactId>
zipkin-sender-kafka11
</artifactId>
...
@@ -138,33 +113,21 @@
...
@@ -138,33 +113,21 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-
instrumentation-spring-web
</artifactId>
<artifactId>
brave-
bom
</artifactId>
<version>
${brave.version}
</version>
<version>
${brave.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-spring-webmvc
</artifactId>
<artifactId>
brave-context-slf4j
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-httpclient
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-mysql
</artifactId>
<version>
${brave.version}
</version>
</dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<artifactId>
brave-instrumentation-okhttp3
</artifactId>
<version>
${brave.version}
</version>
<version>
${brave.version}
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
io.zipkin.brave
</groupId>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
brave-instrumentation-spring-rabbit
</artifactId>
<artifactId>
okhttp
</artifactId>
<version>
${
brave
.version}
</version>
<version>
${
okhttp
.version}
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
...
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