monitoring

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 50 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const OTelSDKModule = "go.opentelemetry.io/otel/sdk"

OTelSDKModule is the Go OpenTelemetry SDK module the exporter is linked against

View Source
const RedactionUnavailable = memory.RedactionUnavailable

RedactionUnavailable is what egress carries when the secret redactor itself fails

Variables

View Source
var (
	// Runtime status payload of the active gateway, assigned by the gateway package
	GatewayReadRuntimeStatus func() *jsonutil.Object

	// Live background work counters, assigned by the tools package
	AsyncDelegationActiveTaskCount func() int
	AsyncDelegationActiveCount     func() int
	ProcessRegistryCountRunning    func() int
)
View Source
var (

	// Runtime status contract derivations, assigned by the gateway package
	GatewayDeriveBusy      func(gatewayRunning bool, gatewayState, activeAgents any) (bool, error)
	GatewayDeriveDrainable func(gatewayRunning bool, gatewayState any) bool
)
View Source
var GatewayParseActiveAgents func(raw any) (any, error)

Runtime status contract parse of active_agents, assigned by the gateway package

Functions

func ClassifyCronError

func ClassifyCronError(raw any) string

First matching error class of the lowered error text, auth by word boundary, unknown when none match

func ClassifyExitReason

func ClassifyExitReason(raw, state any, restartRequested bool) *string

Bounded operational class of free form shutdown text, nil when there is no reason to classify

func ClassifyGatewayError

func ClassifyGatewayError(raw any) string

Bounded class of free form gateway error text, unknown when no rule matches

func CmdMonitoring

func CmdMonitoring(ctx context.Context, h string, ns map[string]any, w, errw io.Writer) (int, error)

Prints the gateway monitoring status

func Emit

func Emit(event any)

Emits through the process wide emitter

func EmitExecutionState

func EmitExecutionState(record map[string]any, deliveryOutcome *string)

Emits the lifecycle event of a record, flushing terminal states for up to a second, never failing the caller

func EmitRuntimeStatusTransition

func EmitRuntimeStatusTransition(previous, current *jsonutil.Object)

Emits content free gateway events for a runtime status change, failing open with a debug log

func EnsureInstallID

func EnsureInstallID(ctx context.Context) string

Stable install id of the profile, a fresh uuid minted and saved when empty

func ExportBatch

func ExportBatch(provider *TracerProvider, batch []*jsonutil.Object) int

ExportBatch maps a batch of events to spans on the provider and returns how many it created

func IsOTLPEnabled

func IsOTLPEnabled(ctx context.Context) bool

IsOTLPEnabled reports an enabled export with a collector address

func PlatformForSubsystem

func PlatformForSubsystem(subsystem string) *string

Platform named by a platform subsystem, nil for every other subsystem

func RedactBounded

func RedactBounded(raw any) string

Redacted and length bounded text of a value with the default limit and markers

func RedactBoundedWith

func RedactBoundedWith(raw any, limit int, empty, unavailable string) (out string)

Redacted text of a falsy defaulted value cut to limit characters, empty and failure markers substituted

func RedactForExport

func RedactForExport(text any) (string, bool)

Scrubs a value for egress, secrets first, then email, uuid and phone shapes, false for None

func ResolveHeaders

func ResolveHeaders(headersEnv any) map[string]string

ResolveHeaders maps header names to the values of the env vars named for them, unset vars skipped

func RuntimeResourceAttributes

func RuntimeResourceAttributes(ctx context.Context, telemetryScope string) map[string]string

RuntimeResourceAttributes builds the safe OTLP resource shared by spans, metrics and diagnostic logs

func SafeResourceAttributes

func SafeResourceAttributes(raw any) map[string]string

SafeResourceAttributes keeps allowlisted bounded resource labels, rejecting values redaction would change

func SetCronHealthSources

func SetCronHealthSources(s CronHealthSources)

Installs the cron readers the health snapshot projects

func SignalEndpoint

func SignalEndpoint(endpoint, signal string) string

SignalEndpoint rewrites a traces or metrics OTLP path to the named signal, other paths passing through

func SourceLoggerForExport

func SourceLoggerForExport(name any) *string

Bounded source controlled gateway logger name for the OTLP scope, nil for any other name

func SpanAttrs

func SpanAttrs(ev *jsonutil.Object) map[string]any

SpanAttrs maps a monitoring event to span attributes, content free by construction

func SubsystemForLogger

