Skip to content

fix(otlp-transformer): correctly handle Uint8Array attribute values when serializing to JSON#6348

Merged
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
dynatrace-oss-contrib:fix/uint8arrays-otlp-json-encoder
Jan 30, 2026
Merged

fix(otlp-transformer): correctly handle Uint8Array attribute values when serializing to JSON#6348
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
dynatrace-oss-contrib:fix/uint8arrays-otlp-json-encoder

Conversation

@pichlermarc
Copy link
Copy Markdown
Member

Which problem is this PR solving?

Fixes #6190

Uint8Arrays (including Buffers) are currently not handled properly when they get exported as part of a log record body or attribute value. The incorrect handling results in bytesValue containing an array of numbers instead of the data as a base64-encoded string - this causes the collector to reject the whole request.

Semi-related changes:

  • We had an intermediate step that allowed options to be passed, from which a Encoder object was created. In the past, this was public API; nowadays however, it's an implementation detail. As it was getting difficult to track which of the four options apply to which format in testing, I opted to remove this intermediate options step and pass the Encoder directly.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Existing tests
  • Added tests

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.48%. Comparing base (903739c) to head (2ce4f0f).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6348      +/-   ##
==========================================
- Coverage   95.68%   95.48%   -0.21%     
==========================================
  Files         313      363      +50     
  Lines        9667    11564    +1897     
  Branches     2226     2669     +443     
==========================================
+ Hits         9250    11042    +1792     
- Misses        417      522     +105     
Files with missing lines Coverage Δ
...l/packages/otlp-transformer/src/common/internal.ts 100.00% <100.00%> (ø)
...ntal/packages/otlp-transformer/src/common/utils.ts 100.00% <100.00%> (ø)
...tal/packages/otlp-transformer/src/logs/internal.ts 100.00% <100.00%> (ø)
...al/packages/otlp-transformer/src/logs/json/logs.ts 100.00% <100.00%> (ø)
...ackages/otlp-transformer/src/logs/protobuf/logs.ts 100.00% <100.00%> (ø)
.../packages/otlp-transformer/src/metrics/internal.ts 100.00% <100.00%> (ø)
...kages/otlp-transformer/src/metrics/json/metrics.ts 100.00% <100.00%> (ø)
...s/otlp-transformer/src/metrics/protobuf/metrics.ts 100.00% <100.00%> (ø)
...al/packages/otlp-transformer/src/trace/internal.ts 98.55% <100.00%> (-0.05%) ⬇️
.../packages/otlp-transformer/src/trace/json/trace.ts 100.00% <100.00%> (ø)
... and 1 more

... and 60 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pichlermarc
Copy link
Copy Markdown
Member Author

pichlermarc commented Jan 29, 2026

note: something was wrong with the coverage upload, so I pushed a commit so that the browser/webworker tests also publish the results to coverage/ instead of .nyc_output/ - that resolved the issue.

@pichlermarc pichlermarc marked this pull request as ready for review January 29, 2026 12:14
@pichlermarc pichlermarc requested a review from a team as a code owner January 29, 2026 12:14
@pichlermarc pichlermarc added bug Something isn't working priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect labels Jan 29, 2026
@pichlermarc pichlermarc added this to the Logs API/SDK GA milestone Jan 29, 2026
Copy link
Copy Markdown
Member

@raphael-theriault-swi raphael-theriault-swi left a comment

Choose a reason for hiding this comment

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

Much prefer this approach to the options !

Comment on lines 96 to 101
export interface OtlpEncodingOptions {
/** Convert trace and span IDs to hex strings. */
useHex?: boolean;
/** Convert HrTime to 2 part 64 bit values. */
useLongBits?: boolean;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this still used anywhere after the changes ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it is used by createExpectedSpanJson function in test/trace.test.ts to create the expected spans within the test. Tests are using different combinations of the options so (without knowing much) I guess is better to keep it. We could move the type to the test file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep, that's the reason why I kept it for now. Once I get to working on the custom proto serializer, I'm hoping that I can further simplify the tests and get rid of that too.

Comment thread experimental/CHANGELOG.md Outdated
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
@david-luna
Copy link
Copy Markdown
Contributor

Thanks for working on this @pichlermarc :)

@pichlermarc pichlermarc added this pull request to the merge queue Jan 30, 2026
Merged via the queue into open-telemetry:main with commit aa4a7e8 Jan 30, 2026
27 checks passed
@pichlermarc pichlermarc deleted the fix/uint8arrays-otlp-json-encoder branch January 30, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pkg:otlp-transformer priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffers are not serialised correctly as per the protoJSON specification

4 participants