[OTLP Logs] Fix ArgumentOutOfRangeException serializing large log batches (pooled buffers)#8862
[OTLP Logs] Fix ArgumentOutOfRangeException serializing large log batches (pooled buffers)#8862NachoEchevarria wants to merge 4 commits into
Conversation
BenchmarksBenchmark execution time: 2026-07-02 14:46:55 Comparing candidate commit 9078d4b in PR branch Found 2 performance improvements and 0 performance regressions! Performance is the same for 70 metrics, 0 unstable metrics, 62 known flaky benchmarks, 64 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8862) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (70ms) : 68, 72
master - mean (72ms) : 67, 77
section Bailout
This PR (8862) - mean (73ms) : 72, 74
master - mean (77ms) : 73, 80
section CallTarget+Inlining+NGEN
This PR (8862) - mean (1,084ms) : 1044, 1124
master - mean (1,084ms) : 1040, 1128
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (109ms) : 105, 113
master - mean (113ms) : 106, 120
section Bailout
This PR (8862) - mean (110ms) : 108, 111
master - mean (112ms) : 106, 117
section CallTarget+Inlining+NGEN
This PR (8862) - mean (781ms) : 759, 803
master - mean (780ms) : 751, 808
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (96ms) : 94, 99
master - mean (101ms) : 95, 107
section Bailout
This PR (8862) - mean (102ms) : 97, 107
master - mean (99ms) : 94, 105
section CallTarget+Inlining+NGEN
This PR (8862) - mean (944ms) : 903, 984
master - mean (937ms) : 894, 980
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (96ms) : 91, 100
master - mean (94ms) : 91, 97
section Bailout
This PR (8862) - mean (97ms) : 95, 99
master - mean (99ms) : 94, 103
section CallTarget+Inlining+NGEN
This PR (8862) - mean (817ms) : 771, 862
master - mean (814ms) : 764, 864
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (204ms) : 198, 210
master - mean (203ms) : 198, 207
section Bailout
This PR (8862) - mean (209ms) : 204, 214
master - mean (207ms) : 201, 212
section CallTarget+Inlining+NGEN
This PR (8862) - mean (1,224ms) : 1171, 1276
master - mean (1,213ms) : 1170, 1257
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (292ms) : 286, 298
master - mean (291ms) : 282, 300
section Bailout
This PR (8862) - mean (295ms) : 289, 301
master - mean (290ms) : 285, 294
section CallTarget+Inlining+NGEN
This PR (8862) - mean (976ms) : 950, 1002
master - mean (972ms) : 948, 996
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (284ms) : 275, 292
master - mean (284ms) : 277, 290
section Bailout
This PR (8862) - mean (282ms) : 275, 290
master - mean (284ms) : 279, 288
section CallTarget+Inlining+NGEN
This PR (8862) - mean (1,172ms) : 1131, 1213
master - mean (1,174ms) : 1136, 1212
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8862) - mean (285ms) : 280, 290
master - mean (283ms) : 277, 289
section Bailout
This PR (8862) - mean (287ms) : 281, 292
master - mean (285ms) : 278, 293
section CallTarget+Inlining+NGEN
This PR (8862) - mean (1,056ms) : 1009, 1103
master - mean (1,048ms) : 1002, 1093
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary of changes
Fix an
ArgumentOutOfRangeExceptionwhen serializing OTLP log batches that exceed 64 KB, and serialize into a pooled, growable buffer bounded at 3 MB.Seen here.
Reason for change
OtlpLogsSerializerwrote into a fixed 64 KB buffer with no bounds checking or resizing. Once a batch's serialized size crossed 64 KB, the next write threwArgumentOutOfRangeException(surfacing inWriteLogRecorddue to inlining), the batch failed to send, and it was dropped.This is rare in practice — error tracking shows very few occurrences — but when it does happen it's a hard failure that silently drops the batch, so it's worth guarding against.
Implementation details
OtlpLogsSerializer.TrySerializeLogsnow serializes into a caller-provided buffer and returnsfalse(instead of throwing) when the batch doesn't fit. Overflow is detected via theArgumentException/IndexOutOfRangeExceptionthe writers already throw, keeping the common path allocation-free rather than pre-sizing every batch.OtlpExporterowns the buffer: it rents fromArrayPool<byte>.Shared, grows it (doubling) up to a 3 MB cap on overflow, and returns it to the pool once the request completes (the send path consumes it synchronously). This removes the per-export buffer and result-copy allocations.DirectSubmissionLogSink.MaxTotalSizeBytes).Test coverage
Added
OtlpLogsSerializerTests: small/empty batches, buffer-too-small returns false without throwing (the original crash repro), fits-in-larger-buffer, and start-position handling.Other details
Alternative to #8858 (simple grow-and-retry). Keeping both open for now to compare approaches.