Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus

  • v0.114.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Prometheus Normalization

OpenTelemetry's metric semantic convention is not compatible with Prometheus' own metrics naming convention. This module provides centralized functions to convert OpenTelemetry metrics to Prometheus-compliant metrics. These functions are used by the following components for Prometheus:

Metric name

Full normalization

Warning

This feature can be controlled with feature gate pkg.translator.prometheus.NormalizeName. It is currently enabled by default (beta stage).

Example of how to disable it:

$ otelcol --config=config.yaml --feature-gates=-pkg.translator.prometheus.NormalizeName
List of transformations to convert OpenTelemetry metrics to Prometheus metrics
CaseTransformationExample
Unsupported characters and extraneous underscoresReplace unsupported characters with underscores (_). Drop redundant, leading and trailing underscores.(lambda).function.executions(#)lambda_function_executions
Standard unitConvert the unit from Unified Code for Units of Measure to Prometheus standard and appendsystem.filesystem.usage with unit Bysystem_filesystem_usage_bytes
Non-standard unit (unit is surrounded with {})Drop the unitsystem.network.dropped with unit {packets}system_network_dropped
Non-standard unit (unit is not surrounded with {})Append the unit, if not already present, after sanitization (all non-alphanumeric chars are dropped)system.network.dropped with unit packetssystem_network_dropped_packets
Percentages (unit is 1)Append _ratio (for gauges only)system.memory.utilization with unit 1system_memory_utilization_ratio
Percentages (unit is %)Replace % with percent _percentstorage.filesystem.utilization with unit %storage_filesystem_utilization_percent
Rates (unit contains /)Replace / with perastro.light.speed with unit m/sastro_light_speed_meters_per_second
CounterAppend _totalsystem.processes.createdsystem_processes_created_total

List of standard OpenTelemetry units that will be translated to Prometheus standard base units:

OpenTelemetry UnitCorresponding Prometheus Unit
Time
ddays
hhours
minminutes
sseconds
msmilliseconds
usmicroseconds
nsnanoseconds
Bytes
Bybytes
KiBykibibytes
MiBymebibytes
GiBygibibytes
TiBytibibytes
KBykilobytes
MBymegabytes
GBygigabytes
TByterabytes
SI Units
mmeters
Vvolts
Aamperes
Jjoules
Wwatts
ggrams
Misc.
Celcelsius
Hzhertz
%percent

Note Prometheus also recommends using base units (no kilobytes, or milliseconds, for example) but these functions will not attempt to convert non-base units to base units.

List of transformations performed to convert Prometheus metrics to OpenTelemetry metrics
CaseTransformationExample
UNIT defined in OpenMetrics formatDrop the unit suffix and set it in the OpenTelemetry metric unit fieldsystem_network_dropped_packetssystem_network_dropped with packets unit
CounterDrop _total suffixsystem_processes_created_totalsystem_processes_created

Simple normalization

If feature pkg.translator.prometheus.NormalizeName is not enabled, a simple sanitization of the OpenTelemetry metric name is performed to ensure it follows Prometheus naming conventions:

  • Drop unsupported characters and replace with underscores (_)
  • Remove redundant, leading and trailing underscores
  • Ensure metric name doesn't start with a digit by prefixing with an underscore

No processing of the unit is performed, and _total is not appended for Counters.

Labels

OpenTelemetry Attributes are converted to Prometheus labels and normalized to follow the Prometheus labels naming rules.

The following transformations are performed on OpenTelemetry Attributes to produce Prometheus labels:

  • Drop unsupported characters and replace with underscores (_)
  • Prefix label with key_ if it doesn't start with a letter, except if it's already prefixed with double-underscore (__)

By default, labels that start with a simple underscore (_) are prefixed with key, which is strictly unnecessary to follow Prometheus labels naming rules. This behavior can be disabled with the feature pkg.translator.prometheus.PermissiveLabelSanitization, which must be activated with the feature gate option of the collector:

$ otelcol --config=config.yaml --feature-gates=pkg.translator.prometheus.PermissiveLabelSanitization

Examples:

OpenTelemetry AttributePrometheus Label
namename
host.namehost_name
host_namehost_name
name (of the host)name__of_the_host_
2 centskey_2_cents
__name__name
_namekey_name
_name_name (if PermissiveLabelSanitization is enabled)

FAQs

Package last updated on 18 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc