Documentation
¶
Overview ¶
Package trace is a light wrapper over the OpenTelemetry tracing API, modeled on Sourcegraph's internal/trace: one constructor bound to the global tracer provider and a Trace type that adds error helpers to the span.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Trace ¶
Trace is a light wrapper of oteltrace.Span. Use New to construct one.
func New ¶
func New(ctx context.Context, name string, opts ...oteltrace.SpanStartOption) (context.Context, Trace)
New starts a span under the global tracer provider and returns it with the derived context. Spans are children of the span in ctx, or roots when ctx carries none. Before telemetry.New runs, or when tracing is disabled, the global provider is a no-op, so callers never need a nil check. A nil ctx is treated as context.Background().
func (Trace) EndWithErr ¶
EndWithErr finishes the span and sets its error value. To run it deferred against a named return, wrap it in a closure so the final value of err is read:
ctx, span := trace.New(ctx, "op")
defer func() { span.EndWithErr(err) }()
Prefer a direct "defer span.End()" plus SetError where the control flow allows: the SDK's End records a panic as an exception event only when it is the deferred call itself.