Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus label keys must not include colons #2289

Closed
dashpole opened this issue Sep 1, 2023 · 0 comments · Fixed by #2330
Closed

Prometheus label keys must not include colons #2289

dashpole opened this issue Sep 1, 2023 · 0 comments · Fixed by #2330
Labels
bug Something isn't working triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@dashpole
Copy link
Contributor

dashpole commented Sep 1, 2023

What is the expected behavior?

From https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md#metric-attributes,

OpenTelemetry Metric Attributes MUST be converted to Prometheus labels. String Attribute values are converted directly to Metric Attributes, and non-string Attribute values MUST be converted to string attributes following the attribute specification. Prometheus metric label keys are required to match the following regex: [a-zA-Z_]([a-zA-Z0-9_])*.

Metric names are allowed to include colons, but label keys are not.

What is the actual behavior?

SetMetricBasic translates attributes to prometheus labels:

void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &metric,
std::chrono::nanoseconds time,
const metric_sdk::PointAttributes &labels)
{
metric.timestamp_ms = time.count() / 1000000;
// auto label_pairs = ParseLabel(labels);
if (!labels.empty())
{
metric.label.resize(labels.size());
size_t i = 0;
for (auto const &label : labels)
{
auto sanitized = SanitizeNames(label.first);
metric.label[i].name = sanitized;
metric.label[i++].value = AttributeValueToString(label.second);

It uses the same sanitization function used for metric names:

std::string PrometheusExporterUtils::SanitizeNames(std::string name)
{
constexpr const auto replacement = '_';
constexpr const auto replacement_dup = '=';
auto valid = [](int i, char c) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ':' ||
(c >= '0' && c <= '9' && i > 0))
{

...which allows colons as a valid character.

@dashpole dashpole added the bug Something isn't working label Sep 1, 2023
@github-actions github-actions bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Sep 1, 2023
@lalitb lalitb assigned esigo and unassigned esigo Sep 1, 2023
@marcalff marcalff added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 6, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 25, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 26, 2023
punya added a commit to punya/opentelemetry-cpp that referenced this issue Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants