Skip to content

Overhaul the log records flow#156

Merged
inge4pres merged 8 commits into
zig-o11y:mainfrom
agagniere:improvement/simplify-logs-flow
May 21, 2026
Merged

Overhaul the log records flow#156
inge4pres merged 8 commits into
zig-o11y:mainfrom
agagniere:improvement/simplify-logs-flow

Conversation

@agagniere

Copy link
Copy Markdown
Contributor

Stacked on top of #155

Review the log records flow, fix lifetime issues, and simplify allocation and cleaning.

Fix

previously, toReadable duplicated some external strings (body and severity text) but shallow-copied the strings in the attributes, introducing a foot-gun as it appears duplicated but relies on externally-owned data.

Improvement

After reviewing the flow (see .md), it became clear that:

  • the SimpleLogProcessor didn't require any duplication at all, as it exports before emit returns
  • the BatchLogProcessor requires a full deep copy, then frees all log records when flushing

Furthermore, cleaning requires iterating over all log records, testing for presence of optionals, and, if we were to properly duplicate all strings, iterate over attributes, etc. While in fact, the log records in a batch are all freed at the same time

So this PR:

  • introduces asReadable which makes a cheaper shallow copy, without any duplication and any cleaning required, for the SimpleLogProcessor
  • makes toReadable a full deep copy
  • adds an arena in BatchLogProcessor to allocate the strings of the log records added to the batch, so that cleaning is a single step. Capacity is retained so that the following batches will not required new allocations from the underlying allocator

Misc

Minor improvements are also included:

  • use @memcpy instead of a loop in the BatchLogProcessor
  • use appendSlice instead of a loop when copying attributes into an ArrayList
  • pre-allocated ArrayLists to the right capacity when the number of elements to be inserted is known

@agagniere agagniere force-pushed the improvement/simplify-logs-flow branch from e3e6224 to f2f9cdd Compare May 17, 2026 16:26
@agagniere agagniere marked this pull request as ready for review May 17, 2026 16:26
@inge4pres inge4pres self-requested a review May 20, 2026 18:05
@inge4pres inge4pres merged commit c2fe660 into zig-o11y:main May 21, 2026
6 checks passed
@agagniere agagniere deleted the improvement/simplify-logs-flow branch May 21, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants