open-telemetry / opentelemetry-rust

The Rust OpenTelemetry implementation
https://opentelemetry.io
Apache License 2.0
1.79k stars 414 forks source link

[Bug]: Meter attributes seem to be missing when using Prometheus exporter #1910

Open ikaros opened 2 months ago

ikaros commented 2 months ago

What happened?

The Meter's attributes seem to no be appended when using Prometheues Exporter.

I created a small example sandbox to reproduce the behvavior.

The relevant output line is

< asdf_stuff_total{key="value",otel_scope_name="my-app"} 100
> asdf_stuff_total{missing_attribute="missing_on_prometheus",key="value",otel_scope_name="my-app"} 100

Example Project

Cargo.toml

[package]
name = "otlp_api"
version = "0.1.0"
edition = "2021"

[dependencies]
opentelemetry = "0.23.0"
opentelemetry-prometheus = "0.16.0"
opentelemetry_sdk = "0.23.0"
prometheus = "0.13.4"

main.rs

use opentelemetry::{metrics::MeterProvider, trace::FutureExt, KeyValue};
use opentelemetry_sdk::metrics::SdkMeterProvider;
use prometheus::{Encoder, TextEncoder};
use std::borrow::Cow;

fn main() {
    let registry = prometheus::Registry::new();

    let exporter = opentelemetry_prometheus::exporter()
        .with_registry(registry.clone())
        .build()
        .unwrap();
    let provider = SdkMeterProvider::builder().with_reader(exporter).build();
    let attributes = vec![KeyValue::new("missing_attribute", "missing_on_prometheus")];
    let meter = provider.versioned_meter(
        "my-app",
        None::<Cow<'static, str>>,
        None::<Cow<'static, str>>,
        Some(attributes),
    );

    let counter = meter
        .u64_counter("stuff")
        .with_description("Counts things")
        .init();
    counter.add(100, &[KeyValue::new("key", "value")]);

    TextEncoder::new()
        .encode(&registry.gather(), &mut std::io::stdout().lock())
        .unwrap();
}

API Version

0.23.0

SDK Version

0.23.0

What Exporter(s) are you seeing the problem on?

No response

Relevant log output

# HELP asdf_stuff_total Counts things
# TYPE asdf_stuff_total counter
asdf_stuff_total{key="value",otel_scope_name="my-app"} 100
# HELP otel_scope_info Instrumentation Scope metadata
# TYPE otel_scope_info gauge
otel_scope_info{otel_scope_name="my-app"} 1
# HELP target_info Target metadata
# TYPE target_info gauge
target_info{service_name="unknown_service",telemetry_sdk_language="rust",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="0.23.0"} 1
cijothomas commented 1 month ago

Thanks for reporting the issue. Meter attributes are not supported yet on Prometheus exporter. We are currently prioritizing core api/stable sdk + OTLP exporters only, it'll be a while when Prometheus exporters add this capability.