jaeger

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0 Imports: 16 Imported by: 4

README

概述

为mosn加入jaeger trace的链路追踪功能。

项目结构

  • mosn
    • pkg
      • trace
        • jaeger

启动

二开逻辑: 1、在项目启动时,我们需要把jaeger插件注册进mosn的trace driver中。因此在mosn/pkg/trace/jaeger/driver.go中注册driver

const (
	JaegerDriverName = "jaeger"
)

func init() {
	trace.RegisterDriver(DriverName, NewJaegerImpl())
}

然后需要在mosn的启动文件中引入这个包mosn/cmd/mosn/main/mosn.go

import (
    _ "mosn.io/mosn/pkg/trace/jaeger"
)

2、把关键数据inject入jaeger的span中

查看mosn/pkg/trace/jaeger/span.go文件,如果想要添加额外的数据,则可以修改下面的函数就可以

//SetRequestInfo 把当前请求相关信息放入span中
func (s *Span) SetRequestInfo(reqinfo api.RequestInfo) {
	span := s.jaegerSpan
	span.SetTag("request_size", reqinfo.BytesReceived())
	span.SetTag("response_size", reqinfo.BytesSent())
	if reqinfo.UpstreamHost() != nil {
		span.SetTag("upstream_host_address", reqinfo.UpstreamHost().AddressString())
	}
	if reqinfo.DownstreamLocalAddress() != nil {
		span.SetTag("downstream_host_address", reqinfo.DownstreamRemoteAddress().String())
	}

	code := reqinfo.ResponseCode()
	span.SetTag("http.status_code", code)

	if isErrorResponse(code) {
		span.SetTag("error", true)
		span.SetTag("error.message", http.StatusText(code))
	}
	span.SetTag("mosn_process_time", reqinfo.ProcessTimeDuration().String())
}

jaeger管理后台截图 alt screenshots

3、实际使用 然后我们在项目启动的配置文件中配置使用jaeger就可以了。例子如下:

{
    "tracing": {
        "enable": true,                            //是否启动tracing功能
        "driver": "jaeger",                        //driver选择jaeger
        "config": {
            "service_name": "sample_sidecar",      //当前sidecar上报到jaeger的服务名称,建议【应用服务名_sidecar】,不设置则默认值为:default_sidecar
            "agent_host": "127.0.0.1:6831"       //当前jaeger agent的地址,不设置则默认值为:0.0.0.0:6831
        }
    },
}

Documentation

Index

Constants

View Source
const (
	DriverName          = "jaeger"
	HeaderRouteMatchKey = "service"
)

Variables

This section is empty.

Functions

func NewJaegerImpl

func NewJaegerImpl() api.Driver

NewJaegerImpl create jaeger driver

func NewTracer

func NewTracer(traceCfg map[string]interface{}) (api.Tracer, error)

NewTracer create new jaeger

Types

type HTTPHeadersCarrier

type HTTPHeadersCarrier http.RequestHeader

HTTPHeadersCarrier

func (HTTPHeadersCarrier) ForeachKey

func (c HTTPHeadersCarrier) ForeachKey(handler func(key, val string) error) error

ForeachKey conforms to the HTTPHeadersCarrier interface.

type Span

type Span struct {
	// contains filtered or unexported fields
}

func (*Span) FinishSpan

func (s *Span) FinishSpan()

FinishSpan submit span info to agent

func (*Span) InjectContext

func (s *Span) InjectContext(requestHeaders api.HeaderMap, requestInfo api.RequestInfo)

func (*Span) ParentSpanId

func (s *Span) ParentSpanId() string

func (*Span) SetOperation

func (s *Span) SetOperation(operation string)

func (*Span) SetRequestInfo

func (s *Span) SetRequestInfo(reqinfo api.RequestInfo)

SetRequestInfo record current request info to Span

func (*Span) SetTag

func (s *Span) SetTag(key uint64, value string)

func (*Span) SpanId

func (s *Span) SpanId() string

func (*Span) SpawnChild

func (s *Span) SpawnChild(operationName string, startTime time.Time) api.Span

func (*Span) Tag

func (s *Span) Tag(key uint64) string

func (*Span) TraceId

func (s *Span) TraceId() string

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

func (*Tracer) Start

func (t *Tracer) Start(ctx context.Context, request interface{}, startTime time.Time) api.Span

Start init span

Jump to

Keyboard shortcuts

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