observability

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package observability provides metrics and monitoring for ReleasePilot.

Package observability provides metrics, tracing, and monitoring for ReleasePilot.

Index

Constants

View Source
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 SetTracer

func SetTracer(t Tracer)

SetTracer sets the global tracer instance.

func ShutdownTracer

func ShutdownTracer(ctx context.Context) error

ShutdownTracer gracefully shuts down the global tracer.

func TraceFunc

func TraceFunc(ctx context.Context, name string, fn func(ctx context.Context) error) error

TraceFunc is a helper to trace a function execution.

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

func InitGlobal(version string) *Metrics

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

func NewMetrics(version string) *Metrics

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

func (m *Metrics) Handler() http.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

func (m *Metrics) RecordCommandInvocation(command string, duration time.Duration)

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

func (m *Metrics) RecordPluginExecution(pluginName string, success bool, duration time.Duration)

RecordPluginExecution records a plugin execution.

func (*Metrics) RecordRelease

func (m *Metrics) RecordRelease(success bool, duration time.Duration)

RecordRelease records a release operation.

func (*Metrics) SetActiveReleases

func (m *Metrics) SetActiveReleases(count int64)

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

func SpanFromContext(ctx context.Context) Span

SpanFromContext returns the current span from context, or a noop span.

func StartSpan

func StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)

StartSpan starts a new span using the global tracer.

type SpanContext

type SpanContext struct {
	TraceID string
	SpanID  string
}

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.

func WithSpanKind

func WithSpanKind(kind SpanKind) SpanOption

WithSpanKind sets the span kind.

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 GetTracer

func GetTracer() Tracer

GetTracer returns the global tracer instance.

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.

func NewLoggingTracer

func NewLoggingTracer(logger *slog.Logger, serviceName string) Tracer

NewLoggingTracer creates a new logging tracer for development/debugging.

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.

Jump to

Keyboard shortcuts

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