聊聊dubbo-go的tracingFilter
时间:2022-07-22
本文章向大家介绍聊聊dubbo-go的tracingFilter,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
序
本文主要研究一下dubbo-go的tracingFilter
tracingFilter
dubbo-go-v1.4.2/filter/filter_impl/tracing_filter.go
const (
tracingFilterName = "tracing"
)
// this should be executed before users set their own Tracer
func init() {
extension.SetFilter(tracingFilterName, newTracingFilter)
opentracing.SetGlobalTracer(opentracing.NoopTracer{})
}
var (
errorKey = "ErrorMsg"
successKey = "Success"
)
// if you wish to using opentracing, please add the this filter into your filter attribute in your configure file.
// notice that this could be used in both client-side and server-side.
type tracingFilter struct {
}
- tracingFilter的init方法设置了newTracingFilter
newTracingFilter
dubbo-go-v1.4.2/filter/filter_impl/tracing_filter.go
func newTracingFilter() filter.Filter {
if tracingFilterInstance == nil {
tracingFilterInstance = &tracingFilter{}
}
return tracingFilterInstance
}
- newTracingFilter方法实例化tracingFilter
Invoke
dubbo-go-v1.4.2/filter/filter_impl/tracing_filter.go
func (tf *tracingFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
var (
spanCtx context.Context
span opentracing.Span
)
operationName := invoker.GetUrl().ServiceKey() + "#" + invocation.MethodName()
wiredCtx := ctx.Value(constant.TRACING_REMOTE_SPAN_CTX)
preSpan := opentracing.SpanFromContext(ctx)
if preSpan != nil {
// it means that someone already create a span to trace, so we use the span to be the parent span
span = opentracing.StartSpan(operationName, opentracing.ChildOf(preSpan.Context()))
spanCtx = opentracing.ContextWithSpan(ctx, span)
} else if wiredCtx != nil {
// it means that there has a remote span, usually from client side. so we use this as the parent
span = opentracing.StartSpan(operationName, opentracing.ChildOf(wiredCtx.(opentracing.SpanContext)))
spanCtx = opentracing.ContextWithSpan(ctx, span)
} else {
// it means that there is not any span, so we create a span as the root span.
span, spanCtx = opentracing.StartSpanFromContext(ctx, operationName)
}
defer func() {
span.Finish()
}()
result := invoker.Invoke(spanCtx, invocation)
span.SetTag(successKey, result.Error() != nil)
if result.Error() != nil {
span.LogFields(log.String(errorKey, result.Error().Error()))
}
return result
}
- Invoke方法首先构建operationName,然后使用opentracing.StartSpan开启span,之后defer执行span.Finish(),然后执行invoker.Invoke(spanCtx, invocation),最后设置span.SetTag及span.LogFields
OnResponse
dubbo-go-v1.4.2/filter/filter_impl/tracing_filter.go
func (tf *tracingFilter) OnResponse(ctx context.Context, result protocol.Result,
invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
- OnResponse方法直接返回result
小结
tracingFilter的Invoke方法首先构建operationName,然后使用opentracing.StartSpan开启span,之后defer执行span.Finish(),然后执行invoker.Invoke(spanCtx, invocation),最后设置span.SetTag及span.LogFields
doc
- tracing_filter
- 揭秘:针对中国移动用户的强大网银木马剖析
- 从源代码到Runtime发生的重排序编译器重排序指令重排序内存系统重排序阻止重排序
- 内存屏障保证缓存一致性优化
- 最新XSS 0day漏洞来袭,影响最新版本IE浏览器(含POC)
- Java内存模型—JMMhappens-before规则
- 那些年我们一起用过的Hybrid App
- 来看看美帝人民的安全意识:安全研究人员指责iOS版Outlook存在多处安全隐患
- 不是原配也可以-对接非原生配体
- oj放苹果
- 漏洞追踪:最新IE UXSS漏洞技术分析
- 如何使用Python超参数的网格搜索ARIMA模型
- int string相互转换
- Android 增量更新和升级
- web服务器集群集群是什么?分布式是什么?集中式是什么?例子缺点
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 图卷积网络-多标签分类
- MySQL parttion分区,以及分区和分表的区别
- ThreadPoolExcutor源码分析
- 动态分组卷积-Dynamic Group Convolution for Accelerating Convolutional Neural Networks
- (15)Shell概述及脚本执行方式
- jvm线上内存问题排查
- (18)Bash输入输出重定向
- RPC 和 REST还有RESTFul到底是个什么玩意?
- 线程和线程池的几个状态值
- 阿里代码规约为什么不让使用Executors包装好线程池呢?
- Groovy、热部署和热加载(自定义类加载器)及spring loaded 部分源码分析
- Centos在线迁移到腾讯云cvm
- ClickHouse源码导读:网络IO
- 手把手教你:将ClickHouse集群迁至云上
- 直播中台iLiveSDK终端框架演变之路