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 ¶
- func ALegID(ctx context.Context) string
- func EnsureCallDiag(ctx context.Context, traceID, aLegID string) context.Context
- func TraceID(ctx context.Context) string
- func WithALeg(ctx context.Context, aLegID string) context.Context
- func WithCallDiag(ctx context.Context, traceID, aLegID string) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- type TraceIDGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureCallDiag ¶
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 ¶
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 ¶
WithALeg returns a child context that carries the A-leg identifier for lineage diagnostics.
func WithCallDiag ¶
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.
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.