trace

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package trace provides stable request trace and correlation middleware.

The middleware propagates request and trace identifiers through context and response headers so logs, Problem Details responses, and downstream calls can be correlated without coupling handlers to a tracing provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpanID

func GetSpanID(r *http.Request) string

GetSpanID returns the hex-encoded 8-byte span id if present.

func GetTraceID

func GetTraceID(r *http.Request) string

GetTraceID returns the hex-encoded 16-byte trace id if present.

func Use

func Use(opts Options) (func(http.Handler) http.Handler, error)

Use preserves the old helper-style API. Deprecated: use New(opts).Middleware() instead.

Types

type Middleware

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

Middleware attaches trace/span IDs to request context and sets response header.

func New

func New(opts Options) (*Middleware, error)

New constructs a Middleware with sane defaults.

func (*Middleware) Middleware

func (m *Middleware) Middleware() func(http.Handler) http.Handler

Middleware implements ports.Middleware by producing the handler adapter.

type Options

type Options struct {
	// TrustIncoming strictly validates client-provided traceparent and uses it
	// if valid. When false, the middleware always generates a fresh trace ID.
	TrustIncoming bool
	// SampledFlag defaults to 00 (not sampled). Set to 01 to enable sampling bit.
	SampledFlag byte
	// TraceIDGen overrides the trace id generator.
	TraceIDGen ports.IDGen
	// SpanIDGen overrides the span id generator.
	SpanIDGen ports.IDGen
}

Options controls middleware behaviour.

Jump to

Keyboard shortcuts

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