Home > Mobile >  How can find or correctly export resource labels of OpenTelemetry metrics in Prometeus?
How can find or correctly export resource labels of OpenTelemetry metrics in Prometeus?

Time:02-16

I am creating an application using .Net with OpenTelemetry for collecting metrics, traces. .Net application uses Otlp exporter. Also, I have configured a collector that has Otlp as a receiver and Prometheus as exporter for metrics.

I setup ServiceName (ex."OpenTelemetrySample") and set some attributes (ex. attributeA,attributeB) in my .Net application

services.AddOpenTelemetryMetrics(builder =>{ 
     builder.SetResourceBuilder(ResourceBuilder.CreateDefault()
            .AddService("OpenTelemetrySample")
            .AddAttributes(new KeyValuePair<string, object>[]
            {new("attributeA", "AAA"), new("attributeB", "BBB")}));
     builder.AddMeter("opentelemetry-meter");
     builder.AddOtlpExporter(otlpOptions =>
            {otlpOptions.Endpoint = new Uri("http://localhost:4317");   
            });
          });

Then I am using some Counter in the code:

static Meter myMeter = new("opentelemetry-meter", "1.0.0");
static Counter<int> myCounter = myMeter.CreateCounter<int>(name: $"test-counter",
            unit: "Counter",
            description: "The number of something");
...
myCounter.Add(2, new("custom.tagA", "tagValueA"), new("custom.tagB", "tagValueB"));

The result that I see in PrometeusUI is: here I expected to see somewhere service.name and attributes of resources, but can not find them in Prometheus UI.

For example, the same process, when I export metrics through console of collector shows mentioned attributes in section Resource labels

Console output:

collector            | 2022-02-15T13:01:40.968Z INFO    loggingexporter/logging_exporter.go:56  MetricsExporter {"#metrics": 1}
collector            | 2022-02-15T13:01:40.968Z DEBUG   loggingexporter/logging_exporter.go:66  ResourceMetrics #0
collector            | Resource labels:
collector            |      -> attributeA: STRING(AAA)
collector            |      -> attributeB: STRING(BBB)
collector            |      -> service.name: STRING(OpenTelemetrySample)
collector            |      -> service.instance.id: STRING(0f08e609-66e0-49a5-ad6d-44c8e3520bad)
collector            | InstrumentationLibraryMetrics #0
collector            | InstrumentationLibrary opentelemetry-meter 1.0.0
collector            | Metric #0
collector            | Descriptor:
collector            |      -> Name: test-counter
collector            |      -> Description: The number of something
collector            |      -> Unit: Counter
collector            |      -> DataType: Sum
collector            |      -> IsMonotonic: true
collector            |      -> AggregationTemporality: AGGREGATION_TEMPORALITY_CUMULATIVE
collector            | NumberDataPoints #0
collector            | Data point attributes:
collector            |      -> custom.tagA: STRING(tagValueA)
collector            |      -> custom.tagB: STRING(tagValueB)
collector            | StartTimestamp: 2022-02-15 12:26:55.3992028  0000 UTC
collector            | Timestamp: 2022-02-15 13:01:40.5841487  0000 UTC
collector            | Value: 2

otel-collector-config.yaml

receivers:
  otlp:
    protocols:
      grpc:
exporters:
    logging:
      loglevel: debug
    jaeger:
      endpoint: jaeger:14250
      insecure: true
    prometheus:
      endpoint: "0.0.0.0:8889"
extensions:
  health_check:
  pprof:
  zpages:
processors:
    batch:
service:
    extensions: [health_check,pprof,zpages]
    pipelines:
        traces:
            receivers: [otlp]
            exporters: [logging, jaeger]
            processors: [batch]
        metrics:
            receivers: [otlp]          
            exporters: [logging, prometheus]
            processors: [batch]            
        logs:
            receivers: [otlp]
            exporters: [logging]
            processors: [batch]

prometheus.yaml

scrape_configs:
  - job_name: 'otel-collector'
    scrape_interval: 5s
    static_configs:
      - targets: ['collector:8889']

Looking for any idea how to find or export correctly resource labels for metrics correctly, thank you

CodePudding user response:

The resource attributes to metrics label conversion is disabled by default. Please update the otel config to following to see the resource attribute is prom UI.

receivers:
  otlp:
    protocols:
      grpc:
exporters:
    logging:
      loglevel: debug
    jaeger:
      endpoint: jaeger:14250
      insecure: true
    prometheus:
      endpoint: "0.0.0.0:8889"
      resource_to_telemetry_conversion:
        enabled: true
extensions:
  health_check:
  pprof:
  zpages:
processors:
    batch:
service:
    extensions: [health_check,pprof,zpages]
    pipelines:
        traces:
            receivers: [otlp]
            exporters: [logging, jaeger]
            processors: [batch]
        metrics:
            receivers: [otlp]          
            exporters: [logging, prometheus]
            processors: [batch]            
        logs:
            receivers: [otlp]
            exporters: [logging]
            processors: [batch]

  • Related