Skip to content

[pdata/pcommon] Remove HTML-escaping of special chars when converting Map and Slice Values to JSON strings#14670

Open
zpzhuSplunk wants to merge 1 commit into
open-telemetry:mainfrom
zpzhuSplunk:pdata-encoding
Open

[pdata/pcommon] Remove HTML-escaping of special chars when converting Map and Slice Values to JSON strings#14670
zpzhuSplunk wants to merge 1 commit into
open-telemetry:mainfrom
zpzhuSplunk:pdata-encoding

Conversation

@zpzhuSplunk
Copy link
Copy Markdown
Contributor

Description
Value.AsString() produces inconsistent output for string values containing HTML-special characters (<, >, &). When the Value is of type ValueTypeStr, the raw string is returned with no escaping. However, when the Value is of type ValueTypeMap or ValueTypeSlice, the standard library's json.Marshal HTML-escapes those characters to their Unicode escape sequences (\u003c, \u003e, \u0026).
This fix replaces encoding/json's json.Marshal with github.com/goccy/go-json's json.MarshalWithOption using the json.DisableHTMLEscape() option, so that Map and Slice values are serialized to JSON without HTML escaping, consistent with the behavior of plain string values.
Link to tracking issue
Fixes #14662

Testing
Added two new test cases to TestValueAsString:
map_with_html_chars: verifies that a Map containing the string html&value is serialized as {"key":"html&value"} (not {"key":"\u003cb\u003ehtml\u0026value\u003c/b\u003e"}).
slice_with_html_chars: verifies that a Slice containing strings link and a]>b&c is serialized as ["link","a]>b&c"].
All existing tests in pdata/pcommon continue to pass.

Documentation
A changelog entry was added at .chloggen/fix-value-asstring-html-escaping.yaml describing the bug fix for the pkg/pdata component.

@zpzhuSplunk zpzhuSplunk requested review from a team, bogdandrutu and dmitryax as code owners March 2, 2026 18:09
@zpzhuSplunk zpzhuSplunk force-pushed the pdata-encoding branch 3 times, most recently from b51b91a to 84b80d1 Compare March 2, 2026 18:33
@zpzhuSplunk
Copy link
Copy Markdown
Contributor Author

We added a new dependency goccy/go-json for pdata/pcommon. All modules depending on this will need a go.mod update.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.82%. Comparing base (f21ec9e) to head (611907a).
⚠️ Report is 195 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14670   +/-   ##
=======================================
  Coverage   91.81%   91.82%           
=======================================
  Files         680      680           
  Lines       43043    43043           
=======================================
+ Hits        39522    39525    +3     
+ Misses       2449     2447    -2     
+ Partials     1072     1071    -1     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR, can we confirm first with the specification what the recommended approach is for this? There was a recent change (see open-telemetry/opentelemetry-specification/pull/4848) that established some guidance on representing complex attributes, I would like to understand what the preferred approach is so that the Collector is as consistent as feasible with SDKs

@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added Stale and removed Stale labels Mar 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Apr 8, 2026
@github-actions github-actions Bot removed the Stale label Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pdata] pCommon.Value.AsString function escapes HTML on ValueTypeMap and ValueTypeSlice

2 participants