tracectx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package tracectx holds W3C trace context: it parses and formats traceparent headers and carries the current span in a context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSpanID

func NewSpanID() (id [8]byte)

NewSpanID returns a random span ID.

func NewTraceID

func NewTraceID() (id [16]byte)

NewTraceID returns a random trace ID.

func With

With returns a copy of ctx carrying sc as the current span.

Types

type SpanContext

type SpanContext struct {
	TraceID [16]byte
	SpanID  [8]byte
	Sampled bool
}

SpanContext identifies a span within a trace.

func From

func From(ctx context.Context) (SpanContext, bool)

From returns the current span of ctx.

func Parse

func Parse(h string) (SpanContext, bool)

Parse parses a version-00 traceparent header. It returns false for anything else, so a malformed header starts a new trace instead of failing the request.

func (SpanContext) Traceparent

func (sc SpanContext) Traceparent() string

Traceparent formats sc as a version-00 traceparent header.

func (SpanContext) Valid

func (sc SpanContext) Valid() bool

Valid reports whether both IDs are non-zero.

Jump to

Keyboard shortcuts

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