func SubsystemForLogger(loggerName string) string

Subsystem of a gateway logger, the relay and each platform module named apart

Types

type BatchSpanProcessor

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

BatchSpanProcessor queues spans and exports them in bounded batches on a schedule, on flush and on shutdown

func NewBatchSpanProcessor

func NewBatchSpanProcessor(exporter SpanExporter) *BatchSpanProcessor

NewBatchSpanProcessor wraps an exporter with the OpenTelemetry batch defaults

func (*BatchSpanProcessor) ForceFlush

func (p *BatchSpanProcessor) ForceFlush()

ForceFlush exports everything queued before returning

func (*BatchSpanProcessor) OnEnd

func (p *BatchSpanProcessor) OnEnd(span *Span)

Queues a finished span, dropping it when the queue is full

func (*BatchSpanProcessor) Shutdown

func (p *BatchSpanProcessor) Shutdown()

Shutdown stops the schedule, drains the queue and shuts the exporter down

type CronExecutionEvent

type CronExecutionEvent struct {
	Status          string
	JobKey          string
	Source          string
	DurationMS      *int64
	DeliveryOutcome *string
	ErrorClass      *string
	TsNS            int64
}

CronExecutionEvent is a content free durable cron execution lifecycle projection

func NewCronExecutionEvent

func NewCronExecutionEvent(status, jobKey string) CronExecutionEvent

Cron event with unknown source and the current nanosecond timestamp

func ProjectExecutionEvent

func ProjectExecutionEvent(record map[string]any, deliveryOutcome *string) CronExecutionEvent

Content free event of a ledger record with opaque job key and bucketed status, source and outcome

func (CronExecutionEvent) ToDict

func (e CronExecutionEvent) ToDict() *jsonutil.Object

type CronHealthSnapshot

type CronHealthSnapshot struct {
	Metrics []GatewayMetric
	Events  []CronExecutionEvent
}

CronHealthSnapshot holds the cron gauges and the always empty event list of one snapshot

func BuildCronHealthSnapshot

func BuildCronHealthSnapshot(ctx context.Context) CronHealthSnapshot

Scheduler freshness, job, running and store gauges with no events

type CronHealthSources

type CronHealthSources struct {
	Now                    func() time.Time
	LoadJobs               func(ctx context.Context) ([]CronJobHealth, error)
	TickerHeartbeatAge     func() (*float64, error)
	TickerSuccessAge       func() (*float64, error)
	CatchUpOccurrenceCount func() (int, error)
	RunningJobCount        func() (int, error)
	DegradedSkippedRuns    func() ([]int, error)
}

CronHealthSources are the cron readers pkg/cron registers in init, each fail open on its own

type CronJobHealth

type CronJobHealth struct {
	Enabled      bool
	NextRunAt    any
	HasSchedule  bool
	GraceSeconds func() int
}

CronJobHealth is the view of one stored job the overdue gauge reads

type EmitterStats

type EmitterStats struct {
	Queued, Dispatched, Dropped, Subscribers int
}

EmitterStats is the queued, dispatched, dropped and subscriber count snapshot

type Event

type Event interface {
	ToDict() *jsonutil.Object
}

Event is a typed monitoring event whose dict form leads with its event name in wire order

type GatewayDiagnosticEvent

type GatewayDiagnosticEvent struct {
	Name         string
	Subsystem    string
	ErrorClass   string
	ErrorCode    *string
	Platform     *string
	OldState     *string
	NewState     *string
	Profile      *string
	Version      *string
	Severity     string
	TsNS         int64
	SourceLogger *string
}

GatewayDiagnosticEvent is a redacted gateway diagnostic event for operator owned observability

func NewGatewayDiagnosticEvent

func NewGatewayDiagnosticEvent(name, subsystem string) GatewayDiagnosticEvent

Diagnostic event with unknown class, warning severity and the current nanosecond timestamp

func (GatewayDiagnosticEvent) ToDict

type GatewayDiagnosticLogHandler

type GatewayDiagnosticLogHandler struct {
	Profile string
	Version string
}

GatewayDiagnosticLogHandler bridges gateway warning and error records into allowlisted diagnostic events

func NewGatewayDiagnosticLogHandler

func NewGatewayDiagnosticLogHandler(profile, version string) *GatewayDiagnosticLogHandler

Warning level handler stamping each event with the given profile and version

func (*GatewayDiagnosticLogHandler) Close

