IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

聊聊dubbo-go的tracingFilter

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

本文主要研究一下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

文章永久链接:https://tech.souyunku.com/?p=25956


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(74) 打赏



未经允许不得转载:搜云库技术团队 » 聊聊dubbo-go的tracingFilter

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367