trace

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 11 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

trace

框架支持 opentracing,默认集成 jaeger。

如果想开启 jaeger 收集 opentracing 数据,需要以下配置:

  • JAEGER_AGENT_HOST jaeger 服务器IP或域名,默认为 127.0.0.1
  • JAEGER_AGENT_PORT jaeger 服务器端口,默认为 6831
  • JAEGER_SAMPLER_PARAM 采样率,0-1 之间的浮点数,默认为0,也就是不采集

个人开发环境可以使用 docker 体验:

docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -p 5775:5775/udp \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 14268:14268 \
  -p 14250:14250 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.25

启动后访问 http://127.0.0.1:16686 即可打开查询界面。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDuration added in v1.3.2

func GetDuration(span opentracing.Span) time.Duration

GetDuration 查询当前 span 耗时

func GetTraceID

func GetTraceID(ctx context.Context) (traceID string)

GetTraceID 查询 trace_id

func InjectTraceHeader

func InjectTraceHeader(ctx opentracing.SpanContext, req *http.Request)

InjectTrace 注入 OpenTracing 头信息

func StartFollowSpanFromContext added in v1.3.0

func StartFollowSpanFromContext(ctx context.Context, operation string) (opentracing.Span, context.Context)

StartFollowSpanFromContext 开起一个 follow 类型 span follow 类型用于异步任务,可能在 root span 结束之后才完成。

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context)

StartSpanFromContext starts and returns a Span with `operationName`, using any Span found within `ctx` as a ChildOfRef. If no such parent could be found, StartSpanFromContext creates a root (parentless) Span.

The second return value is a context.Context object built around the returned Span.

Example usage:

SomeFunction(ctx context.Context, ...) {
    sp, ctx := opentracing.StartSpanFromContext(ctx, "SomeFunction")
    defer sp.Finish()
    ...
}

func StartSpanServerHTTP

func StartSpanServerHTTP(r *http.Request, operation string) (req *http.Request, span opentracing.Span)

StartSpanServerHTTP 启动http服务的span

func Stop

func Stop()

Stop 停止 trace 协程

Types

This section is empty.

Jump to

Keyboard shortcuts

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