Documentation
¶
Overview ¶
Package telemetry ports Pi's explicit-parent, callback-scoped telemetry to Go. The zero Context is inert; NewInMemory records span snapshots. It has no dependency on a JavaScript runtime or on the application.
Index ¶
- Constants
- func BindSafeOrigin(ctx context.Context, origin SafeOrigin, category SafeCategory) context.Context
- func DetachSafeExecution(ctx context.Context, category SafeCategory) context.Context
- func ReconcileSafe(ctx context.Context, accounting SafeAccounting)
- func SafeFailureKind(s string) string
- func StartSpan[T any](c Context, options SpanOptions, callback func(*Span) (T, error)) (value T, err error)
- func StartSpanFrom[T any](c Context, read func() SpanOptions, callback func(*Span) (T, error)) (value T, err error)
- func StartTypedSpan[T any](starter SpanStarter, name string, attributes Attributes, ...) (value T, err error)
- func StringifyValue(value any) ([]byte, error)
- func WithContext(ctx context.Context, parent Context) context.Context
- func WithRecordingParent(ctx context.Context, parent Context) context.Context
- func WithSafeCategory(ctx context.Context, category SafeCategory) context.Context
- func WithSafeObserver(ctx context.Context, observer *SafeObserver, execution SafeExecution) (context.Context, error)
- func WithoutSafeOrigin(ctx context.Context) context.Context
- type Array
- type AttributeDefinition
- type Attributes
- type Context
- type ContextCallbacks
- type Drops
- type ErrorDetails
- func (e *ErrorDetails) Error() string
- func (e ErrorDetails) MarshalJSON() ([]byte, error)
- func (e ErrorDetails) MessageValue() any
- func (e ErrorDetails) NameValue() any
- func (e *ErrorDetails) SetMessageValue(value any)
- func (e *ErrorDetails) SetNameValue(value any)
- func (e *ErrorDetails) UnmarshalJSON(data []byte) error
- type EventAttributeDefinition
- type EventDefinition
- type InMemory
- type JSONMethod
- type Limits
- type Object
- type ParentDefinition
- type Property
- type RecordedEvent
- type RecordedSpan
- type SafeAccounting
- type SafeAggregate
- type SafeAttempt
- func (a *SafeAttempt) Finish(status, failureKind string, accounting SafeAccounting)
- func (a *SafeAttempt) FinishAdmission(status, failureKind string, accounting SafeAccounting, provider, model string, ...)
- func (a *SafeAttempt) FinishModel(status, failureKind string, accounting SafeAccounting, provider, model string)
- type SafeCall
- type SafeCategory
- type SafeExecution
- type SafeHealth
- type SafeLabels
- type SafeObserver
- type SafeObserverOptions
- type SafeOrigin
- type SafeRecord
- type SafeTokens
- type SchemaDefinition
- type Span
- func (s *Span) AddEvent(name string, attributes Attributes)
- func (s *Span) AddEventFrom(name string, read func() Attributes)
- func (s *Span) AddEventWithPayload(name string, attributes Attributes, key string, payload func() ([]byte, error))
- func (s *Span) CapturesPayloads() bool
- func (s *Span) Context() Context
- func (s *Span) SetAttributes(attributes Attributes)
- func (s *Span) SetAttributesFrom(read func() Attributes)
- func (s *Span) SetSafeOutcome(status, failure string)
- func (s *Span) SetStatus(status SpanStatus)
- func (s *Span) SetStatusFrom(read func() SpanStatus)
- func (s *Span) StartSpan(options SpanOptions, callback func(*Span) error) error
- func (s *Span) StartSpanFrom(read func() SpanOptions, callback func(*Span) error) error
- type SpanCallbacks
- type SpanDefinition
- type SpanOptions
- type SpanStarter
- type SpanStatus
- type SpanTiming
- type StartAttributeDefinition
- type StatusDefinition
Constants ¶
const SafeAccountingSchema = "2ai.disjoint-tokens.v1"
const SafeDrainLimit = 256
const SafeIdentifierLimit = 128
const SafeQueueLimit = 2048
const SafeRecordLimit = 4096
const SafeSchemaVersion = "2ai.safe.v1"
const Undefined = jsonjs.Undefined
Undefined represents JavaScript's undefined in attribute payloads. Unlike nil (null), it does not overwrite an existing attribute during SetAttributes. Nested snapshots retain the marker; JSON omits object fields carrying it and emits null for array elements, matching JSON.stringify.
Variables ¶
This section is empty.
Functions ¶
func BindSafeOrigin ¶
func BindSafeOrigin(ctx context.Context, origin SafeOrigin, category SafeCategory) context.Context
func DetachSafeExecution ¶
func DetachSafeExecution(ctx context.Context, category SafeCategory) context.Context
func ReconcileSafe ¶
func ReconcileSafe(ctx context.Context, accounting SafeAccounting)
ReconcileSafe reports aggregates without inventing physical attempt coverage.
func SafeFailureKind ¶
func StartSpan ¶
func StartSpan[T any](c Context, options SpanOptions, callback func(*Span) (T, error)) (value T, err error)
StartSpan preserves a typed callback result as well as its error. The method on Context is the equivalent for callbacks that only return an error.
func StartSpanFrom ¶
func StartSpanFrom[T any](c Context, read func() SpanOptions, callback func(*Span) (T, error)) (value T, err error)
StartSpanFrom preserves the typed callback value and error, as StartSpan does.
func StartTypedSpan ¶
func StartTypedSpan[T any](starter SpanStarter, name string, attributes Attributes, callback func(*Span, SpanStarter) (T, error)) (value T, err error)
StartTypedSpan preserves a generic result without boxing it into an interface.
func StringifyValue ¶
StringifyValue preserves JSON.stringify's undefined root as an empty result. Only explicit JSONMethod values stored as toJSON hooks can execute on export.
func WithContext ¶
WithContext carries an explicit telemetry parent through Go host callbacks. It creates no span and has no global or goroutine-local state.
func WithRecordingParent ¶
WithRecordingParent rebinds only the private recording parent, keeping ctx's safe scope (its execution lineage). Work that outlives the span it was started from (an async child of a tool call) records under a parent that lives as long as that work is joined, instead of becoming a late no-op.
func WithSafeCategory ¶
func WithSafeCategory(ctx context.Context, category SafeCategory) context.Context
func WithSafeObserver ¶
func WithSafeObserver(ctx context.Context, observer *SafeObserver, execution SafeExecution) (context.Context, error)
WithSafeObserver accepts opaque host-approved correlation only. Runtime, tenant, config and agent identity remain the consuming host's responsibility.
Types ¶
type AttributeDefinition ¶
type AttributeDefinition struct {
Type string `json:"type"`
Description string `json:"description"`
Sensitive *bool `json:"sensitive,omitempty"`
Cardinality string `json:"cardinality,omitempty"`
Values json.RawMessage `json:"values,omitempty"`
ElementValues json.RawMessage `json:"elementValues,omitempty"`
Examples json.RawMessage `json:"examples,omitempty"`
}
AttributeDefinition is the serializable schema metadata from Pi. Values, ElementValues and Examples retain the JSON shape of their selected Type: scalar examples are arrays, array examples are arrays of arrays. Metadata describes instrumentation; it never causes runtime validation or redaction.
type Attributes ¶
type Attributes = jsonjs.ObjectValue
Attributes records Pi's scalar and array attributes. Like Pi's runtime, it also accepts JSON-shaped objects, mixed arrays and nested values without imposing the TypeScript declaration as runtime validation. Attribute objects and outer arrays are copied; nested objects/arrays retain shared identity. NewAttributes and its Get/Lookup/Set/Delete/Entries methods retain property insertion order, with numeric index keys enumerated first. The zero value is empty. NewArray retains shared length and indexed mutations. Decoded arrays use *Array; direct array attributes are spread-copied, while nested arrays stay shared. A nil value represents null. Undefined omits an attribute, including during a merge; nested object fields omit Undefined and array elements export it as null. Function values remain in memory; JSON omits object fields and uses null for array elements without invoking the function. Numeric Go types share one category; []any may mix numeric widths. JSON uses binary64 numbers (including integer rounding), nonfinite values become null, and byte slices remain numeric arrays. In-memory snapshots keep Go types. JSON decoding creates binary64 values, retaining overflow and signed zero; a successful decode replaces the object, and a failed decode leaves it untouched. Decoded lone UTF-16 surrogates use WTF-8 bytes in strings and map keys. Attribute JSON export preserves them; ordinary Go rune iteration does not. Callers must synchronize access to shared input/snapshot maps and slices.
func NewAttributes ¶
func NewAttributes(properties ...Property) Attributes
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context identifies an explicit parent. Copies share the same recording scope; there is no global recorder or implicit goroutine-local parent.
func FromContext ¶
func NewContext ¶
func NewContext(start func(SpanOptions, func(*Span) error) error) Context
NewContext binds a backend's synchronous callback-scoped span operation. The backend owns settlement, passivity, and explicit child parentage. A nil function gives the same no-op behavior as the zero Context.
func NewContextWithCallbacks ¶
func NewContextWithCallbacks(callbacks ContextCallbacks) Context
NewContextWithCallbacks binds a backend that supports deferred option reads. NewContext is the equivalent constructor for an eager-only backend.
func SafeContext ¶
SafeContext composes safe live settlement with the existing private backend. It also works when that backend is inert or refuses late children.
func (Context) StartSpan ¶
func (c Context) StartSpan(options SpanOptions, callback func(*Span) error) (err error)
StartSpan invokes callback exactly once in the calling goroutine. Returning an error or panicking settles the span without changing the error/panic value. Child work that should belong to this span must start before callback returns.
func (Context) StartSpanFrom ¶
func (c Context) StartSpanFrom(read func() SpanOptions, callback func(*Span) error) error
StartSpanFrom reads options only when this context can admit a span. A read panic falls back to no-op telemetry, without allocating an ID or changing the callback's result. The callback still runs exactly once. Readers run without the recorder lock and may create other spans; those are admitted first. Concurrent parent settlement wins over a reader that has not yet returned.
type ContextCallbacks ¶
type ContextCallbacks struct {
StartSpan func(SpanOptions, func(*Span) error) error
StartSpanFrom func(func() SpanOptions, func(*Span) error) error
}
ContextCallbacks supplies eager and deferred span admission for a backend. Backends own settlement, read passivity and child parentage. A missing operation invokes the user's callback with a no-op span; an absent deferred operation also leaves its options reader uncalled.
type Drops ¶
type Drops struct {
Spans int `json:"spans,omitempty"`
Events int `json:"events,omitempty"`
Payloads int `json:"payloads,omitempty"`
}
Drops counts what a recording scope refused because of its Limits. A payload is also counted when its producer failed.
type ErrorDetails ¶
type ErrorDetails struct {
Name string `json:"name"`
Message string `json:"message"`
// contains filtered or unexported fields
}
func (*ErrorDetails) Error ¶
func (e *ErrorDetails) Error() string
Error preserves an explicitly named failure when adapting serialized Pi errors. Ordinary Go errors continue to use the default name "Error".
func (ErrorDetails) MarshalJSON ¶
func (e ErrorDetails) MarshalJSON() ([]byte, error)
func (ErrorDetails) MessageValue ¶
func (e ErrorDetails) MessageValue() any
func (ErrorDetails) NameValue ¶
func (e ErrorDetails) NameValue() any
NameValue and MessageValue expose the actual JS-shaped fields, including Undefined for absent fields and shared *Object/*Array values. Name/Message remain convenient string projections for ordinary Go errors.
func (*ErrorDetails) SetMessageValue ¶
func (e *ErrorDetails) SetMessageValue(value any)
func (*ErrorDetails) SetNameValue ¶
func (e *ErrorDetails) SetNameValue(value any)
SetNameValue and SetMessageValue replace only this error's field. They also distinguish explicit empty strings, null and Undefined from an unchanged Go zero value. Nested edits through the returned object/array stay shared.
func (*ErrorDetails) UnmarshalJSON ¶
func (e *ErrorDetails) UnmarshalJSON(data []byte) error
type EventAttributeDefinition ¶
type EventAttributeDefinition = StartAttributeDefinition
type EventDefinition ¶
type EventDefinition struct {
Description string `json:"description"`
Attributes map[string]EventAttributeDefinition `json:"attributes"`
}
type InMemory ¶
type InMemory struct {
Context
}
InMemory owns one isolated recording scope. Spans are retained for its lifetime, just as in Pi's reference adapter, within its Limits.
func NewInMemory ¶
func NewStream ¶
func NewStream(settled func(RecordedSpan, SpanTiming), limits ...Limits) *InMemory
NewStream records like NewInMemory but hands each span to settled as soon as it settles and then forgets it, so a long run holds only its live spans and a crash loses only those. settled runs on the settling goroutine outside the recorder lock and must not block; a panic in it is ignored.
func (*InMemory) GetSpanTimings ¶
func (m *InMemory) GetSpanTimings() []SpanTiming
GetSpanTimings returns settled span timings in start order. Active and no-op spans have no completed timing. Durations use Go's monotonic clock and each snapshot is independent of future recording.
func (*InMemory) GetSpans ¶
func (m *InMemory) GetSpans() []RecordedSpan
GetSpans returns snapshots in start order, including active spans. Attribute maps and outer arrays are detached; nested objects/arrays remain shared, as with Pi's shallow copy. Callers must synchronize edits to shared payloads.
type JSONMethod ¶
type JSONMethod = jsonjs.JSONMethod
type Limits ¶
type Limits struct {
Spans int // spans held at once; default 10,000
Events int // events per span; default 1,000
Payloads int // opt-in payloads captured per scope; default 0 (off)
PayloadBytes int // bytes per payload; default 1 MiB
}
Limits bounds one recording scope so a long run cannot grow it without limit. Zero fields use the defaults. Payload capture (see Span.AddEventWithPayload) is off unless Payloads is positive.
type ParentDefinition ¶
func (ParentDefinition) MarshalJSON ¶
func (p ParentDefinition) MarshalJSON() ([]byte, error)
An explicit empty spans list is distinct from an absent list in the union.
type Property ¶
Property, Object and Array share the native JSON value implementation used by agent arguments. No JavaScript runtime or interface hierarchy is involved.
type RecordedEvent ¶
type RecordedEvent struct {
Name string `json:"name"`
Attributes Attributes `json:"attributes"`
}
func (RecordedEvent) MarshalJSON ¶
func (e RecordedEvent) MarshalJSON() ([]byte, error)
func (*RecordedEvent) UnmarshalJSON ¶
func (e *RecordedEvent) UnmarshalJSON(raw []byte) error
type RecordedSpan ¶
type RecordedSpan struct {
ID int `json:"id"`
ParentID *int `json:"parentId"`
Name string `json:"name"`
Attributes Attributes `json:"attributes"`
Events []RecordedEvent `json:"events"`
Status SpanStatus `json:"status"`
Settled bool `json:"settled"`
EndSequence *int `json:"endSequence,omitempty"`
}
func (RecordedSpan) MarshalJSON ¶
func (s RecordedSpan) MarshalJSON() ([]byte, error)
func (*RecordedSpan) UnmarshalJSON ¶
func (s *RecordedSpan) UnmarshalJSON(raw []byte) error
type SafeAccounting ¶
type SafeAccounting struct {
UsageObserved bool `json:"usage_observed"`
PricingObserved bool `json:"pricing_observed"`
UsageSource string `json:"usage_source"`
PricingSource string `json:"pricing_source"`
PriceState string `json:"price_state"`
Complete bool `json:"complete"`
AttemptCoverage string `json:"attempt_coverage"`
Tokens *SafeTokens `json:"tokens"`
KnownCostUSD *float64 `json:"known_cost_usd"`
}
SafeAccounting is evidence, not a billing claim. Unknown values are null. Only attempt_settled records are additive. Reconciliation is comparison-only.
func NormalizeSafeAccounting ¶
func NormalizeSafeAccounting(a SafeAccounting) SafeAccounting
type SafeAggregate ¶
type SafeAggregate struct {
ReportedTokens SafeTokens `json:"reported_tokens"`
ReportedCostUSD float64 `json:"reported_cost_usd"`
Additive bool `json:"additive"`
}
SafeAggregate preserves existing reported totals for comparison only. The producer cannot infer wire usage or known pricing from these host totals.
type SafeAttempt ¶
type SafeAttempt struct {
// contains filtered or unexported fields
}
func (*SafeAttempt) Finish ¶
func (a *SafeAttempt) Finish(status, failureKind string, accounting SafeAccounting)
func (*SafeAttempt) FinishAdmission ¶
func (a *SafeAttempt) FinishAdmission(status, failureKind string, accounting SafeAccounting, provider, model string, admitted bool)
FinishAdmission distinguishes an attempted open from an admitted producer. An admission failure remains an attempt with unavailable provider usage.
func (*SafeAttempt) FinishModel ¶
func (a *SafeAttempt) FinishModel(status, failureKind string, accounting SafeAccounting, provider, model string)
FinishModel checks response selection against the immutable approved binding. A different provider answering is unavailable; response text is never copied into a label. A routed model id (a gateway alias such as "flash") answers with its upstream name, so a model-only difference keeps the host binding that was called: the label names what the host approved, not what the response says.
type SafeCall ¶
type SafeCall struct {
// contains filtered or unexported fields
}
NewSafeCall allocates one logical call identity, shared by every retry/rung.
func NewSafeCall ¶
func (SafeCall) StartAttempt ¶
func (c SafeCall) StartAttempt(ordinal int, labels SafeLabels) *SafeAttempt
type SafeCategory ¶
type SafeCategory string
const ( CategoryMain SafeCategory = "main" CategoryCompaction SafeCategory = "compaction" CategoryAdvisor SafeCategory = "advisor" CategoryMemory SafeCategory = "memory" CategoryChild SafeCategory = "child" )
type SafeExecution ¶
type SafeExecution struct {
ExecutionID, OriginExecutionID string
Category SafeCategory
}
type SafeHealth ¶
type SafeHealth struct {
Capacity int `json:"capacity"`
Queued int `json:"queued"`
Admitted uint64 `json:"admitted"`
Overflow uint64 `json:"overflow"`
Oversize uint64 `json:"oversize"`
ClosedAdmission uint64 `json:"closed_admission"`
Contended uint64 `json:"contended"`
Closed bool `json:"closed"`
Complete bool `json:"complete"`
}
type SafeLabels ¶
type SafeLabels struct {
// contains filtered or unexported fields
}
SafeLabels can only be constructed by an explicit host approval. Approval must use configured public IDs, never provider response text or raw metadata. The zero value represents unavailable labels. Values are immutable.
func ApproveModelLabels ¶
func ApproveModelLabels(provider, model string) (SafeLabels, error)
func ApproveToolLabel ¶
func ApproveToolLabel(tool string) (SafeLabels, error)
type SafeObserver ¶
type SafeObserver struct {
// contains filtered or unexported fields
}
SafeObserver is a finite passive pull queue. It owns no goroutine and invokes no sink. The host drains, persists, retries and deduplicates detached records. Intake lifetime belongs to the host, independently of any root settlement.
func NewSafeObserver ¶
func NewSafeObserver(options SafeObserverOptions) (*SafeObserver, error)
func (*SafeObserver) Changes ¶
func (o *SafeObserver) Changes() <-chan struct{}
Changes is a coalescing doorbell for one host collector, not an event stream. On wake, sample Health and drain all pending batches before sleeping. Intake never waits for the collector; the channel stays open after Close so shutdown cannot become a busy loop. Calling Drain does not acknowledge this doorbell.
func (*SafeObserver) Close ¶
func (o *SafeObserver) Close()
func (*SafeObserver) Drain ¶
func (o *SafeObserver) Drain(limit int) []SafeRecord
Drain consumes at most min(limit, 256) records. A nonpositive limit consumes none. Host delivery retries retain the returned event IDs; there is no replay.
func (*SafeObserver) Health ¶
func (o *SafeObserver) Health() SafeHealth
type SafeObserverOptions ¶
type SafeObserverOptions struct{ Capacity, RecordBytes int }
type SafeOrigin ¶
type SafeOrigin struct {
// contains filtered or unexported fields
}
SafeOrigin carries only immutable safe observation metadata across host work queues. It carries no cancellation, private recorder or application context.
func CaptureSafeOrigin ¶
func CaptureSafeOrigin(ctx context.Context) SafeOrigin
func (SafeOrigin) Merge ¶
func (o SafeOrigin) Merge(other SafeOrigin) SafeOrigin
func (SafeOrigin) SameScope ¶
func (o SafeOrigin) SameScope(other SafeOrigin) bool
SameScope compares immutable observation metadata, including its observer, execution, span and category. Equivalent context copies share a scope.
type SafeRecord ¶
type SafeRecord struct {
SchemaVersion string `json:"schema_version"`
AccountingSchema string `json:"accounting_schema"`
Kind string `json:"kind"`
ProducerEventID string `json:"producer_event_id"`
ExecutionID string `json:"execution_id"`
OriginExecutionID *string `json:"origin_execution_id"`
SpanID *string `json:"span_id"`
ParentSpanID *string `json:"parent_span_id"`
ParentExecutionID *string `json:"parent_execution_id"`
CallID *string `json:"call_id"`
AttemptID *string `json:"attempt_id"`
AttemptOrdinal int `json:"attempt_ordinal"`
ProducerAdmitted bool `json:"producer_admitted"`
Category SafeCategory `json:"category"`
SpanKind string `json:"span_kind"`
ProviderID *string `json:"provider_id"`
ModelID *string `json:"model_id"`
ToolID *string `json:"tool_id"`
LabelsState string `json:"labels_state"`
StartedAt time.Time `json:"started_at"`
SettledAt time.Time `json:"settled_at"`
Duration time.Duration `json:"duration_ns"`
Status string `json:"status"`
FailureKind string `json:"failure_kind"`
Accounting SafeAccounting `json:"accounting"`
Reconciliation *SafeAggregate `json:"reconciliation"`
}
SafeRecord has no private attributes, errors, messages or serializer hooks. Every optional ID is null when unavailable. All records are detached values.
type SafeTokens ¶
type SchemaDefinition ¶
type SchemaDefinition struct {
Version float64 `json:"version"`
Spans map[string]SpanDefinition `json:"spans"`
}
func DefineSchema ¶
func DefineSchema(schema *SchemaDefinition) *SchemaDefinition
DefineSchema is Pi's identity helper. No cloning, normalization, validation, or schema access occurs; the same pointer is returned.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span is valid as a recording parent until its callback returns. Retaining it is safe: later mutations are inert, and later child callbacks still execute.
func NewSpan ¶
func NewSpan(children Context, callbacks SpanCallbacks) *Span
NewSpan constructs a backend span with its explicit child context. It does not add lifecycle behavior; that belongs to the backend's start function.
func (*Span) AddEvent ¶
func (s *Span) AddEvent(name string, attributes Attributes)
func (*Span) AddEventFrom ¶
func (s *Span) AddEventFrom(name string, read func() Attributes)
AddEventFrom reads attributes only while recording is active. A read panic suppresses the outer event; nested events already emitted by the reader stay in order. No recorder lock is held while invoking the reader. An event is ignored if its span settles before the reader returns.
func (*Span) AddEventWithPayload ¶
func (s *Span) AddEventWithPayload(name string, attributes Attributes, key string, payload func() ([]byte, error))
AddEventWithPayload records an event and, only when the recorder opted into payloads, attaches payload's bytes as the string attribute key. payload runs outside the recorder lock and only when its result would be kept. A payload beyond the count or size bound, or whose producer fails, is dropped and counted, and the event carries key+".dropped" with the reason ("count", "size" or "error"). Backends supplied through callbacks receive the event without the payload.
func (*Span) CapturesPayloads ¶
CapturesPayloads reports whether this span's recorder opted into payloads and can still take one, so a caller can skip snapshotting a payload's inputs when nothing would keep them.
func (*Span) SetAttributes ¶
func (s *Span) SetAttributes(attributes Attributes)
func (*Span) SetAttributesFrom ¶
func (s *Span) SetAttributesFrom(read func() Attributes)
SetAttributesFrom defers reading an incoming attribute set until recording is active. Like Pi's property reads, a panic discards the outer update while retaining any reentrant mutations the reader already made. A successful read merges into the attributes captured before reading, so reentrant attribute updates are overwritten by that outer merge. Events and status are unaffected. Readers run without the recorder lock; concurrent settlement wins.
func (*Span) SetSafeOutcome ¶
SetSafeOutcome binds only bounded structural status metadata. It never reads a private status/error or changes the legacy recorder's status precedence. Cancellation may accompany a returned error; that error is still preserved.
func (*Span) SetStatus ¶
func (s *Span) SetStatus(status SpanStatus)
func (*Span) SetStatusFrom ¶
func (s *Span) SetStatusFrom(read func() SpanStatus)
SetStatusFrom reads a status only when recording is active. It is the Go equivalent of Pi reading a status object with user-defined getters. A reader panic is passive: no outer status/explicit-status change is applied, while the reader's own reentrant mutations remain. Readers run without the recorder lock, so they may record events, set a nested status or inspect snapshots. Concurrent settlement wins over a reader that has not yet returned. Callback backends implement admission through SpanCallbacks.SetStatusFrom.
func (*Span) StartSpan ¶
func (s *Span) StartSpan(options SpanOptions, callback func(*Span) error) error
func (*Span) StartSpanFrom ¶
func (s *Span) StartSpanFrom(read func() SpanOptions, callback func(*Span) error) error
StartSpanFrom creates a child using deferred options and explicit parentage.
type SpanCallbacks ¶
type SpanCallbacks struct {
AddEvent func(string, Attributes)
SetAttributes func(Attributes)
SetStatus func(SpanStatus)
// Deferred reads own admission, including skipping reads after settlement
// and suppressing read failures. Nil retains the supplied context's default
// behavior (inert for an opaque backend).
SetStatusFrom func(func() SpanStatus)
SetAttributesFrom func(func() Attributes)
AddEventFrom func(string, func() Attributes)
}
SpanCallbacks are the mutation operations supplied by a telemetry backend. Provided callbacks override native recorder operations; opaque contexts leave missing operations inert. Backends must ignore mutations after settlement and suppress recording failures without changing the user's callback result.
type SpanDefinition ¶
type SpanDefinition struct {
Description string `json:"description"`
Parents ParentDefinition `json:"parents"`
StartAttributes map[string]StartAttributeDefinition `json:"startAttributes"`
EndAttributes map[string]AttributeDefinition `json:"endAttributes"`
Events map[string]EventDefinition `json:"events,omitempty"`
Status StatusDefinition `json:"status"`
}
func (SpanDefinition) MarshalJSON ¶
func (s SpanDefinition) MarshalJSON() ([]byte, error)
type SpanOptions ¶
type SpanOptions struct {
Name string `json:"name"`
Attributes Attributes `json:"attributes,omitzero"`
SafeLabels SafeLabels `json:"-"`
}
func (SpanOptions) MarshalJSON ¶
func (o SpanOptions) MarshalJSON() ([]byte, error)
func (*SpanOptions) UnmarshalJSON ¶
func (o *SpanOptions) UnmarshalJSON(raw []byte) error
type SpanStarter ¶
type SpanStarter struct {
// contains filtered or unexported fields
}
SpanStarter binds one explicit parent context. Schema values are deliberately unread, as in createTypedSpanStarter. Go does not infer literal attribute types from schema values; use application-owned typed wrappers when needed. It must not introduce runtime validation absent from Pi's implementation.
func CreateTypedSpanStarter ¶
func CreateTypedSpanStarter(parent Context, _ ...*SchemaDefinition) SpanStarter
func (SpanStarter) StartSpan ¶
func (s SpanStarter) StartSpan(name string, attributes Attributes, callback func(*Span, SpanStarter) error) error
StartSpan supplies a child starter bound to the newly admitted span. Saving that starter does not extend the span's lifetime; late children remain no-op.
type SpanStatus ¶
type SpanStatus struct {
Status string `json:"status"`
Error *ErrorDetails `json:"error,omitempty"`
// contains filtered or unexported fields
}
func (SpanStatus) MarshalJSON ¶
func (s SpanStatus) MarshalJSON() ([]byte, error)
func (*SpanStatus) UnmarshalJSON ¶
func (s *SpanStatus) UnmarshalJSON(data []byte) error
UnmarshalJSON projects serialized status inputs using Pi's property reads. Non-object primitives have no status/error properties; null is unreadable and SetStatus ignores it. Truthy errors copy only their name/message properties.
type SpanTiming ¶
type SpanTiming struct {
SpanID int `json:"span_id"`
StartedAt time.Time `json:"started_at"`
Duration time.Duration `json:"duration_ns"`
EventTimes []time.Time `json:"event_times,omitempty"`
}
SpanTiming is a detached timing for a settled span. It is kept separately from RecordedSpan so Pi-compatible records retain their original JSON shape. EventTimes holds when each of the span's events was recorded, in order.
type StartAttributeDefinition ¶
type StartAttributeDefinition struct {
AttributeDefinition
Required bool `json:"required"`
}