聊聊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
- 监听器第二篇【统计网站人数、自定义session扫描器、踢人小案例】
- 通俗易懂的分析如何用Python实现一只小爬虫,爬取拉勾网的职位信息
- JSP第一篇【JSP介绍、工作原理、生命周期、语法、指令、行为】
- 一条执行时间两天半的sql语句简化(r4笔记第62天)
- 05-01总结方法,数组(一维)
- 02 Java类的加载机制
- 权限管理系统
- 03 JVM的垃圾回收机制
- Tomcat就是这么简单
- Servlet第三篇【request和response介绍、response的常见应用】
- 通过java来格式化sql语句(r4笔记第61天)
- Servlet第四篇【request对象常用方法、应用】
- Servlet第五篇【介绍会话技术、Cookie的API、详解、应用】
- Java类加载器(用户自定义类加载器实现)
- 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 数组属性和方法
- Python堆糖网图片爬虫,多进程及多线程的使用例子
- Python Post提交简单案例,文本内容在线语音合成
- Python多线程爬虫,主播信息资料爬取采集
- 基于Tensorflow2 Lite在Android手机上实现图像分类
- Python知乎专栏爬虫,pdfkit专栏文章制作PDF电子书
- Python爬虫练手,一个简单的Python资讯采集案例
- Python与seo,百度关键词相关搜索关键词采集源码
- istio请求路由分析
- [剑指]2空格替换
- (补充)SPAN+AVISPA for Verifying Cryptographic Protocols
- 如何修改终端中$符号前面的一串名称?
- Alfred 有多强悍,我写了个一键上传图片的 workflow 来告诉你
- Peewee出错:Illegal mix of collations
- 【TOOLS】Linux环境下升级python2.7到python3.6
- 溯源黑帽利用 Web 编辑器漏洞非法植入 SEO 页面事件