Documentation
¶
Overview ¶
Package observability provides OpenTelemetry instrumentation for magus. Telemetry is OFF by default; set telemetry.enabled=true in magus.yaml to export.
Index ¶
- func CacheRunOptions(ctx context.Context, p Provider) []cache.RunOption
- func CacheTracer(p Provider) cache.Tracer
- func GraphObserver(ctx context.Context, p Provider) types.Observer
- func InstrumentRemoteBackend(b cache.RemoteBackend, p Provider) cache.RemoteBackend
- func TargetRunOptions(ctx context.Context, p Provider, spellsOf func(projectPath string) []string) []cache.RunOption
- func WithProvider(ctx context.Context, p Provider) context.Context
- type Attr
- type BuzzHostCall
- type Config
- type MCPCall
- type Provider
- type RemoteOp
- type SandboxRules
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheRunOptions ¶
CacheRunOptions returns cache.RunOption values that wire OnHit/OnMiss/OnError to the Provider. Returns nil when p is nil or disabled; callers can wire unconditionally.
func CacheTracer ¶
CacheTracer adapts a Provider to cache.Tracer so the cache package can open phase spans without importing this package. It returns nil when telemetry is off; cache.ContextWithTracer stores a nil Tracer as a no-op.
func GraphObserver ¶
GraphObserver wraps p as a types.Observer; returns types.NoopObserver{} when p is nil or disabled.
func InstrumentRemoteBackend ¶
func InstrumentRemoteBackend(b cache.RemoteBackend, p Provider) cache.RemoteBackend
InstrumentRemoteBackend wraps b so every get/put records a span and the magus.cache.remote.* metrics through p. It returns b unchanged when telemetry is off, so a disabled build pays nothing — no wrapping, no byte counting. The optional cache.RemotePruner capability is preserved: a backend that supports prune still does after wrapping (the prune sweep is traced too).
func TargetRunOptions ¶
func TargetRunOptions(ctx context.Context, p Provider, spellsOf func(projectPath string) []string) []cache.RunOption
TargetRunOptions returns cache.RunOption values that record per-target metrics (magus.project, spell, target, outcome, cache.hit) via the Provider. spellsOf maps project path → spell names; one row is emitted per spell. Returns nil when p is nil.
func WithProvider ¶
WithProvider returns a copy of ctx carrying p. Retrieve with FromContext.
Types ¶
type BuzzHostCall ¶ added in v0.2.0
BuzzHostCall describes one native-boundary call from Buzz into a host callable, for the magus.buzz.host.call.* family. Callable names the host function; Outcome is "success" or "error"; Duration is wall-clock seconds.
type Config ¶
type Config struct {
Enabled bool // gates exporter setup; false = no-op
Endpoint string // OTLP collector host:port (no scheme); required when Enabled
Protocol string // "grpc" (default) or "http"
Insecure bool // disable TLS for the OTLP exporter
Headers map[string]string // static headers on every OTLP request
ServiceName string // resource attribute service.name
ServiceVersion string // resource attribute service.version
SampleRatio float64 // head-based trace sampling ratio [0,1]
WorkspaceRoot string // stamped as magus.workspace.root when set
// LocalCollect builds an always-on in-process metrics collector even when Enabled is false
// (no external export), so the daemon can serve OTLP snapshots to the /dashboard. The CLI
// leaves this false to keep one-shot invocations a true no-op.
LocalCollect bool
}
Config holds the values needed to start the OTel exporter. Construct via ConfigFromTelemetry.
type MCPCall ¶ added in v0.2.0
type MCPCall struct {
Tool string
Outcome string
InputBytes int64
OutputBytes int64
Duration float64
}
MCPCall describes one completed MCP tool call for the magus.mcp.tool.* family. Outcome is "success" or "error". InputBytes/OutputBytes are the request/response payload sizes; Duration is wall-clock seconds.
type Provider ¶
type Provider interface {
Enabled() bool
RecordCacheHit(ctx context.Context, attrs ...Attr)
RecordCacheMiss(ctx context.Context, attrs ...Attr)
RecordCacheError(ctx context.Context, attrs ...Attr)
RecordCacheDuration(ctx context.Context, secs float64, attrs ...Attr) // magus.cache.duration histogram
RecordCacheSaved(ctx context.Context, secs float64) // magus.cache.saved.duration histogram
RecordGraphQuery(ctx context.Context, secs float64, attrs ...Attr) // magus.graph.query.duration histogram
RecordRemoteOp(ctx context.Context, op RemoteOp) // magus.cache.remote.* metrics
StartSpan(ctx context.Context, name string, attrs ...Attr) (context.Context, func(error)) // end fn marks failure on non-nil error
RecordTargetRun(ctx context.Context, secs float64, attrs ...Attr) // magus.target.runs + magus.target.duration
RecordPoolAcquire(ctx context.Context, waitSecs float64, n int64) // magus.pool.wait.duration + slots.running+n
RecordPoolRelease(ctx context.Context, n int64) // slots.running-n
RecordPoolWaiting(ctx context.Context, delta int64) // magus.pool.slots.queued += delta
// MCP tool call family: magus.mcp.tool.*.
RecordMCPCall(ctx context.Context, c MCPCall)
// Filesystem sandbox families: magus.sandbox.*.
RecordSandboxApply(ctx context.Context, secs float64, outcome, scope string) // magus.sandbox.apply.duration
RecordSandboxRules(ctx context.Context, r SandboxRules) // magus.sandbox.rules + magus.sandbox.env.rules
RecordSandboxCheck(ctx context.Context, access, decision, project string) // magus.sandbox.checks
RecordSandboxEnvDropped(ctx context.Context, project string, n int64) // magus.sandbox.env.dropped
// Buzz language families: magus.buzz.*.
RecordBuzzExec(ctx context.Context, secs float64, mode, outcome string) // magus.buzz.exec.duration
RecordBuzzCompile(ctx context.Context, secs float64, phase, mode string) // magus.buzz.compile.duration
RecordBuzzHostCall(ctx context.Context, c BuzzHostCall) // magus.buzz.host.call.{duration,count}
RecordBuzzSessionReuse(ctx context.Context, outcome string) // magus.buzz.session.pool.reuse
RecordBuzzSessionIdle(ctx context.Context, delta int64) // magus.buzz.session.pool.idle
RecordBuzzSessionEviction(ctx context.Context, source string) // magus.buzz.session.pool.evictions
RecordBuzzSessionWarm(ctx context.Context, secs float64, source string) // magus.buzz.session.warm.duration
RecordBuzzImport(ctx context.Context, secs float64, kind, outcome string) // magus.buzz.import.duration
RecordBuzzSpellResolve(ctx context.Context, secs float64, spell, builtin string) // magus.buzz.spell.resolve.duration
RecordBuzzSpellBuiltinsWarm(ctx context.Context, secs float64, spell string) // magus.buzz.spell.builtins.warm
RecordBuzzJITRun(ctx context.Context) // magus.buzz.jit.runs
RecordBuzzVMFault(ctx context.Context, kind string) // magus.buzz.vm.faults
// Agent-surface families: magus.lease.*, magus.attention.*, magus.review.*. Every
// attribute here is a bounded enum the caller has already validated; an id, a path, a
// lease label or a remark body must never reach one.
RecordLeaseRegistration(ctx context.Context, verdict string) // magus.lease.registrations
RecordAttentionDisposition(ctx context.Context, secs float64, sev string) // magus.attention.disposition.duration
RecordReviewRemark(ctx context.Context, author string) // magus.review.remarks
RecordReviewPublish(ctx context.Context, verdict string, downgraded bool) // magus.review.publishes
// Snapshot returns the current metrics as standard OTLP protobuf, or (nil, nil) when this
// provider is not collecting locally. OTLP is the export format for real monitoring
// backends; it is never put on the dashboard's wire.
Snapshot(ctx context.Context) ([]byte, error)
Shutdown(ctx context.Context) error
}
Provider is the OTel runtime surface. All methods are concurrency-safe; all are no-ops when Enabled=false.
func FromContext ¶
FromContext returns the Provider stored by WithProvider, or nil.
type RemoteOp ¶
type RemoteOp struct {
Method string
Outcome string
Duration float64 // wall-clock seconds
Bytes int64
}
RemoteOp describes one completed remote cache backend operation for the magus.cache.remote.* instruments. Method is "get" or "put"; Outcome is "hit" or "miss" for a get, "stored" for a successful put, or "error" for any failure. Bytes is the entry payload transferred — 0 for a miss or an error before any data moved. A get hit and a put both carry a non-zero Bytes.
type SandboxRules ¶ added in v0.2.0
type SandboxRules struct {
Read int64
Write int64
Exec int64
EnvExact int64
EnvGlob int64
Scope string
}
SandboxRules describes the allow-rules one sandbox was built from, for the magus.sandbox.rules and magus.sandbox.env.rules families. Read/Write/Exec count filesystem access rules by permission; EnvExact/EnvGlob count environment allow-rules by match kind; Scope is the sandbox scope attribute (e.g. "workspace" or "target").