span

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package span provides small helpers for running functions inside OpenTelemetry spans.

Index

Constants

This section is empty.

Variables

View Source
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.

func Call2

func Call2[T, U any](ctx context.Context, tracer trace.Tracer, name string, f Func2[T, U], opts ...Option) (ret T, ret2 U, err error)

Call2 is Run with two return values.

func Run

func Run(ctx context.Context, tracer trace.Tracer, name string, f Func, opts ...Option) (err error)

Run starts name on tracer, executes f, records returned errors, and ends the span. A nil tracer falls back to the global OpenTelemetry tracer.

Types

type Func

type Func func(ctx context.Context, span trace.Span) error

Func is a function executed with a started span.

type Func1

type Func1[T any] func(ctx context.Context, span trace.Span) (T, error)

Func1 is a function executed with a started span and one return value.

type Func2

type Func2[T, U any] func(ctx context.Context, span trace.Span) (T, U, error)

Func2 is a function executed with a started span and two return values.

type Option

type Option func(*options)

Option configures span helper behavior.

func WithAttrs

func WithAttrs(attrs ...attribute.KeyValue) Option

WithAttrs starts the span with the provided attributes.

func WithErrorFilter

func WithErrorFilter(filter func(error) bool) Option

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 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL