Comments (5)
对于需要自己生成TraceId和SpaceId的实践:
1、起始处增加如下代码:
SofaTraceContext sofaTraceContext=SofaTraceContextHolder.getSofaTraceContext();
SofaTracerSpan span = sofaTraceContext.getCurrentSpan();
if(span==null){//防止覆盖
span= (SofaTracerSpan) SpringMvcTracer.getSpringMvcTracerSingleton().getSofaTracer().buildSpan("testInjectSpan")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
sofaTraceContext.push(span);
}
2、结束处:
span.finish();
sofaTraceContext.pop();
from sofa-tracer.
异步处理还有一种更加简单的方式,用我们提供的工具类包装一下 Runnable 或者 Callable 就可以了。https://github.com/alipay/sofa-tracer/wiki/Async#%E5%BC%82%E6%AD%A5%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86
from sofa-tracer.
如果不是http产生的请求,而是自己产生的线程,有生成相应的TraceId 和 SpaceId的方法吗?
这个问题就相当于你是作为请求的第一个发起方,可以直接通过 OpenTracing 的方式构建一个 Span,可以类似这样去构建:
//开始,当然 this.sofaTracer 是需要继承构建好的实例,简单的可以看下 `com.alipay.sofa.tracer.plugins.springmvc.SpringMvcTracer` 构建方法
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
//结束
span.finish();
我这边手动往MDC里塞值,在rpc调用的时候会被冲掉;有什么不被冲掉的方法吗?
如果 MDC 对应打印的字段是这个文档描述的方式,那么在同一个线程中发生 RPC 调用时,在结束前都会是 RPC 根据你的当前 Span 构造的 Child Span,那么复写就是正常的。如果在 RPC 调用结束后或者开始 RPC 调用前自己向 MDC 中塞值是可以生效的。如果是作为服务引用方,那么可以在被引用的服务发生调用时,在方法前后进行复写 MDC ,但是我们一般不建议大家去覆盖默认的值,如果变为比较随意的值是不易于链路的“串联”的。
from sofa-tracer.
在切换线程的时候,通过拷贝threadlocal到新线程进行上下文传递,应该可以保证在新线程里面发起client调用调用时仍然可以获取到正确的trace信息。
from sofa-tracer.
ttl,思路是一样的
from sofa-tracer.
Related Issues (20)
- OpenFeign 10.7.3+版本兼容问题 HOT 1
- 不使用sofa boot,使用spring boot parent,依赖tracer-sofa-boot-starter时启动报错 HOT 6
- does support dubbo async invoke??? HOT 1
- Redis plugin未恢复paren span,导致span id的层级无限增长
- Open Source Promotion Plan 2022 - upgrade opentracing api version & adapter opentelemetry api HOT 5
- SofaTracer如何支持Agent接入方式 HOT 2
- spring cloud 3中的openfeign支持 HOT 2
- spring cloud gateway webflux集成问题 HOT 1
- 基于SOFAArk实现类加载器加载外置的SofaTracer的Spring Boot Starter插件 HOT 4
- datasource 模块如何记录完整的 sql 语句,包含参数的那种
- sofa-tracer-kafkamq-plugin支持ProducerListener解决方案 HOT 1
- sofatracer的tracerId不一定为30位 HOT 1
- sofa-tracer-httpclient-plugin使用httpclient连接池,请求发生异常时,内存泄漏,spanId无限变长 HOT 19
- CI failed in the master branch
- classNotFound SofaTracerLoadBalancedFeignClient HOT 1
- 是否支持 SOFA-TraceId 由前端生成放到header中请求
- sofa-tracer redis plugin未串联父span
- dubbo 2.7 使用问题 HOT 1
- feat: Delegate java.util.concurrent.Executor
- springboot v3 版本 启动报错 HOT 1
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 sofa-tracer.