tracing

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndSpan

func EndSpan(sp *Span, err error)

EndSpan finalises the span and records status depending on the provided error.

func Init

func Init(serviceName, serviceVersion, outputFile string) error

Init configures OpenTelemetry with the stdout exporter. If outputFile is an empty string the exporter uses os.Stdout; otherwise the traces are written to the specified file. The function is safe to call multiple times – the first successful initialisation wins. Init configures OpenTelemetry with the stdout exporter backed by either os.Stdout or the specified file. If outputFile is an empty string traces are written to os.Stdout. The function is safe to call multiple times – the first successful initialisation wins.

func InitWithExporter

func InitWithExporter(serviceName, serviceVersion string, exporter sdktrace.SpanExporter) error

InitWithExporter configures OpenTelemetry using the supplied SpanExporter. This allows callers to integrate with any exporter supported by the OpenTelemetry SDK (e.g. OTLP, Jaeger, Zipkin). The function is safe to call multiple times – the first successful initialisation wins.

func WithSpan

func WithSpan(ctx context.Context, sp *Span) context.Context

WithSpan attaches the OpenTelemetry span wrapped by *Span to the context.

func WithTrace

func WithTrace(ctx context.Context, _ *Trace) context.Context

WithTrace is retained purely for compatibility and presently returns the received context unchanged because OpenTelemetry does not require additional trace data to be stored inside the context by the callers.

Types

type Span

type Span struct {
	// contains filtered or unexported fields
}

Span wraps go.opentelemetry.io/otel/trace.Span so that the callers do not need to import the upstream package directly.

func SpanFromContext

func SpanFromContext(ctx context.Context) (*Span, bool)

SpanFromContext retrieves the *Span wrapper from the supplied context when present.

func StartSpan

func StartSpan(ctx context.Context, name, kind string) (context.Context, *Span)

StartSpan starts a new child span using OpenTelemetry. The string "kind" is mapped onto the appropriate trace.SpanKind value; when the mapping cannot be determined SpanKindInternal is used as a sensible default.

func (*Span) OnDone

func (s *Span) OnDone()

OnDone is kept for backward compatibility; in the OpenTelemetry world span.End() is used instead so this function simply calls End.

func (*Span) SetStatus

func (s *Span) SetStatus(err error)

SetStatus records an error status on the span. If err is nil an OK status is recorded instead.

func (*Span) SetStatusFromHTTPCode

func (s *Span) SetStatusFromHTTPCode(code int)

SetStatusFromHTTPCode sets the span’s status based on an HTTP response code.

func (*Span) WithAttributes

func (s *Span) WithAttributes(attrs map[string]string) *Span

WithAttributes attaches all provided attributes to the span.

type Trace

type Trace struct{}

Trace is kept only so that the public API of the package remains the same. It no longer contains any fields because OpenTelemetry manages traces internally. The value can be used as a marker by callers that still expect it.

func NewTrace

func NewTrace(serviceName, serviceVersion string) *Trace

NewTrace is retained for backward compatibility. It returns an empty *Trace and makes sure that the global tracer provider is initialised. The function is idempotent.

func TraceFromContext

func TraceFromContext(context.Context) (*Trace, bool)

TraceFromContext returns (nil, false) because Trace is no longer stored in the context; the function is provided so that callers continue to compile.

Jump to

Keyboard shortcuts

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