Skip to content

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

@zpzhuSplunk

Description

@zpzhuSplunk

Component(s)

pdata

What happened?

Describe the bug

There is a misalignment on how Value.AsString works with value of string type and values of map and slice.
HTML escaping is not done for strings but done for map and slices.
For instance, "<".ToString() -> "<" but ["<"].ToString() -> ["\u003c"] and {"key": "<"}.ToString()
-> {"key": "\u003c"}.

We should make map and slice to not escape HTML as well so
["<"].ToString() -> ["<"] and {"key": "<"}.ToString() -> {"key": "<"}.

The issue is https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/pcommon/value.go#L404 and https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/pcommon/value.go#L411 uses Go's encoding/json which escapes HTML when Marshalling.

Steps to reproduce

  1. Configure the collector with a receiver and exporter that uses pdata.
  2. Send an event whose body is of type map or slice and contains "<" ">" or "&"
  3. See the exported event body contains escaped HTML.

What did you expect to see?

Nothing should be escaped.
"<".AsString() -> "<" | ["<"].AsString() -> ["<"] | {"key": "<"}.AsString() -> {"key": "<"}.

What did you see instead?

"<".AsString() -> "<" but ["<"].AsString() -> ["\u003c"] and {"key": "<"}.AsString()
-> {"key": "\u003c"}.

Collector version

v1.52.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

Log output

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions