聊聊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
- 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 数组属性和方法
- CSS盒子模型
- SQL注入
- CSS实现垂直居中布局
- Js实现链表操作
- 性能优化漫谈(一):无代码调优
- C++职责链模式
- Newbe.Claptrap 框架入门,第四步 —— 利用 Minion,商品下单
- 使用 NextCloud + COS 搭建个人网盘
- Shader基础技巧整理
- 隐秘的物理粒子系统与渲染 !Cocos Creator LiquidFun !
- 一起用Gradle Transform API + ASM完成代码织入呀~
- 掩盖浏览痕迹不会被发现的方法【逗】
- webpack实战——样式预处理
- 前端防止浏览器访问旧版 js 和 css 的优化思路
- 少数派实测报告:AI巨无霸模型GPT-3 | 附送API 调用方法「AI核心算法」