Documentation ¶
Index ¶
- func Annotate(ctx context.Context) map[string]interface{}
- func CurrentSpanID(ctx context.Context) (spanID int64)
- func CurrentTraceID(ctx context.Context) (traceID int64)
- func Do(ctx context.Context, kind string, name string, act func(context.Context))
- func GenerateID(ctx context.Context) (int64, error)
- func Join(ctx context.Context, traceCtx context.Context) (context.Context, error)
- func Record(ctx context.Context, rec Recorder) (context.Context, error)
- func WithBuffer(ctx context.Context, buffer int) context.Context
- func WithContext(ctx context.Context, traceCtx context.Context) context.Context
- func WithLogger(ctx context.Context, logger Logger) context.Context
- func WithParentID(ctx context.Context, parentID int64) context.Context
- func WithProcess(ctx context.Context, process string) context.Context
- func WithTraceID(ctx context.Context, traceID int64) context.Context
- type Handler
- type Logger
- type Recorder
- type Span
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotate ¶
Annotate returns a map that can be used to store trace span-specific data if a trace is active in ctx. Otherwise it returns nil.
func CurrentSpanID ¶
CurrentSpanID returns the current span id if a trace is active in the context. Otherwise it returns 0.
func CurrentTraceID ¶
CurrentTraceID returns the current trace id if a trace is active in the context. Otherwise it returns 0.
func Do ¶
Do starts a new trace span if recording is active in the context. If a trace is already active in ctx then the new trace span continues under the existing trace id, otherwise a new trace id is generated.
The activity function act is always invoked, either with a new context representing a new trace span, or with the caller-provided ctx if recording is not active or an error occurs.
func GenerateID ¶
GenerateId returns a probablistically unique 64-bit id if a trace is active in ctx. All id values returned by this function will be positive integers. This may be useful for callers that want to generate their own id values.
func Join ¶
Join creates a new context that joins trace recording already in progress. If the original trace recording context is canceled then recording stops in all joined contexts. Cancellation of joined contexts has no effect on recording.
func Record ¶
Record starts trace recording in a context. If the context is canceled then trace recording stops.
func WithBuffer ¶
WithBuffer returns a new context.Context instance with a buffer depth included as a value. This buffer value is used when allocating internal channels for trace span recording.
func WithContext ¶
WithContext returns a new context.Context instance merging trace and parent id values from a context.Context where tracing is active.
func WithLogger ¶
WithLogger returns a new context.Context instance with a Logger as a value. This logger is used to log errors that occur during tracing.
func WithParentID ¶
WithParentID returns a new context.Context instance with a parent id included as a value. This may be used to override parent id determination when new trace spans are created.
func WithProcess ¶
WithProcess returns a new context.Context instance with a process identifier included as a value. This process identifier is used in all trace spans created from the new context.
Types ¶
type Handler ¶
type Handler struct { // Kind is the kind value used when starting new traces. Kind string // HeaderKey is the key used when ServeHTTP inserts an id header in requests or responses. HeaderKey string // HonorReqHeader determines whether or not ServeHTTP honors id headers in requests. HonorReqHeader bool // AddRespHeader determines whether or not ServeHTTP adds id headers to responses. AddRespHeader bool // contains filtered or unexported fields }
func NewHandler ¶
NewHandler creates a middleware handler that facilitates HTTP request tracing.
If the request contains an id header and HonorReqHeader is true, then the id values are used (allowing trace contexts to span services). Otherwise a new trace id is generated. An id header is optionally added to the response.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)
type Logger ¶
type Logger interface {
Println(v ...interface{})
}
Logger is an interface compatible with log.Logger.
type Span ¶
type Span struct { SpanID int64 `json:"span_id,string" yaml:"span_id"` TraceID int64 `json:"trace_id,string" yaml:"trace_id"` ParentID int64 `json:"parent_id,string" yaml:"parent_id"` Process string `json:"process,omitempty" yaml:",omitempty"` Kind string `json:"kind,omitempty" yaml:",omitempty"` Name string `json:"name,omitempty" yaml:",omitempty"` Start time.Time `json:"-" yaml:"-"` StartStr string `json:"start,omitempty" yaml:"start,omitempty"` Finish time.Time `json:"-" yaml:"-"` FinishStr string `json:"finish,omitempty" yaml:"finish,omitempty"` Data map[string]interface{} `json:"data,omitempty" yaml:",omitempty,inline"` }
Span tracks an activity within a trace. Note: YAML struct tags are included for backwards-compatibility with V1 code.