translator

package module
v0.0.0-...-d98aeb4 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

otlp-prometheus-translator

Experimental dependency-free library to translate metrics and labels from OTLP to Prometheus format.

Documentation

Index

Constants

View Source
const (
	// MetricMetadataTypeKey is the key used to store the original Prometheus
	// type in metric metadata:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#metric-metadata
	MetricMetadataTypeKey = "prometheus.type"
	// ExemplarTraceIDKey is the key used to store the trace ID in Prometheus
	// exemplars:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#exemplars
	ExemplarTraceIDKey = "trace_id"
	// ExemplarSpanIDKey is the key used to store the Span ID in Prometheus
	// exemplars:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#exemplars
	ExemplarSpanIDKey = "span_id"
	// ScopeInfoMetricName is the name of the metric used to preserve scope
	// attributes in Prometheus format:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope
	ScopeInfoMetricName = "otel_scope_info"
	// ScopeNameLabelKey is the name of the label key used to identify the name
	// of the OpenTelemetry scope which produced the metric:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope
	ScopeNameLabelKey = "otel_scope_name"
	// ScopeVersionLabelKey is the name of the label key used to identify the
	// version of the OpenTelemetry scope which produced the metric:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope
	ScopeVersionLabelKey = "otel_scope_version"
	// TargetInfoMetricName is the name of the metric used to preserve resource
	// attributes in Prometheus format:
	// https://github.com/open-telemetry/opentelemetry-specification/blob/e6eccba97ebaffbbfad6d4358408a2cead0ec2df/specification/compatibility/prometheus_and_openmetrics.md#resource-attributes-1
	// It originates from OpenMetrics:
	// https://github.com/OpenObservability/OpenMetrics/blob/1386544931307dff279688f332890c31b6c5de36/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems
	TargetInfoMetricName = "target_info"
)

Variables

This section is empty.

Functions

func BuildCompliantMetricName

func BuildCompliantMetricName(name, unit string, metricType MetricType, addMetricSuffixes bool) string

BuildCompliantMetricName builds a Prometheus-compliant metric name for the specified metric.

Metric name is prefixed with specified namespace and underscore (if any). Namespace is not cleaned up. Make sure specified namespace follows Prometheus naming convention.

See rules at https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels, https://prometheus.io/docs/practices/naming/#metric-and-label-naming and https://github.com/open-telemetry/opentelemetry-specification/blob/v1.38.0/specification/compatibility/prometheus_and_openmetrics.md#otlp-metric-points-to-prometheus.

func BuildMetricName

func BuildMetricName(name, unit string, metricType MetricType, addMetricSuffixes bool) string

BuildMetricName builds a valid metric name but without following Prometheus naming conventions. It doesn't do any character transformation, it only prefixes the metric name with the namespace, if any, and adds metric type suffixes, e.g. "_total" for counters and unit suffixes.

Differently from BuildCompliantMetricName, it doesn't check for the presence of unit and type suffixes. If "addMetricSuffixes" is true, it will add them anyway.

Please use BuildCompliantMetricName for a metric name that follows Prometheus naming conventions.

func NormalizeLabel

func NormalizeLabel(label string) string

Normalizes the specified label to follow Prometheus label names standard.

See rules at https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels.

Labels that start with non-letter rune will be prefixed with "key_". An exception is made for double-underscores which are allowed.

func SanitizeLabelName

func SanitizeLabelName(name string) string

SanitizeLabelName replaces anything that doesn't match client_label.LabelNameRE with an underscore. Note: this does not handle all Prometheus label name restrictions (such as not starting with a digit 0-9), and hence should only be used if the label name is prefixed with a known valid string.

Types

type MetricType

type MetricType string
const (
	MetricTypeNonMonotonicCounter  MetricType = "non-monotonic-counter"
	MetricTypeMonotonicCounter     MetricType = "monotonic-counter"
	MetricTypeGauge                MetricType = "gauge"
	MetricTypeHistogram            MetricType = "histogram"
	MetricTypeExponentialHistogram MetricType = "exponential-histogram"
	MetricTypeSummary              MetricType = "summary"
	MetricTypeUnknown              MetricType = "unknown"
)

Jump to

Keyboard shortcuts

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