opentracing

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 7 Imported by: 0

README

opentracing中间件使用方法

安装

go get github.com/hanguangbaihuo/sparrow_cloud_go

iris框架中使用方法

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

func main() {
    // 初始化iris app
    app := iris.New()
    // 使用opentracing中间件,从header中b3 headers,用于之后注入restclient请求头
    app.Use(opentracing.Serve)
    ...
}

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"))
    ...
}

注意

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalTracer *zipkin.Tracer

GlobalTracer is zipkin Tracer

View Source
var OpentracingInf map[string][]string

OpentracingInf saving opentracing information that incoming request header usually contain "x-request-id", "x-b3-traceid", "x-b3-spanid", "x-b3-parentspanid", "x-b3-sampled"... for having installed envoy kubernetes pods, only transmit the header to next pod is enough

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 InitZipkinTracer added in v0.4.0

func InitZipkinTracer(debug bool) *zipkin.Tracer

InitZipkinTracer is for initilize zipkin global Tracer function

func Serve

func Serve(ctx context.Context)

Serve is for saving incoming request header of b3

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