func (*GatewayDiagnosticLogHandler) Handle

Emits a diagnostic event for a gateway logger record at warning or above

func (*GatewayDiagnosticLogHandler) Level

func (h *GatewayDiagnosticLogHandler) Level() int

type GatewayDiagnosticLogStreamer

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

GatewayDiagnosticLogStreamer is the emitter subscriber sending gateway diagnostic events as OTLP logs

func (*GatewayDiagnosticLogStreamer) Call

func (s *GatewayDiagnosticLogStreamer) Call(batch []*jsonutil.Object)

Emits one log record per gateway diagnostic event of the batch, scoped by its source logger

func (*GatewayDiagnosticLogStreamer) Exported

func (s *GatewayDiagnosticLogStreamer) Exported() int

Count of log records the streamer emitted

func (*GatewayDiagnosticLogStreamer) Shutdown

func (s *GatewayDiagnosticLogStreamer) Shutdown()

Unsubscribes from the emitter, flushes queued records and shuts the processor down

type GatewayHealthEvent

type GatewayHealthEvent struct {
	Name               string
	GatewayState       *string
	OldState           *string
	NewState           *string
	ExitReason         *string
	RestartRequested   *bool
	ActiveAgents       any
	GatewayBusy        bool
	GatewayDrainable   bool
	PlatformCount      int
	FatalPlatformCount int
	Profile            *string
	InstallID          *string
	Version            *string
	SupervisionMode    *string
	PID                any
	TsNS               int64
}

GatewayHealthEvent is a content free gateway health snapshot or lifecycle event

func NewGatewayHealthEvent

func NewGatewayHealthEvent(name string) GatewayHealthEvent

Health event with the dataclass defaults and the current nanosecond timestamp

func (GatewayHealthEvent) ToDict

func (e GatewayHealthEvent) ToDict() *jsonutil.Object

type GatewayHealthExportRuntime

type GatewayHealthExportRuntime struct {
	Enabled        bool
	Reason         string
	Streamer       *OTLPStreamer
	MetricProvider *sdkmetric.MeterProvider
	LogHandler     *GatewayDiagnosticLogHandler
	LogStreamer    *GatewayDiagnosticLogStreamer
	// contains filtered or unexported fields
}

GatewayHealthExportRuntime owns the metric provider, streamers, log handler and snapshot loop of one export

func StartGatewayHealthExport

func StartGatewayHealthExport(ctx context.Context) *GatewayHealthExportRuntime

Starts the gateway health export the profile enables, a disabled runtime with its reason otherwise

func (*GatewayHealthExportRuntime) Shutdown

func (r *GatewayHealthExportRuntime) Shutdown()

Stops the snapshot loop, detaches the handler, drains the emitter and closes exporters within two seconds

type GatewayHealthSnapshot

type GatewayHealthSnapshot struct {
	Metrics []GatewayMetric
	Events  []Event
}

GatewayHealthSnapshot holds the gauges and events one runtime status read produces

func BuildGatewayHealthSnapshot

func BuildGatewayHealthSnapshot(runtime *jsonutil.Object, gatewayRunning bool, profile, installID, version, supervisionMode string) GatewayHealthSnapshot

Converts gateway_state.json compatible runtime state into service health gauges and events

type GatewayMetric

type GatewayMetric struct {
	Name       string
	Value      any
	Attributes map[string]string
}

GatewayMetric is one exported gauge with its value and string attributes

type InMemorySpanExporter

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

InMemorySpanExporter keeps every exported span, the test double of the OTLP exporter

type MonitoringEmitter

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

MonitoringEmitter owns the bounded queue, the dispatcher goroutine and the subscriber list

func GetEmitter

func GetEmitter() *MonitoringEmitter

Process wide emitter, created disabled until an exporter subscribes

func NewMonitoringEmitter

func NewMonitoringEmitter(enabled bool) *MonitoringEmitter

Emitter that collects only while enabled

func (*MonitoringEmitter) Close

func (e *MonitoringEmitter) Close()

Stops the dispatcher, waiting up to two seconds for it to exit

func (*MonitoringEmitter) Emit

func (e *MonitoringEmitter) Emit(event any)

Enqueues an event without blocking or panicking, dropping the oldest entry when the queue is full; the dispatcher starts once the event is queued

func (*MonitoringEmitter) Flush

func (e *MonitoringEmitter) Flush(timeout float64)

Waits up to timeout seconds for queued and in flight batches to finish dispatch

