Skip to content

Buffers are not serialised correctly as per the protoJSON specification #6190

@alistairjevans

Description

@alistairjevans

What happened?

If I specify a "Buffer" as an attribute to an OTel object (trace/log), and I'm using the OTLP HTTP Exporter, the Buffer is serialised into the attribute as:

"bytesValue": {
    "type": "Buffer",
    "data": [
        105,
        50,
        214,
        222,
        243,
        159,
        243,
        10,
        202,
        225,
        43,
        40
    ]
}

Where it should be a base64 string, as per the spec: https://protobuf.dev/programming-guides/json/#field-representation

This problem prevents code based on the protobuf spec from being able to decode this data; e.g. in the ruby protobuf library:

Error occurred during parsing: Error parsing JSON @1:661: Expected string

Steps to Reproduce

I've created a reproduction repo here:

https://github.com/alistairjevans/node-otel-serialisation

Expected Result

All binary representations are serialised to base64 to match the protobuf specification.

Actual Result

The object is dumped using the default prototype of the object, which does not match the protobuf spec.

Additional Details

  • The bug is in the toAnyValue function I believe.
  • The bug impacts UIntArray as well.

Relevant log output

OTLPExportDelegate items to be sent [
  LogRecord {
    attributes: {
      'my.bytes.buffer': <Buffer 48 65 6c 6c 6f>,
      'my.string.attribute': 'normal string for comparison'
    },
    totalAttributesCount: 2,
    _isReadonly: false,
    hrTime: [ 1764942699, 829000000 ],
    hrTimeObserved: [ 1764942699, 829000000 ],
    _severityNumber: 9,
    _severityText: 'INFO',
    _body: 'Test log message with bytes attribute',
    resource: Resource {
      _attributes: [Object],
      asyncAttributesPending: false,
      _syncAttributes: [Object],
      _asyncAttributesPromise: undefined
    },
    instrumentationScope: {
      name: 'bytes-test-logger',
      version: undefined,
      schemaUrl: undefined
    },
    _logRecordLimits: { attributeCountLimit: 128, attributeValueLengthLimit: Infinity }
  }
]

Full outputted payload:

{
    "resourceLogs": [
        {
            "resource": {
                "attributes": [
                    {
                        "key": "service.name",
                        "value": {
                            "stringValue": "bytes-serialisation-test"
                        }
                    },
                    {
                        "key": "telemetry.sdk.language",
                        "value": {
                            "stringValue": "nodejs"
                        }
                    },
                    {
                        "key": "telemetry.sdk.name",
                        "value": {
                            "stringValue": "opentelemetry"
                        }
                    },
                    {
                        "key": "telemetry.sdk.version",
                        "value": {
                            "stringValue": "1.30.1"
                        }
                    }
                ],
                "droppedAttributesCount": 0
            },
            "scopeLogs": [
                {
                    "scope": {
                        "name": "bytes-test-logger"
                    },
                    "logRecords": [
                        {
                            "timeUnixNano": "1764942699829000000",
                            "observedTimeUnixNano": "1764942699829000000",
                            "severityNumber": 9,
                            "severityText": "INFO",
                            "body": {
                                "stringValue": "Test log message with bytes attribute"
                            },
                            "attributes": [
                                {
                                    "key": "my.bytes.buffer",
                                    "value": {
                                        "bytesValue": {
                                            "type": "Buffer",
                                            "data": [
                                                72,
                                                101,
                                                108,
                                                108,
                                                111
                                            ]
                                        }
                                    }
                                },
                                {
                                    "key": "my.string.attribute",
                                    "value": {
                                        "stringValue": "normal string for comparison"
                                    }
                                }
                            ],
                            "droppedAttributesCount": 0
                        }
                    ]
                }
            ]
        }
    ]
}

Operating System and Version

macOS 15.6.1

Runtime and Version

At least nodejs 22.18.0 and 22.21.1

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions