phase

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package phase records one tracing span per phase of a long, sequential operation.

It deliberately lives outside the parent traces package, which pulls in the OTLP exporters: the packages that instrument their phases should not gain a dependency on the exporters to do it. Only the OpenTelemetry API is used here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracker

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

Tracker records one child span per phase of a long, sequential operation such as a translation, so that its total duration can be attributed to a phase instead of being reported as one opaque span.

The phases run one after another, so a single span is in flight at any time:

phases := phase.NewTracker(ctx, tracer)
defer phases.EndInFlight()

phases.Start("Translator.processRoutes", attribute.Int("routes.count", len(routes)))
processRoutes(routes)
phases.End()

Phase spans stay flat: Start does not hand back the phase's context, so a span started inside a phase parents to the enclosing span, not to the phase.

func NewTracker

func NewTracker(ctx context.Context, tracer trace.Tracer) *Tracker

NewTracker returns a tracker that starts its phase spans as children of the span in ctx.

func (*Tracker) End

func (p *Tracker) End()

End ends the phase span started by the last call to Start.

func (*Tracker) EndInFlight

func (p *Tracker) EndInFlight()

EndInFlight ends a phase span that was started but never ended, marking it as incomplete. Deferring it keeps the phase visible when the operation panics: a panicking phase is exactly the one an operator needs to see, and an unended span is never exported.

func (*Tracker) Start

func (p *Tracker) Start(name string, attrs ...attribute.KeyValue)

Start begins a phase span. The attrs are meant to record the size of the input the phase is about to process: without them a slow run cannot be told apart from a run over a bigger input.

Jump to

Keyboard shortcuts

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