trace

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: LGPL-3.0 Imports: 4 Imported by: 0

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

type Trace struct {
	oteltrace.Span // never nil
}

Trace is a light wrapper of oteltrace.Span. Use New to construct one.

func New

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

func (t Trace) EndWithErr(err error)

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.

func (Trace) SetError

func (t Trace) SetError(err error)

SetError declares that this span resulted in an error. A nil err is a no-op.

Jump to

Keyboard shortcuts

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