trace

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, t *RequestTrace) context.Context

func NewSpanContext

func NewSpanContext(ctx context.Context, s *Span) context.Context

NewSpanContext carries an active span so downstream code (e.g. the MCP composer) can annotate it without re-discovering it from the trace.

Types

type LLMAttrs

type LLMAttrs struct {
	RegistryID     string
	Provider       string
	Model          string
	SentModel      string
	RequestedModel string
	FinishReason   string
	TurnID         string
	Attempt        int
	Fallback       bool
	Pinned         bool
	Route          string
	Outcome        string
	Usage          *adapter.CanonicalUsage
}

type MCPAttrs

type MCPAttrs struct {
	Method         string
	Operation      string
	ServerName     string
	RegistryID     string
	Host           string
	CatalogCode    string
	Transport      string
	Tool           string
	UpstreamTool   string
	Prompt         string
	ResourceURI    string
	Targets        int
	UpstreamStatus string
	RPCErrorCode   int
}

type Metadata

type Metadata struct {
	GatewayID    string
	TeamID       string
	ConsumerID   string
	ConsumerName string
	Path         string
	Method       string
	IP           string
	SessionID    string
	Kind         string
}

type PluginAttrs

type PluginAttrs struct {
	Stage      string
	Mode       string
	Decision   string
	Score      *float64
	ScoreLabel string
	Extras     any
}

type RequestTrace

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

func FromContext

func FromContext(ctx context.Context) *RequestTrace

func New

func New(traceID string, meta Metadata) *RequestTrace

func (*RequestTrace) AddAsync

func (t *RequestTrace) AddAsync()

AddAsync registers asynchronous work (a detached span) that must complete before the trace is published. Pair every AddAsync with a Done.

func (*RequestTrace) AddSpan

func (t *RequestTrace) AddSpan(s *Span) *Span

func (*RequestTrace) Done

func (t *RequestTrace) Done()

Done releases one unit of outstanding work (the request hold or an async span). The last Done fires OnComplete exactly once.

func (*RequestTrace) End

func (t *RequestTrace) End()

func (*RequestTrace) EndedAt

func (t *RequestTrace) EndedAt() time.Time

func (*RequestTrace) LLMUsage

func (t *RequestTrace) LLMUsage() *adapter.CanonicalUsage

func (*RequestTrace) Metadata

func (t *RequestTrace) Metadata() Metadata

func (*RequestTrace) ObserveLLMResult

func (t *RequestTrace) ObserveLLMResult(model, finishReason string)

func (*RequestTrace) ObserveLLMTurnID

func (t *RequestTrace) ObserveLLMTurnID(turnID string)

func (*RequestTrace) ObserveLLMUsage

func (t *RequestTrace) ObserveLLMUsage(u *adapter.CanonicalUsage)

func (*RequestTrace) OnComplete

func (t *RequestTrace) OnComplete(fn func())

OnComplete registers the callback fired once the request and all of its asynchronous spans (e.g. post_response plugins) have finished. It must be set before the request hold is released via Done.

func (*RequestTrace) PluginTracesEnabled

func (t *RequestTrace) PluginTracesEnabled() bool

func (*RequestTrace) RequestTracesEnabled

func (t *RequestTrace) RequestTracesEnabled() bool

func (*RequestTrace) SetConsumer

func (t *RequestTrace) SetConsumer(id, name string)

func (*RequestTrace) SetGating

func (t *RequestTrace) SetGating(requestTraces, pluginTraces bool)

func (*RequestTrace) SetStatusReason

func (t *RequestTrace) SetStatusReason(reason string)

func (*RequestTrace) Spans

func (t *RequestTrace) Spans() []*Span

func (*RequestTrace) StartSpan

func (t *RequestTrace) StartSpan(spanType SpanType, name string) *Span

func (*RequestTrace) StartedAt

func (t *RequestTrace) StartedAt() time.Time

func (*RequestTrace) StatusReason

func (t *RequestTrace) StatusReason() string

func (*RequestTrace) TraceID

func (t *RequestTrace) TraceID() string

type Span

type Span struct {
	ID        string
	ParentID  string
	Type      SpanType
	Name      string
	StartedAt time.Time

	LLM    *LLMAttrs
	Plugin *PluginAttrs
	MCP    *MCPAttrs
	// contains filtered or unexported fields
}

func SpanFromContext

func SpanFromContext(ctx context.Context) *Span

func (*Span) End

func (s *Span) End()

func (*Span) EndedAt

func (s *Span) EndedAt() time.Time

func (*Span) Error

func (s *Span) Error() string

func (*Span) HasDecision

func (s *Span) HasDecision() bool

func (*Span) LLMAttrsCopy

func (s *Span) LLMAttrsCopy() (LLMAttrs, bool)

func (*Span) Latency

func (s *Span) Latency() time.Duration

func (*Span) MCPAttrsCopy

func (s *Span) MCPAttrsCopy() (MCPAttrs, bool)

func (*Span) ObserveUsage

func (s *Span) ObserveUsage(u *adapter.CanonicalUsage)

func (*Span) PluginAttrsCopy

func (s *Span) PluginAttrsCopy() PluginAttrs

func (*Span) SetDecision

func (s *Span) SetDecision(decision string)

func (*Span) SetError

func (s *Span) SetError(msg string)

func (*Span) SetExtras

func (s *Span) SetExtras(extras any)

func (*Span) SetLLMResult

func (s *Span) SetLLMResult(model, finishReason string)

func (*Span) SetLatency

func (s *Span) SetLatency(d time.Duration)

func (*Span) SetMCPRequest

func (s *Span) SetMCPRequest(method, operation, tool, prompt, resourceURI string)

func (*Span) SetMCPStatus

func (s *Span) SetMCPStatus(status string, rpcErrorCode int)

func (*Span) SetMCPTargets

func (s *Span) SetMCPTargets(targets int)

func (*Span) SetMCPUpstream

func (s *Span) SetMCPUpstream(serverName, registryID, host, catalogCode, transport, upstreamTool, status string)

func (*Span) SetMode

func (s *Span) SetMode(mode string)

func (*Span) SetScore

func (s *Span) SetScore(score float64, label string)

func (*Span) SetStage

func (s *Span) SetStage(stage string)

func (*Span) SetStatusCode

func (s *Span) SetStatusCode(code int)

func (*Span) SetTurnID

func (s *Span) SetTurnID(turnID string)

func (*Span) StatusCode

func (s *Span) StatusCode() int

func (*Span) Usage

func (s *Span) Usage() *adapter.CanonicalUsage

type SpanType

type SpanType string
const (
	SpanLLM    SpanType = "llm"
	SpanMCP    SpanType = "mcp"
	SpanA2A    SpanType = "a2a"
	SpanPlugin SpanType = "plugin"
)

Jump to

Keyboard shortcuts

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