Documentation ¶
Index ¶
- func ExtractFromHTTPRequest(req *http.Request, handlerName string) (opentracing.Span, *http.Request)
- func InfoFromContext(ctx context.Context) (traceID string, sampled bool, found bool)
- func InfoFromSpan(span opentracing.Span) (traceID string, sampled bool, found bool)
- func InjectToHTTPRequest(span opentracing.Span, req *http.Request)
- func LogError(span opentracing.Span, err error) error
- func StartSpanFromContext(ctx context.Context) (opentracing.Span, context.Context)
- func StartSpanFromContextWithOperationName(ctx context.Context, operationName string) (opentracing.Span, context.Context)
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 ¶
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 ¶
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 ¶
InjectToHTTPRequest adds tracing headers to an HTTP request. Easier than adding this boilerplate everywhere.
func LogError ¶
LogError adds a span log for an error. Returns unchanged error, so useful to wrap as in:
return 0, tracing.LogError(err)
func StartSpanFromContext ¶
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")
Types ¶
This section is empty.