Comments (5)
from brave-example.
For log data analysis,also need to know the call chains.
from brave-example.
from brave-example.
1). I customized the brave example code to add the parentSpanId as below:
import brave.internal.HexCodec;
import brave.internal.Nullable;
import brave.propagation.CurrentTraceContext;
import brave.propagation.TraceContext;
import org.apache.logging.log4j.ThreadContext;
/**
* Adds {@linkplain ThreadContext} properties "traceId" , "spanId" and "parentSpanId" when a {@link
* brave.Tracer#currentSpan() span is current}. These can be used in log correlation.
*/
public final class MyThreadContextCurrentTraceContext extends CurrentTraceContext {
public static MyThreadContextCurrentTraceContext create() {
return create(CurrentTraceContext.Default.inheritable());
}
public static MyThreadContextCurrentTraceContext create(CurrentTraceContext delegate) {
return new MyThreadContextCurrentTraceContext(delegate);
}
final CurrentTraceContext delegate;
MyThreadContextCurrentTraceContext(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) {
final String previousTraceId = ThreadContext.get("traceId");
final String previousSpanId = ThreadContext.get("spanId");
if (currentSpan != null) {
ThreadContext.put("traceId", currentSpan.traceIdString());
ThreadContext.put("spanId", HexCodec.toLowerHex(currentSpan.spanId()));
Long parentId= currentSpan.parentId();
if(parentId!=null){
String pid=HexCodec.toLowerHex(parentId);
ThreadContext.put("parentSpanId",pid);
}
} else {
ThreadContext.remove("traceId");
ThreadContext.remove("spanId");
ThreadContext.remove("parentSpanId");
}
final Scope scope = delegate.newScope(currentSpan);
class ThreadContextCurrentTraceContextScope implements Scope {
@Override public void close() {
scope.close();
ThreadContext.put("traceId", previousTraceId);
ThreadContext.put("spanId", previousSpanId);
}
}
return new ThreadContextCurrentTraceContextScope();
}
}
2). add the below line in log4j config file:
[%X{traceId}/%X{spanId}/%X{parentSpanId}]
3). after I sent the request to the parent system,I got parentSpanId:""(blank) that is correct,
but after resent the request to parent system for several times(about 10 times), I got the parentSpanId not blank,why this happened?(it should be blank)
from brave-example.
filed in brave
from brave-example.
Related Issues (15)
- Unit test failed: ITZipkinSpanCollector.testOfferTimeOut:101 ╗ TTransport Could not create Serve... HOT 1
- convert this project to normal webmvc and rest template HOT 1
- Trio the example, spring XML, java config, boot HOT 8
- Zipkin brave and Kafka transports using XML HOT 12
- Should use "java.lang.String" instead of "String" as type in `constructor-arg` tag of OkHttpSender's factory method HOT 1
- Sample code for Spring 2.X is not working since Spring Rest Template is not available in Spring 2.X HOT 5
- Help needed on deploying this example for tomcat WITHOUT using PROFILES HOT 2
- Help about Spring Boot Option ? it seems does not work HOT 2
- I got several questions about trace wanna discuss with you. HOT 3
- The project can't be build with jdk8 HOT 4
- Extend example with ZipkinSpanCollector HOT 1
- Hello,here is sidharth!!!
- WebMVC3 configuration not working with spring 5.1.2.RELEASE HOT 5
- Rename repo to brave-example and start publishing docker test images HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brave-example.