Documentation
¶
Overview ¶
Package span provides small helpers for running functions inside OpenTelemetry spans.
Index ¶
- Variables
- func Call[T any](ctx context.Context, tracer trace.Tracer, name string, f Func1[T], ...) (ret T, err error)
- func Call2[T, U any](ctx context.Context, tracer trace.Tracer, name string, f Func2[T, U], ...) (ret T, ret2 U, err error)
- func Run(ctx context.Context, tracer trace.Tracer, name string, f Func, opts ...Option) (err error)
- type Func
- type Func1
- type Func2
- type Option
- func WithAttrs(attrs ...attribute.KeyValue) Option
- func WithErrorFilter(filter func(error) bool) Option
- func WithRecoverPanics() Option
- func WithSpanOptions(opts ...trace.SpanStartOption) Option
- func WithStackTrace(extract func(error) string) Option
- func WithoutErrorStatus() Option
- func WithoutRecordError() Option
- type PanicError
Constants ¶
This section is empty.
Variables ¶
var ErrNilFunc = errors.New("xtrace: nil span function")
Functions ¶
func Call ¶
func Call[T any](ctx context.Context, tracer trace.Tracer, name string, f Func1[T], opts ...Option) (ret T, err error)
Call is Run with one return value.
Types ¶
type Option ¶
type Option func(*options)
Option configures span helper behavior.
func WithErrorFilter ¶
WithErrorFilter decides which returned errors should be recorded on the span.
func WithRecoverPanics ¶
func WithRecoverPanics() Option
WithRecoverPanics converts a panic into a PanicError return value after recording it on the span. Without this option panics are recorded and re-panicked.
func WithSpanOptions ¶
func WithSpanOptions(opts ...trace.SpanStartOption) Option
WithSpanOptions appends OpenTelemetry span start options.
func WithStackTrace ¶ added in v1.1.5
WithStackTrace records the stack an error carries as the exception's exception.stacktrace: extract returns the stack captured where the error was made (e.g. by its wrapping package), or "" for none, and then no stacktrace is recorded — a stack taken at the span's end would only show the helper's own frames.
func WithoutErrorStatus ¶
func WithoutErrorStatus() Option
WithoutErrorStatus prevents setting span status to Error for returned errors.
func WithoutRecordError ¶
func WithoutRecordError() Option
WithoutRecordError prevents RecordError calls for returned errors.
type PanicError ¶
type PanicError struct {
Value any
}
PanicError is returned when WithRecoverPanics catches a panic.
func (PanicError) Error ¶
func (e PanicError) Error() string