opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

Fix sign extension on LogRecord flags in low-allocation log marshaler

Open thswlsqls opened this issue 5 months ago • 1 comments

Fixes #

Description

  • LogStatelessMarshaler passes the TraceFlags byte directly into the int-taking serializeFixed32 / sizeFixed32 for LogRecord.flags, so a flags byte with the high bit set sign-extends.
  • 0x80 is then written little-endian as 80 FF FF FF instead of 80 00 00 00, and the JSON renders the sign-extended integer. fixed32 is always 4 bytes, so the size is unaffected — only the byte/JSON content is wrong.
  • Fix: use serializeByteAsFixed32 / sizeByteAsFixed32, which mask ((int) value) & 0xff, matching the non-stateless sibling LogMarshaler (lines 121, 156).

Testing done

  • Set the shared SPAN_CONTEXT in LowAllocationLogRequestMarshalerTest to TraceFlags.fromByte((byte) 0x80), so the existing relative assertions (validateOutput, validateJsonOutput) compare the stateless and non-stateless paths with the high bit set. Both fail before the fix and pass after.
  • ./gradlew :exporters:otlp:common:check passed (118 tests).
  • Internal package, so no docs/apidiffs/ change. Added a ## Unreleased CHANGELOG.md entry under SDK > Exporters.

thswlsqls avatar Jun 21 '26 00:06 thswlsqls

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 91.60%. Comparing base (2c83278) to head (6547604). :warning: Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8493      +/-   ##
============================================
- Coverage     91.61%   91.60%   -0.01%     
  Complexity    10311    10311              
============================================
  Files          1013     1013              
  Lines         27260    27260              
  Branches       3201     3201              
============================================
- Hits          24973    24971       -2     
- Misses         1560     1561       +1     
- Partials        727      728       +1     

: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.

codecov[bot] avatar Jun 21 '26 00:06 codecov[bot]

Ready for review — CI is green.

thswlsqls avatar Jul 05 '26 05:07 thswlsqls

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.

otelbot[bot] avatar Jul 13 '26 19:07 otelbot[bot]