func (*MonitoringEmitter) Stats

func (e *MonitoringEmitter) Stats() EmitterStats

Queue depth, dispatched and dropped totals and subscriber count

func (*MonitoringEmitter) Subscribe

func (e *MonitoringEmitter) Subscribe(cb *Subscriber)

Registers a live batch subscriber once and enables collection

func (*MonitoringEmitter) Unsubscribe

func (e *MonitoringEmitter) Unsubscribe(cb *Subscriber)

Removes the first registration of a subscriber and disables collection when none remain

type OTLPHTTPSpanExporter

type OTLPHTTPSpanExporter struct {
	Endpoint string
	Headers  map[string]string
	Client   *http.Client
	Resource map[string]string
}

OTLPHTTPSpanExporter posts spans to an OTLP/HTTP traces endpoint as JSON

func BuildExporter

func BuildExporter(ctx context.Context) (*OTLPHTTPSpanExporter, error)

BuildExporter constructs the OTLP span exporter the profile names, an error without a collector address

func NewOTLPHTTPSpanExporter

func NewOTLPHTTPSpanExporter(endpoint string, headers map[string]string) *OTLPHTTPSpanExporter

NewOTLPHTTPSpanExporter targets the endpoint with the resolved headers and a ten second timeout

func (*OTLPHTTPSpanExporter) Export

func (e *OTLPHTTPSpanExporter) Export(spans []*Span) error

Export posts one ExportTraceServiceRequest, a non 2xx status an error

func (*OTLPHTTPSpanExporter) Shutdown

func (e *OTLPHTTPSpanExporter) Shutdown() error

type OTLPStreamer

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

OTLPStreamer pushes each emitter batch to OTLP as spans, scoped to its plane by the event filter

func NewOTLPStreamer

func NewOTLPStreamer(ctx context.Context, eventFilter func(*jsonutil.Object) bool) (*OTLPStreamer, error)

NewOTLPStreamer builds the provider the profile names and the subscriber that exports every batch

func StartStreaming

func StartStreaming(ctx context.Context, eventFilter func(*jsonutil.Object) bool) *OTLPStreamer

StartStreaming attaches a streamer to the singleton emitter when OTLP is enabled, nil otherwise or when the provider cannot build

func (*OTLPStreamer) Call

func (s *OTLPStreamer) Call(batch []*jsonutil.Object)

Call exports the batch after the filter, the emitter callable

func (*OTLPStreamer) Exported

func (s *OTLPStreamer) Exported() int

Exported counts the spans the streamer created

func (*OTLPStreamer) Shutdown

func (s *OTLPStreamer) Shutdown()

Shutdown unsubscribes from the singleton emitter, flushes the processor and shuts the provider down

func (*OTLPStreamer) Subscriber

func (s *OTLPStreamer) Subscriber() *Subscriber

Subscriber is the emitter registration of this streamer

type Span

type Span struct {
	Name       string
	Attributes map[string]any
	TraceID    string
	SpanID     string
	Start, End time.Time
}

Span is one finished monitoring span with its attributes

type SpanExporter

type SpanExporter interface {
	Export(spans []*Span) error
	Shutdown() error
}

SpanExporter receives finished spans in batches

type Subscriber

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

Subscriber receives dispatched batches on the dispatcher goroutine and is matched by identity

func NewSubscriber

func NewSubscriber(fn func(batch []*jsonutil.Object)) *Subscriber

Subscriber handle around a batch callback

type Tracer

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

Tracer records zero duration spans for monitoring events

func (*Tracer) RecordSpan

func (t *Tracer) RecordSpan(name string, attrs map[string]any) error

RecordSpan starts and ends one span with the attributes

type TracerProvider

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

TracerProvider owns the resource and the processor every tracer records spans into

func NewTracerProvider

func NewTracerProvider(resource map[string]string, processor *BatchSpanProcessor) *TracerProvider

NewTracerProvider pairs a resource with a batch processor

func (*TracerProvider) Resource

func (tp *TracerProvider) Resource() map[string]string

Resource returns the provider's resource attributes

func (*TracerProvider) Shutdown

func (tp *TracerProvider) Shutdown()

Shutdown drains the processor or the simple exporter

func (*TracerProvider) Tracer

func (tp *TracerProvider) Tracer(scope string) *Tracer

Tracer returns a tracer recording spans under the instrumentation scope name

Jump to

Keyboard shortcuts

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