Documentation ¶
Overview ¶
Package trace provides a tracing API that in turn invokes both the `golang.org/x/net/trace` API and creates an opentracing span if appropriate.
This is similar to the github.com/sourcegraph/sourcegraph/internal/trace package in the main repo, and it may make sense to factor both out into a common package at some point.
Index ¶
- func ContextWithTrace(ctx context.Context, tr *Trace) context.Context
- func GetOpenTracer(ctx context.Context, tracer opentracing.Tracer) opentracing.Tracer
- func Printf(key, f string, args ...interface{}) log.Field
- func StartSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context)
- func StartSpanFromContextWithTracer(ctx context.Context, tracer opentracing.Tracer, operationName string, ...) (opentracing.Span, context.Context)
- func WithOpenTracingEnabled(ctx context.Context, enableOpenTracing bool) context.Context
- type Trace
- type Tracer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTrace ¶
ContextWithTrace returns a new context.Context that holds a reference to trace's SpanContext.
func GetOpenTracer ¶
GetOpenTracer returns the tracer to actually use depending on whether isOpenTracingEnabled(ctx) returns true or false. If false, this returns the NoopTracer.
func Printf ¶
Printf is an opentracing log.Field which is a LazyLogger. So the format string will only be evaluated if the trace is collected. In the case of net/trace, it will only be evaluated on page load.
func StartSpanFromContext ¶
func StartSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context)
StartSpanFromContext starts a span using the tracer returned by GetOpenTracer.
func StartSpanFromContextWithTracer ¶
func StartSpanFromContextWithTracer(ctx context.Context, tracer opentracing.Tracer, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context)
StartSpanFromContext starts a span using the tracer returned by invoking GetOpenTracer with the passed-in tracer.
Types ¶
type Trace ¶
type Trace struct {
// contains filtered or unexported fields
}
Trace is a combined version of golang.org/x/net/trace.Trace and opentracing.Span. Use New to construct one.
func TraceFromContext ¶
TraceFromContext returns the Trace previously associated with ctx, or nil if no such Trace could be found.
func (*Trace) Finish ¶
func (t *Trace) Finish()
Finish declares that this trace and span is complete. The trace should not be used after calling this method.
func (*Trace) LazyPrintf ¶
LazyPrintf evaluates its arguments with fmt.Sprintf each time the /debug/requests page is rendered. Any memory referenced by a will be pinned until the trace is finished and later discarded.