tracing

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 13 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFromHTTPRequest

func ExtractFromHTTPRequest(req *http.Request, handlerName string) (opentracing.Span, *http.Request)

ExtractFromHTTPRequest gets a child span of the parent referenced in HTTP request headers. Returns the request with updated tracing context. Easier than adding this boilerplate everywhere.

func InfoFromContext

func InfoFromContext(ctx context.Context) (traceID string, sampled bool, found bool)

InfoFromContext returns the traceID and if it was sampled from the Jaeger span found in the given context. It returns whether a span associated to the context has been found.

func InfoFromSpan

func InfoFromSpan(span opentracing.Span) (traceID string, sampled bool, found bool)

InfoFromSpan returns the traceID and if it was sampled from the span, given it is a jaeger span. It returns whether a span associated to the context has been found.

func InjectToHTTPRequest

func InjectToHTTPRequest(span opentracing.Span, req *http.Request)

InjectToHTTPRequest adds tracing headers to an HTTP request. Easier than adding this boilerplate everywhere.

func LogError

func LogError(span opentracing.Span, err error) error

LogError adds a span log for an error. Returns unchanged error, so useful to wrap as in:

return 0, tracing.LogError(err)

func StartSpanFromContext

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

StartSpanFromContext is an improved opentracing.StartSpanFromContext. Uses the calling function as the operation name, and logs the filename and line number.

Passing nil context induces panic. Context without parent span reference triggers root span construction. This function never returns nil values.

Performance

This function incurs a small performance penalty, roughly 1000 ns/op, 376 B/op, 6 allocs/op. Jaeger timestamp and duration precision is only µs, so this is pretty negligible.

Alternatives

If this performance penalty is too much, try these, which are also demonstrated in benchmark tests:

// Create a root span
span := opentracing.StartSpan("operation name")
ctx := opentracing.ContextWithSpan(context.Background(), span)

// Create a child span
span := opentracing.StartSpan("operation name", opentracing.ChildOf(sc))
ctx := opentracing.ContextWithSpan(context.Background(), span)

// Sugar to create a child span
span, ctx := opentracing.StartSpanFromContext(ctx, "operation name")

func StartSpanFromContextWithOperationName

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

StartSpanFromContextWithOperationName is like StartSpanFromContext, but the caller determines the operation name.

Types

type Span

type Span struct {
	opentracing.Span

	Duration time.Duration
	// contains filtered or unexported fields
}

span is a simple wrapper around opentracing.Span in order to get access to the duration of the span for metrics reporting.

func StartSpanFromContextWithPromMetrics

func StartSpanFromContextWithPromMetrics(ctx context.Context, operationName string, hist prometheus.Observer, gauge prometheus.Gauge, opts ...opentracing.StartSpanOption) (*Span, context.Context)

func (*Span) Finish

func (s *Span) Finish()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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