opentelemetry-java
opentelemetry-java copied to clipboard
Fix serialization of array-valued scope and resource attributes in Prometheus exporter
Fixes #5987
Description
- In
Otel2PrometheusConverter.convertAttributes(), scope and resource attributes were serialized with rawObject.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 becausetoLabelValuereturnstoString()for them. - Completes the incomplete fix from #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(scopeotel_scope_*label) and anarray-valued resource attributecase inresourceAttributesAdditionArgs(resource label). Both fail before the fix, pass after. ./gradlew :exporters:prometheus:check— 192 tests pass (Otel2PrometheusConverterTestgreen; one unrelated flakyPrometheusHttpServerTest.fetch_DuplicateMetricslog-assertion fails intermittently and passes on rerun/in isolation).- Private-method change only: no public API change, no
docs/apidiffsdiff. - Added a
## Unreleasedentry inCHANGELOG.md.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: 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
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Ready for review. Removed the placeholder CHANGELOG link that was failing markdown-link-check.
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.