lineage

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package lineage A-leg/B-leg lineage identifiers and records.

Package lineage holds request-lineage context.Context values (trace, A-leg) and accessors without depending on github.com/matdev83/go-llm-interactive-proxy/internal/core/diag or github.com/matdev83/go-llm-interactive-proxy/internal/core/hooks so the hook runtime can import correlation helpers without creating import cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ALegID

func ALegID(ctx context.Context) string

ALegID returns the A-leg identifier from ctx, or empty string if unset.

func EnsureCallDiag

func EnsureCallDiag(ctx context.Context, traceID, aLegID string) context.Context

EnsureCallDiag behaves like WithCallDiag, but returns ctx unchanged when TraceID and ALegID already match traceID and aLegID (including legacy WithTraceID/WithALeg pairs).

If ctx is nil, the result is based on context.TODO (not context.Background) so call sites without cancellation are obvious in code review. APIs that require a request-scoped context should still validate non-nil context.Context at their boundary; do not rely on nil here for production traffic.

func TraceID

func TraceID(ctx context.Context) string

TraceID returns the trace identifier from ctx, or empty string if unset. Precedence: explicit LIP context (WithCallDiag, WithTraceID) over the OpenTelemetry W3C trace id so client X-Trace-ID and in-process correlation win in logs while OTLP export still uses the active span.

func WithALeg

func WithALeg(ctx context.Context, aLegID string) context.Context

WithALeg returns a child context that carries the A-leg identifier for lineage diagnostics.

func WithCallDiag

func WithCallDiag(ctx context.Context, traceID, aLegID string) context.Context

WithCallDiag attaches traceID and aLegID in one context layer (one allocation). Use on streaming hot paths instead of chaining WithTraceID and WithALeg. ctx must be non-nil for production call paths; use context.TODO only in tests.

func WithTraceID

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID returns a child context that carries traceID for diagnostics propagation.

Types

type TraceIDGenerator

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

TraceIDGenerator is a test-friendly, monotonically-increasing id generator.

func NewTraceIDGenerator

func NewTraceIDGenerator() *TraceIDGenerator

NewTraceIDGenerator returns a TraceIDGenerator with a zeroed counter.

func (*TraceIDGenerator) Next

func (g *TraceIDGenerator) Next() string

Next returns the next trace id, formatted as t_%08d.

Jump to

Keyboard shortcuts

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