otelhealth

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package otelhealth exports health.State data via OpenTelemetry.

otelhealth allows you to take the state from a health server and export the data in it via OpenTelemetry metrics. For example, to track the readiness of your server over time you can use OpenTelemetry to export via Prometheus metrics where you can graph and alert on your service not being ready. It also allows you to export version information so you can easily correlate version changes with changes in other metrics making it easier to identify regressions.

The servers in github.com/anz-bank/pkg/health all have a State field. This can be passed to the Register function in this package to have that state provided as OpenTelemetry metrics.

Two metrics are published by this package: - anz_health_ready - anz_health_version

The "ready" metric tracks the real-time value of the Ready field in the State, exporting false as 0 and true as 1.

The "version" metric is constant - it is exported as 1 and never changes. It is the labels on this that are the part of interest. The fields of the Version in the State are exported as labels on the metric. The current labels are "build_log_url", "commit_hash", "container_tag", "semver" and "repo_url".

The prefix "anz_health" is configurable with the WithPrefix Option that can be passed to Register. The prefix can be removed entirely by using the empty string as a prefix.

Index

Constants

View Source
const (
	// CommitHash is the git hash.
	CommitHash = otelAttribute.Key("commit_hash")
	// BuildLogURL is the url for the build log.
	BuildLogURL = otelAttribute.Key("build_log_url")
	// ContainerTag is the tag of container.
	ContainerTag = otelAttribute.Key("container_tag")
	// RepoURL is the url of the github repository.
	RepoURL = otelAttribute.Key("repo_url")
	// Semver is the version.
	Semver = otelAttribute.Key("semver")
)

Variables

This section is empty.

Functions

func Register

func Register(s *health.State, options ...Option) error

Register creates a metrics registry with values from the given health.State. The metrics registry tracks changes to the non-constant values in the health.State.

Types

type Int64Counter

type Int64Counter interface {
	Add(ctx context.Context, value int64, opts ...metric.AddOption)
}

Int64Counter is the interface for otel `metric.Int64Counter` interface.

type Option

type Option func(*registerOptions)

Option is used to configure the registration of the health state. The With* functions should be used to obtain options for passing to Register.

func WithConstLabels

func WithConstLabels(labels map[otelAttribute.Key]otelAttribute.Value) Option

WithConstLabels returns an Option that adds additional labels with constant values to the metrics published by this package.

func WithPrefix

func WithPrefix(metricPrefix string) Option

WithPrefix returns an option that sets the prefix on the metric name published by this package. The default is "anz_health" which can be overidden with this option. The empty string removes the prefix. Any other value will be used as the prefix with an underscore separating the prefix from the base metric name.

Jump to

Keyboard shortcuts

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