perftrace

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package perftrace is the tracing hook for performance work in this repository. The library code calls Start at interesting points (a gotype operation, a transaction open, an FFI call, a decode). When no tracer is installed, Start costs one atomic load and returns a nil *Span, and every *Span method is a no-op on nil.

Only in-repository test code installs a tracer (see the otelperf package), so library users never see this package or its dependencies. Do not install a tracer for benchmarks: benchmark numbers must not include the cost of tracing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled

func Enabled() bool

Enabled reports whether a tracer is installed.

func Install

func Install(t Tracer) (uninstall func())

Install makes t the active tracer. The returned function restores the tracer that was active before, unless another Install replaced t since.

func RegisterGauge

func RegisterGauge(g Gauge)

RegisterGauge adds a gauge. Packages call it from init; the tracer reads the list when it is installed. Registration costs nothing at run time.

Types

type Attr

type Attr struct {
	Key  string
	Kind Kind
	Str  string
	Int  int64
}

Attr is one span attribute. It has no interface value, so building an Attr does not allocate.

func Bool

func Bool(key string, value bool) Attr

Bool returns a boolean attribute.

func Int

func Int(key string, value int) Attr

Int returns an integer attribute.

func String

func String(key, value string) Attr

String returns a string attribute.

type Gauge

type Gauge struct {
	Name        string
	Description string
	Read        func() int64
}

Gauge is a named int64 value that the tracer samples as a metric.

func Gauges

func Gauges() []Gauge

Gauges returns a copy of the registered gauges.

type Kind

type Kind uint8

Kind is the value type of an Attr.

const (
	KindString Kind = iota
	KindInt
	KindBool
)

The Attr value kinds.

type Span

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

Span is a span handle. A nil *Span is valid and records nothing.

func Start

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

Start starts a span. With no tracer installed it returns ctx and nil. A nil ctx is treated as context.Background.

func (*Span) End

func (s *Span) End(err error)

End ends s. A non-nil err marks the span as failed.

func (*Span) Recording

func (s *Span) Recording() bool

Recording reports whether s records anything. Build attributes only when it is true, so the disabled path does not allocate.

func (*Span) SetAttrs

func (s *Span) SetAttrs(attrs ...Attr)

SetAttrs adds attributes to s.

type SpanRecorder

type SpanRecorder interface {
	SetAttrs(attrs []Attr)
	End(err error)
}

SpanRecorder is one recording span of a Tracer.

type Tracer

type Tracer interface {
	// Start starts a span as a child of the span in ctx, if there is one.
	Start(ctx context.Context, name string) (context.Context, SpanRecorder)
}

Tracer is the backend that records spans.

Directories

Path Synopsis
Package otelperf connects perftrace to OpenTelemetry.
Package otelperf connects perftrace to OpenTelemetry.

Jump to

Keyboard shortcuts

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