tracing

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 8 Imported by: 7

README

GO-TRACING

Build Status Coverage Status Go Report Card

Go-tracing provides an easy way to use jeager tracing with only four lines of code.

Quick start

// import the library
import "github.com/ricardo-ch/go-tracing"

// set your tracer
tracing.SetGlobalTracer(appName, "{zipkin_url}")
defer tracing.FlushCollector()

// define a trace
span, ctx := tracing.CreateSpan(ctx, "{span_name}", nil)
defer span.Finish()

Examples

make run-jaeger
go run examples/basic/main.go
go run examples/httpServer/main.go
go run examples/httpServer-middleware/main.go
go run examples/httpGoKit-middleware/main.go

To watch traces you just have to hit http://localhost:16686/search

Examples declare the envar they need in the code (e.g.: os.Setenv("JAEGER_AGENT_HOST", "localhost")), but technically, if using jaeger you are supposed to properly declare envar outside of the code. See list there

Features

  • Create span from nothing
  • Create span from context
  • Extract/Inject span from/to httpRequest
  • Extract/Inject span from/to a map[string]string (textMapCarrier)
  • Declare an error span

License

go-tracing is licensed under the MIT license. (http://opensource.org/licenses/MIT)

Contributing

Pull requests are the way to help us here. We will be really grateful.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSpan

func CreateSpan(ctx context.Context, spanName string, tags *map[string]interface{}) (opentracing.Span, context.Context)

CreateSpan ...

func CreateSpanFromClientContext

func CreateSpanFromClientContext(r *http.Request, spanName string, tags *map[string]interface{}) (opentracing.Span, context.Context)

CreateSpanFromClientContext ...

func ExtractFromCarrier

func ExtractFromCarrier(ctx context.Context, carrier opentracing.TextMapCarrier, spanName string, tags *map[string]interface{}) (opentracing.Span, context.Context)

ExtractFromCarrier returns a span with context passed by the carrier ctx should not already have span in it

func FlushCollector

func FlushCollector()

func GetGlobalTracer

func GetGlobalTracer() opentracing.Tracer

func GotKitEndpointMiddleWare added in v0.2.0

func GotKitEndpointMiddleWare(operationName string) endpoint.Middleware

GotKitEndpointMiddleWare returns a gokit.Middleware which change the behavior of a gokit.endpoint it had tracing capability

func HTTPMiddleware

func HTTPMiddleware(operationName string, next http.Handler) http.Handler

HTTPMiddleware returns a Middleware that injects an OpenTracing Span found in context into the HTTP Headers.

func InjectIntoCarrier

func InjectIntoCarrier(ctx context.Context) opentracing.TextMapCarrier

InjectIntoCarrier returns a textMapCarrier, basically a map[string]string,

which can be used to transmit a span context to another service with ExtractFromCarrier

func InjectSpan

func InjectSpan(r *http.Request, options ...TraceOptions) *http.Request

InjectSpan ...

func SetGlobalTracer

func SetGlobalTracer(options ...tracerOption) error

func SetSpanError

func SetSpanError(span opentracing.Span, err error)

SetSpanError ...

func UsingJaeger added in v0.3.3

func UsingJaeger() tracerOption

Pass UsingJaeger's result as argument to SetGlobalTracer to set Jaeger as your tracing system This is the default behavior

Types

type TraceOptions added in v0.3.2

type TraceOptions func(*httptrace.ClientTrace, opentracing.Span)

TraceOptions represents the options of a ClientTrace

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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