opentracing

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 15 Imported by: 0

README

opentracing中间件使用方法

安装

go get github.com/hanguangbaihuo/sparrow_cloud_go

iris框架中zipkin追踪链使用方法

import "github.com/hanguangbaihuo/sparrow_cloud_go/middleware/opentracing"

func main() {
    // 追踪链配置:初始化GlobalTracer
	// 参数true是是否开启Debug模式,true会输出各种追踪链的log,生产环境请设置为false
	opentracing.InitZipkinTracer(true)

    // 初始化iris app
    app := iris.New()
    // 使用opentracing中间件,从header中提取父span,并存储至全局
    app.Use(opentracing.ZipkinServe("YourServiceName"))
    ...
}

iris框架中使用方法【v0.4版本后废弃】

import "github.com/hanguangbaihuo/sparrow_cloud_go/middleware/opentracing"

func main() {
    // 追踪链配置:初始化Jaeger为GlobalTracer
    // 初始化失败则程序直接结束
    closer := opentracing.InitGlobalTracer("YourServiceName")
    defer closer.Close()
    // 初始化iris app
    app := iris.New()
    // 使用opentracing中间件,从header中提取父span,并存储至中间件
    app.Use(opentracing.Serve("YourServiceName"))
    ...
}

注意

该中间件需要配合restclient包使用,才能实现链路追踪
restclient包的地址:github.com/hanguangbaihuo/sparrow_cloud_go/restclient

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActiveSpan opentracing.Span

ActiveSpan is global opentraing parent span, will be initialized in opentracing Serve function restclient use it to generate child span

View Source
var GlobalTracer *zipkin.Tracer

GlobalTracer is zipkin Tracer

View Source
var ZipkinSpan zipkin.Span

ZipkinSpan is span if the span-context that extract from incoming request header is not nil, ZipkinSpan will be child span of incoming else will be root span

Functions

func InitGlobalTracer

func InitGlobalTracer(serviceName string) io.Closer

InitGlobalTracer is for setting Global Tracer. you must do the function in main() function like follow:

closer := InitGlobalTracer("your_service_name")
defer closer.Close()

func InitZipkinTracer added in v0.4.0

func InitZipkinTracer(debug bool) *zipkin.Tracer

InitZipkinTracer is for initilize zipkin global Tracer function

func Serve

func Serve(operationName string) func(context.Context)

Serve is opentracing middleware function parameter operationName is a operaion name, usually named it service name

func ZipkinServe added in v0.4.0

func ZipkinServe(operationName string) func(context.Context)

Types

type Config added in v0.4.0

type Config struct {
	// Debug configure zipkin output
	// default false
	Debug bool
}

Config is zipkin Global Tracer configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL