Skip to content

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

Merged
jack-berg merged 3 commits into
open-telemetry:mainfrom
thswlsqls:fix/prometheus-scope-resource-array-label-json
Jul 10, 2026
Merged

Fix serialization of array-valued scope and resource attributes in Prometheus exporter#8497
jack-berg merged 3 commits 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 91.61%. Comparing base (0004c7e) to head (95c98a0).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8497   +/-   ##
=========================================
  Coverage     91.60%   91.61%           
  Complexity    10310    10310           
=========================================
  Files          1013     1013           
  Lines         27258    27260    +2     
  Branches       3201     3201           
=========================================
+ Hits          24971    24973    +2     
  Misses         1560     1560           
  Partials        727      727           

☔ 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.

@jack-berg jack-berg added the needs author feedback Waiting for additional feedback from the author label Jul 2, 2026
@thswlsqls
thswlsqls marked this pull request as ready for review July 4, 2026 09:07
@thswlsqls
thswlsqls requested a review from a team as a code owner July 4, 2026 09:07
The unfilled ([#XXXX](.../pull/XXXX)) link failed markdown-link-check.
@thswlsqls

Copy link
Copy Markdown
Contributor Author

Ready for review. Removed the placeholder CHANGELOG link that was failing markdown-link-check.

@github-actions github-actions Bot removed the needs author feedback Waiting for additional feedback from the author label Jul 5, 2026
@jack-berg
jack-berg merged commit 6ee54e5 into open-telemetry:main Jul 10, 2026
28 checks passed
@otelbot

otelbot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @thswlsqls! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

@thswlsqls
thswlsqls deleted the fix/prometheus-scope-resource-array-label-json branch July 11, 2026 00:18
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

3 participants