w3ctrace

package
v1.52.1-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxStateEntries is the maximum number of items in `tracestate` as defined by
	// https://www.w3.org/TR/trace-context/#tracestate-header-field-values
	MaxStateEntries = 32

	// TraceParentHeader is the W3C trace parent header name as defined by https://www.w3.org/TR/trace-context/
	TraceParentHeader = "traceparent"
	// TraceStateHeader is the W3C trace state header name as defined by https://www.w3.org/TR/trace-context/
	TraceStateHeader = "tracestate"
)
View Source
const VendorInstana = "in"

VendorInstana is the Instana vendor key in the `tracestate` list

Variables

View Source
var (
	// ErrContextNotFound is an error retuned by w3ctrace.Extract() if provided HTTP headers does not contain W3C trace context
	ErrContextNotFound = errors.New("no w3c context")
	// ErrContextCorrupted is an error retuned by w3ctrace.Extract() if provided HTTP headers contain W3C trace context in unexpected format
	ErrContextCorrupted = errors.New("corrupted w3c context")
	// ErrUnsupportedVersion is an error retuned by w3ctrace.Extract() if the version of provided W3C trace context is not supported
	ErrUnsupportedVersion = errors.New("unsupported w3c context version")
)

Functions

func Inject

func Inject(trCtx Context, headers http.Header)

Inject adds the w3c trace context headers, overriding any previously set values

func TracingHandlerFunc

func TracingHandlerFunc(handler http.HandlerFunc) http.HandlerFunc

TracingHandlerFunc is an HTTP middleware that forwards the W3C context found in request with the response

Types

type Context

type Context struct {
	RawParent string
	RawState  string
}

Context represents the W3C trace context

func Extract

func Extract(headers http.Header) (Context, error)

Extract extracts the W3C trace context from HTTP headers. Returns ErrContextNotFound if provided value doesn't contain traceparent header.

func New added in v1.13.0

func New(parent Parent) Context

New initializes a new W3C trace context from given parent

func (Context) IsZero added in v1.13.0

func (c Context) IsZero() bool

IsZero returns whether a context is a zero value

func (Context) Parent added in v1.12.1

func (c Context) Parent() Parent

Parent parses RawParent and returns the corresponding list. It silently discards malformed value. To check errors use ParseParent().

func (Context) State added in v1.12.1

func (c Context) State() State

State parses RawState and returns the corresponding list.

type Flags added in v1.12.1

type Flags struct {
	Sampled bool
}

Flags contains the trace flags as defined by https://www.w3.org/TR/trace-context/#trace-flags

type Parent added in v1.12.1

type Parent struct {
	Version  Version
	TraceID  string
	ParentID string
	Flags    Flags
}

Parent represents trace parent extracted from `traceparent` header

func ParseParent added in v1.12.1

func ParseParent(s string) (Parent, error)

ParseParent parses the value of `traceparent` header according to the version defined in the first field

func (Parent) String added in v1.12.1

func (p Parent) String() string

String returns string representation of a trace parent. The returned value is compatible with the `traceparent` header format

type State added in v1.12.1

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

State is list of key=value pairs representing vendor-specific data in the trace context

func FormStateWithInstanaTraceStateValue added in v1.42.1

func FormStateWithInstanaTraceStateValue(st State, instanaTraceStateValue string) State

FormStateWithInstanaTraceStateValue returns a new state prepended with the provided Instana value. If the original state had an Instana list member pair, it is discarded/overwritten.

func NewState added in v1.42.1

func NewState(listMembers []string, instanaTraceStateValue string) State

NewState creates a new State with the given values

func ParseState added in v1.12.1

func ParseState(traceStateValue string) State

ParseState parses the value of `tracestate` header. Empty list items are omitted.

func (State) FetchInstanaTraceStateValue added in v1.42.1

func (st State) FetchInstanaTraceStateValue() (string, bool)

FetchInstanaTraceStateValue retrieves the value of the Instana tracestate list member, if any.

func (State) String added in v1.12.1

func (st State) String() string

String returns string representation of a trace state. The returned value is compatible with the `tracestate` header format. If the state has an Instana-specific list member, that one is always rendered first. This is optimized for the use case of injecting the string representation of the tracestate header into downstream requests.

type Version added in v1.12.1

type Version uint8

Version represents the W3C trace context version. It defines the format of `traceparent` header

const (
	// Version_Invalid represend an invalid  W3C Trace Context version
	Version_Invalid Version = iota
	// Version_0 represent the W3C Trace Context version 00
	Version_0
	// Version_Max is the latest version of W3C Trace Context supported by this package
	Version_Max = Version_0
)

func ParseVersion added in v1.12.1

func ParseVersion(s string) (Version, error)

ParseVersion parses the version part of a `traceparent` header value. It returns ErrContextCorrupted if the version is malformed

func (Version) String added in v1.12.1

func (ver Version) String() string

String returns string representation of a trace parent version. The returned value is compatible with the `traceparent` header format. The caller should take care of handling the Version_Unknown, otherwise this method will return "ff" which is considered invalid

Jump to

Keyboard shortcuts

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