Documentation
¶
Index ¶
- Constants
- func GetFnName(fn reflect.Value) string
- func GetFnTraceName(fn reflect.Value) string
- func GetProvideAllInputTypes(typ reflect.Type) []reflect.Type
- func SetLog(handler slog.Handler)
- type DiagFileQuery
- type DiagFileReadResult
- type DiagFileRecord
- type Dix
- func (dix *Dix) GetObjects() map[reflect.Type]map[string][]reflect.Value
- func (dix *Dix) GetProviderDetails() []ProviderDetails
- func (dix *Dix) GetProviderRuntimeStats() []ProviderRuntimeStats
- func (dix *Dix) GetProviders() map[reflect.Type][]*providerFn
- func (dix *Dix) GetRecentErrors(limit int) []RecentError
- func (dix *Dix) Inject(param any, opts ...Option) any
- func (dix *Dix) InjectContext(ctx context.Context, param any, opts ...Option) any
- func (dix *Dix) Option() Options
- func (dix *Dix) Provide(param any)
- func (dix *Dix) TryInject(param any, opts ...Option) error
- func (dix *Dix) TryInjectContext(ctx context.Context, param any, opts ...Option) error
- func (dix *Dix) TryProvide(param any) (err error)
- type Option
- type Options
- type ProviderDetails
- type ProviderRuntimeStats
- type RecentError
Constants ¶
const ( // DefaultProviderTimeout is the default max execution time for a single provider call. // Set WithProviderTimeout(0) to disable timeout control. DefaultProviderTimeout = 15 * time.Second // DefaultSlowProviderThreshold is the default warning threshold for provider execution latency. // Set WithSlowProviderThreshold(0) to disable slow-provider warnings. DefaultSlowProviderThreshold = 2 * time.Second )
const (
// InjectMethodPrefix can inject objects, as long as the method of this object contains a prefix of `InjectMethodPrefix`
InjectMethodPrefix = "DixInject"
)
Variables ¶
This section is empty.
Functions ¶
func GetFnTraceName ¶
GetFnTraceName returns function name for trace logs with best-effort full package path. For normal packages runtime already returns full import path. For `main.*` symbols, this attempts to rebuild a module-qualified path from source file location.
func GetProvideAllInputTypes ¶
GetProvideAllInputTypes returns all input types for a given type, including struct fields This is a public version of getProvideAllInputs that returns types instead of internal structures
Types ¶
type DiagFileQuery ¶
type DiagFileQuery struct {
Kind string
Event string
Search string
Limit int
BeforeID int64
SinceUnix int64
UntilUnix int64
}
DiagFileQuery controls filtering and pagination for DIX_DIAG_FILE records.
type DiagFileReadResult ¶
type DiagFileReadResult struct {
Enabled bool `json:"enabled"`
Path string `json:"path,omitempty"`
Exists bool `json:"exists"`
Total int `json:"total"`
Returned int `json:"returned"`
NextBefore int64 `json:"next_before_id,omitempty"`
Records []DiagFileRecord `json:"records"`
}
DiagFileReadResult is the API response object for diagnostic file queries.
func ReadDiagFileRecords ¶
func ReadDiagFileRecords(query DiagFileQuery) (DiagFileReadResult, error)
ReadDiagFileRecords loads and filters records from DIX_DIAG_FILE.
func ReadDiagFileRecordsFromLines ¶
func ReadDiagFileRecordsFromLines(lines []string, query DiagFileQuery) DiagFileReadResult
ReadDiagFileRecordsFromLines is a test helper for parsing query behavior without I/O.
type DiagFileRecord ¶
type DiagFileRecord struct {
RecordID int64 `json:"record_id,omitempty"`
Source string `json:"source,omitempty"`
PID int `json:"pid,omitempty"`
Process string `json:"process,omitempty"`
Hostname string `json:"hostname,omitempty"`
TraceDI bool `json:"trace_di,omitempty"`
LLMDiagMode string `json:"llm_diag_mode,omitempty"`
Kind string `json:"kind"`
OccurredAt int64 `json:"occurred_at_unix_nano"`
Event string `json:"event,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
Payload any `json:"payload,omitempty"`
}
DiagFileRecord is an exported diagnostic record returned by file-query APIs.
type Dix ¶
type Dix struct {
// contains filtered or unexported fields
}
func (*Dix) GetObjects ¶
GetObjects returns a copy of the objects map for inspection This is useful for HTTP visualization endpoints
func (*Dix) GetProviderDetails ¶
func (dix *Dix) GetProviderDetails() []ProviderDetails
GetProviderDetails returns detailed information about all providers
func (*Dix) GetProviderRuntimeStats ¶
func (dix *Dix) GetProviderRuntimeStats() []ProviderRuntimeStats
GetProviderRuntimeStats returns runtime stats sorted by total duration (descending). This is helpful for startup latency diagnosis.
func (*Dix) GetProviders ¶
GetProviders returns a copy of the providers map for inspection This is useful for HTTP visualization endpoints
func (*Dix) GetRecentErrors ¶
func (dix *Dix) GetRecentErrors(limit int) []RecentError
GetRecentErrors returns recent Inject/TryInject errors in reverse-chronological order. limit <= 0 means return all currently retained errors.
func (*Dix) Inject ¶
Inject injects dependencies into the given parameter. Panics on error. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.
func (*Dix) InjectContext ¶
InjectContext injects dependencies using the provided context as trace propagation root. Panics on error. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.
func (*Dix) Provide ¶
Provide registers a provider function. Panics on error. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.
func (*Dix) TryInject ¶
TryInject injects dependencies into the given parameter. Returns error instead of panicking. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.
func (*Dix) TryInjectContext ¶
TryInjectContext injects dependencies using the provided context as trace propagation root. Returns error instead of panicking. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.
func (*Dix) TryProvide ¶
TryProvide registers a provider function. Returns error instead of panicking. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.
type Option ¶
type Option func(opts *Options)
func WithProviderTimeout ¶
func WithValuesNull ¶
func WithValuesNull() Option
type Options ¶
type Options struct {
// AllowValuesNull allows result to be nil
AllowValuesNull bool
// ProviderTimeout limits the maximum execution time of one provider call.
// Zero means no timeout.
ProviderTimeout time.Duration
// SlowProviderThreshold emits warning log if provider execution is slower than this threshold.
// Zero means no slow-warning threshold.
SlowProviderThreshold time.Duration
}
type ProviderDetails ¶
type ProviderDetails struct {
OutputType string
OutputPkg string
FunctionName string
FunctionPkg string
FunctionFile string
FunctionLine int
InputTypes []string
InputPkgs []string
}
ProviderDetails contains detailed information about a provider
type ProviderRuntimeStats ¶
type ProviderRuntimeStats struct {
FunctionName string `json:"function_name"`
OutputType string `json:"output_type"`
CallCount int `json:"call_count"`
TotalDuration time.Duration `json:"total_duration"`
AverageDuration time.Duration `json:"average_duration"`
LastDuration time.Duration `json:"last_duration"`
LastError string `json:"last_error,omitempty"`
LastRunAtUnixNano int64 `json:"last_run_at_unix_nano"`
}
ProviderRuntimeStats contains provider runtime metrics for diagnostics.
type RecentError ¶
type RecentError struct {
Operation string `json:"operation"`
ErrorType string `json:"error_type,omitempty"`
Component string `json:"component"`
Stage string `json:"stage,omitempty"`
ProviderFunction string `json:"provider_function,omitempty"`
OutputType string `json:"output_type,omitempty"`
InputType string `json:"input_type,omitempty"`
InputTypes []string `json:"input_types,omitempty"`
Message string `json:"message"`
RootCause string `json:"root_cause,omitempty"`
Hint string `json:"hint,omitempty"`
TimedOut bool `json:"timed_out,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
OccurredAtUnixNano int64 `json:"occurred_at_unix_nano"`
}
RecentError contains a recently captured Inject/TryInject failure event.