Documentation
¶
Overview ¶
Package observability provides metrics and monitoring for ReleasePilot.
Package observability provides metrics, tracing, and monitoring for ReleasePilot.
Index ¶
- Constants
- func SetTracer(t Tracer)
- func ShutdownTracer(ctx context.Context) error
- func TraceFunc(ctx context.Context, name string, fn func(ctx context.Context) error) error
- type Metrics
- func (m *Metrics) DecrementActiveReleases()
- func (m *Metrics) Handler() http.Handler
- func (m *Metrics) IncrementActiveReleases()
- func (m *Metrics) RecordCommandInvocation(command string, duration time.Duration)
- func (m *Metrics) RecordPluginExecution(pluginName string, success bool, duration time.Duration)
- func (m *Metrics) RecordRelease(success bool, duration time.Duration)
- func (m *Metrics) SetActiveReleases(count int64)
- func (m *Metrics) Snapshot() MetricsSnapshot
- type MetricsSnapshot
- type Span
- type SpanContext
- type SpanKind
- type SpanOption
- type SpanStatus
- type Tracer
- type TracerConfig
Constants ¶
const ( AttrReleaseVersion = "release.version" AttrReleaseType = "release.type" AttrRepositoryOwner = "repository.owner" AttrRepositoryName = "repository.name" AttrPluginName = "plugin.name" AttrPluginHook = "plugin.hook" AttrCommandName = "command.name" AttrGitBranch = "git.branch" AttrGitCommit = "git.commit" AttrAIProvider = "ai.provider" AttrAIModel = "ai.model" AttrErrorType = "error.type" AttrErrorMessage = "error.message" )
Common span attribute keys.
Variables ¶
This section is empty.
Functions ¶
func ShutdownTracer ¶
ShutdownTracer gracefully shuts down the global tracer.
Types ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics provides application metrics collection. It exposes Prometheus-compatible metrics at /metrics endpoint.
func Global ¶
func Global() *Metrics
Global returns the global metrics instance. If InitGlobal has not been called, this will initialize with "unknown" version. For proper initialization, call InitGlobal before any calls to Global.
func InitGlobal ¶
InitGlobal initializes the global metrics instance with version info. This should be called early in application startup, before any calls to Global(). If Global() was called first, the version may already be set to "unknown".
func NewMetrics ¶
NewMetrics creates a new Metrics instance. Pre-initializes metrics for known commands to reduce lock contention.
func (*Metrics) DecrementActiveReleases ¶
func (m *Metrics) DecrementActiveReleases()
DecrementActiveReleases decrements the active release count.
func (*Metrics) Handler ¶
Handler returns an HTTP handler for the /metrics endpoint. The output is Prometheus-compatible text format.
func (*Metrics) IncrementActiveReleases ¶
func (m *Metrics) IncrementActiveReleases()
IncrementActiveReleases increments the active release count.
func (*Metrics) RecordCommandInvocation ¶
RecordCommandInvocation records a CLI command invocation. Uses optimistic read lock for pre-initialized commands (hot path), falling back to write lock only for unknown commands.
func (*Metrics) RecordPluginExecution ¶
RecordPluginExecution records a plugin execution.
func (*Metrics) RecordRelease ¶
RecordRelease records a release operation.
func (*Metrics) SetActiveReleases ¶
SetActiveReleases sets the number of active releases.
func (*Metrics) Snapshot ¶
func (m *Metrics) Snapshot() MetricsSnapshot
Snapshot returns a snapshot of current metrics.
type MetricsSnapshot ¶
type MetricsSnapshot struct {
ReleasesTotal int64
ReleasesSuccessful int64
ReleasesFailed int64
ActiveReleases int64
PluginExecutions int64
PluginErrors int64
CommandInvocations map[string]int64
Uptime time.Duration
}
MetricsSnapshot represents a point-in-time snapshot of metrics.
type Span ¶
type Span interface {
// End completes the span.
End()
// SetStatus sets the span status.
SetStatus(status SpanStatus, description string)
// SetAttribute sets a span attribute.
SetAttribute(key string, value any)
// SetAttributes sets multiple span attributes.
SetAttributes(attrs map[string]any)
// RecordError records an error on the span.
RecordError(err error)
// AddEvent adds an event to the span.
AddEvent(name string, attrs map[string]any)
// SpanContext returns the span context for propagation.
SpanContext() SpanContext
}
Span represents a unit of work or operation.
func SpanFromContext ¶
SpanFromContext returns the current span from context, or a noop span.
type SpanContext ¶
SpanContext contains identifying trace information about a Span.
type SpanKind ¶
type SpanKind int
SpanKind represents the type of span.
const ( // SpanKindInternal represents an internal operation. SpanKindInternal SpanKind = iota // SpanKindServer represents a server-side operation. SpanKindServer // SpanKindClient represents a client-side operation. SpanKindClient // SpanKindProducer represents a message producer. SpanKindProducer // SpanKindConsumer represents a message consumer. SpanKindConsumer )
type SpanOption ¶
type SpanOption func(*spanConfig)
SpanOption configures a span.
func WithAttributes ¶
func WithAttributes(attrs map[string]any) SpanOption
WithAttributes sets initial span attributes.
type SpanStatus ¶
type SpanStatus int
SpanStatus represents the status of a span.
const ( // SpanStatusUnset indicates the span status is not set. SpanStatusUnset SpanStatus = iota // SpanStatusOK indicates the operation completed successfully. SpanStatusOK // SpanStatusError indicates the operation failed. SpanStatusError )
type Tracer ¶
type Tracer interface {
// Start creates a new span and returns it along with a new context.
Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
// Shutdown gracefully shuts down the tracer.
Shutdown(ctx context.Context) error
}
Tracer creates spans for tracing operations.
func InitTracer ¶
func InitTracer(cfg TracerConfig) (Tracer, error)
InitTracer initializes the global tracer with the given configuration. If tracing is disabled, a noop tracer is used. If no OTLP endpoint is available, a logging tracer is used for development.
type TracerConfig ¶
type TracerConfig struct {
// Enabled indicates whether tracing is enabled.
Enabled bool
// ServiceName is the name of the service for tracing.
ServiceName string
// ServiceVersion is the version of the service.
ServiceVersion string
// Environment is the deployment environment (dev, staging, prod).
Environment string
// Endpoint is the OTLP endpoint URL (e.g., "localhost:4317").
Endpoint string
// Insecure disables TLS for the OTLP connection.
Insecure bool
// SampleRate is the sampling rate (0.0 to 1.0, default 1.0 = sample all).
SampleRate float64
// Headers are additional headers to send with OTLP requests.
Headers map[string]string
}
TracerConfig configures the tracing system.
func DefaultTracerConfig ¶
func DefaultTracerConfig() TracerConfig
DefaultTracerConfig returns a default tracer configuration.