Documentation ¶
Index ¶
- Variables
- func InjectHTTPCarrier(span Span, req *http.Request) error
- func LogSpanError(span Span, message string, err error)
- func New(router *mux.Router) io.Closer
- func Trace(tracer opentracing.Tracer) mux.MiddlewareFunc
- func TraceWithConfig(config TraceConfig) mux.MiddlewareFunc
- type Span
- type TraceConfig
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTraceConfig is the default Trace middleware config. DefaultTraceConfig = TraceConfig{ ComponentName: defaultComponentName, IsBodyDump: false, } )
Functions ¶
func InjectHTTPCarrier ¶
InjectHTTPCarrier extracts trace ID from span and injects it into the http header.
func LogSpanError ¶
LogSpanError attaches message and error to the span.
func New ¶
New creates an Opentracing tracer and attaches it to mux middleware. Returns Closer do be added to caller function as `defer closer.Close()`
func Trace ¶
func Trace(tracer opentracing.Tracer) mux.MiddlewareFunc
Trace returns a Trace middleware. Trace middleware traces http requests and reporting errors.
func TraceWithConfig ¶
func TraceWithConfig(config TraceConfig) mux.MiddlewareFunc
TraceWithConfig returns a Trace middleware with config. See: `Trace()`.
Types ¶
type Span ¶
type Span interface { Finish() FinishWithOptions(opts opentracing.FinishOptions) Context() opentracing.SpanContext SetOperationName(operationName string) opentracing.Span SetTag(key string, value interface{}) opentracing.Span LogFields(fields ...log.Field) LogKV(alternatingKeyValues ...interface{}) SetBaggageItem(restrictedKey string, value string) opentracing.Span BaggageItem(restrictedKey string) string Tracer() opentracing.Tracer LogEvent(event string) LogEventWithPayload(event string, payload interface{}) Log(data opentracing.LogData) }
Span is copy of opentracing.Span interface. It helps us to wrap the opentracing.Span and expose the local span to other layers.
Span represents an active, un-finished span in the OpenTracing system. The function that create the span is responsible to finish it.
func CreateSpan ¶
CreateSpan creates a new opentracing span adding tags for the span name and caller details. It accepts a context and an operation name. The span will be attached to the context, in this way we can create a nested spans. The operation name can be a function name, service name, or application layer name.
User must call defer `sp.Finish()`
type TraceConfig ¶
type TraceConfig struct { // OpenTracing Tracer instance which should be got before Tracer opentracing.Tracer // ComponentName used for describing the tracing component name ComponentName string // Add req body & resp body to tracing tags IsBodyDump bool }
TraceConfig defines the config for Trace middleware.