trace

package
v0.0.0-...-6700e38 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package trace manages execution traces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ID

func ID(ctx context.Context) string

ID returns the trace id.

func NewContext

func NewContext(ctx context.Context, t *Context) context.Context

NewContext returns new context with a trace context.

Types

type Context

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

Context is a trace context.

func New

func New(ctx context.Context, id string) *Context

New creates a new context for id (uuid).

func (*Context) NewSpan

func (t *Context) NewSpan(ctx context.Context, name string, parent *Span) *Span

NewSpan creates new span in the parent.

func (*Context) SpanProtos

func (t *Context) SpanProtos(ctx context.Context, projectID string) []*tracepb.Span

SpanProtos returns span protos in the trace context.

func (*Context) Spans

func (t *Context) Spans() []SpanData

Spans returns span data in the trace context.

type Exporter

type Exporter struct {
	ProjectID   string
	ServiceName string
	// contains filtered or unexported fields
}

Exporter is trace exporter.

func NewExporter

func NewExporter(ctx context.Context, opts Options) (*Exporter, error)

NewExporter creates new trace exporter.

func (*Exporter) Close

func (e *Exporter) Close(ctx context.Context)

Close flushes all pending traces and closes the exporter.

func (*Exporter) Export

func (e *Exporter) Export(ctx context.Context, tc *Context)

Export exports a trace.

type Options

type Options struct {
	ProjectID string

	ServiceName string

	// threshold of step duration to export.
	// it will not export step trace if step duration is less than this.
	StepThreshold time.Duration

	// threshold of span duration to export.
	// it will not export span trace if span duration is less than this.
	SpanThreshold time.Duration
	ClientOptions []option.ClientOption
}

Options is options for trace exporter.

type Span

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

Span is a trace span.

func CurSpan

func CurSpan(ctx context.Context) *Span

CurSpan returns current span in the context.

func NewSpan

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

NewSpan returns new contexts and span. If no trace context, returns nil span.

func (*Span) Add

func (s *Span) Add(ctx context.Context, sd SpanData) *Span

Add adds span data as a child of the span and returns it.

func (*Span) Close

func (s *Span) Close(st *spb.Status)

Close closes the span.

func (*Span) ID

func (s *Span) ID(projectID string) (trace, span string)

ID returns trace and span id.

func (*Span) SetAttr

func (s *Span) SetAttr(key string, value any)

SetAttr sets attributes in the span.

type SpanData

type SpanData struct {
	Name   string
	Start  time.Time
	End    time.Time
	Attrs  map[string]any
	Status *spb.Status
}

SpanData is a span data.

func (SpanData) Duration

func (sd SpanData) Duration() time.Duration

Duration returns duration of the span.

func (SpanData) NameKind

func (sd SpanData) NameKind() string

NameKind returns span name's kind. It drops resource capacity for semaphore span.

Jump to

Keyboard shortcuts

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