Skip to content

Fix serialization of array-valued scope and resource attributes in Prometheus exporter#8497

Draft
thswlsqls wants to merge 1 commit into
open-telemetry:mainfrom
thswlsqls:fix/prometheus-scope-resource-array-label-json
Draft

Fix serialization of array-valued scope and resource attributes in Prometheus exporter#8497
thswlsqls wants to merge 1 commit into
open-telemetry:mainfrom
thswlsqls:fix/prometheus-scope-resource-array-label-json

Conversation

@thswlsqls

Copy link
Copy Markdown
Contributor

Fixes #5987

Description

  • In Otel2PrometheusConverter.convertAttributes(), scope and resource attributes were serialized with raw Object.toString(), so array values became [a, b] (no quotes, no escaping) instead of valid JSON.
  • Both paths now use the existing toLabelValue(AttributeType, Object) helper, matching the point-attribute path which already JSON-encodes arrays as ["a","b"]. Scalar output (STRING/BOOLEAN/LONG/DOUBLE) is unchanged because toLabelValue returns toString() for them.
  • Completes the incomplete fix from Prometheus label conversion refactored to align with spec #7291 (which aligned only the point-attribute path with the spec). Spec: non-string attribute values are encoded as JSON strings (OTel Prometheus compatibility, common attributes).

Testing done

  • Added Otel2PrometheusConverterTest#arrayValuedScopeAttributeSerializedAsJson (scope otel_scope_* label) and an array-valued resource attribute case in resourceAttributesAdditionArgs (resource label). Both fail before the fix, pass after.
  • ./gradlew :exporters:prometheus:check — 192 tests pass (Otel2PrometheusConverterTest green; one unrelated flaky PrometheusHttpServerTest.fetch_DuplicateMetrics log-assertion fails intermittently and passes on rerun/in isolation).
  • Private-method change only: no public API change, no docs/apidiffs diff.
  • Added a ## Unreleased entry in CHANGELOG.md.

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.77%. Comparing base (824334c) to head (c3a1c95).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8497   +/-   ##
=========================================
  Coverage     78.77%   78.77%           
  Complexity     8579     8579           
=========================================
  Files          1009     1009           
  Lines         28993    28995    +2     
  Branches       3599     3599           
=========================================
+ Hits          22839    22841    +2     
  Misses         5311     5311           
  Partials        843      843           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix serialization of arrays in prometheus exporter

1 participant