Documentation
¶
Overview ¶
Package runtimeinfo provides build-time metadata injected via -ldflags.
It offers a standard way to embed version, commit, and other build information into a Go binary and expose it in common formats for observability.
Example usage in build scripts ¶
go build -ldflags "\ -X github.com/froppa/stackkit/kits/runtimeinfo.Version=1.2.3 \ -X github.com/froppa/stackkit/kits/runtimeinfo.Commit=sha256 \ -X github.com/froppa/stackkit/kits/runtimeinfo.BuiltBy=ci \ -X github.com/froppa/stackkit/kits/runtimeinfo.Date=2025-07-15T12:00:00Z \ -X github.com/froppa/stackkit/kits/runtimeinfo.GoVersion=go1.21.4 \ -X github.com/froppa/stackkit/kits/runtimeinfo.Name=your-service-name \ -X github.com/froppa/stackkit/kits/runtimeinfo.Description='Your service description'"
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Name is the service or binary name. Injected at build time. Name string // Description is a human-readable description of the service. Optional. Description string // Version is the semantic version of the build (e.g. v1.0.0). // Defaults to "dev" if unset. Version = "dev" // Commit is the Git commit hash of the build. Commit string // Date is the UTC timestamp when the binary was built. Date string // BuiltBy is the name of the builder (e.g. CI system or developer). BuiltBy string // GoVersion is the Go toolchain version used to compile the binary. GoVersion string )
Functions ¶
func Fields ¶
Fields returns the build metadata as zap fields for structured logging. Useful for injecting metadata into root loggers.
func OTELAttributes ¶
OTELAttributes returns the build metadata as OpenTelemetry resource attributes. These attributes align with OpenTelemetry semantic conventions where applicable, making them automatically understandable by observability platforms.
func PrometheusLabelKeys ¶
func PrometheusLabelKeys() []string
PrometheusLabelKeys returns a stable list of label keys for Prometheus metrics. This ensures deterministic ordering when registering metrics with constant labels.
func PrometheusLabelValues ¶
func PrometheusLabelValues() []string
PrometheusLabelValues returns the current values for each Prometheus label key, in the same order as returned by PrometheusLabelKeys().
Types ¶
type Meta ¶
type Meta struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
Commit string `json:"git_commit"`
Date string `json:"build_time"`
BuiltBy string `json:"built_by"`
GoVersion string `json:"go_version"`
}
Meta contains the full build metadata for introspection or logging.
func GetMetadata ¶
func GetMetadata() Meta
GetMetadata returns a snapshot of the current build metadata.