Skip to content

Commit

Permalink
[otlp] Fix ProtobufOtlpLogSerializer pool handling (#5989)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Nov 18, 2024
1 parent 4bc398f commit e3665c9
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using OpenTelemetry.Internal;
using OpenTelemetry.Logs;
using OpenTelemetry.Trace;
Expand Down Expand Up @@ -34,6 +35,15 @@ internal static int WriteLogsData(byte[] buffer, int writePosition, SdkLimitOpti
ScopeLogsList[scopeName] = logRecords;
}

if (logRecord.Source == LogRecord.LogRecordSource.FromSharedPool)
{
Debug.Assert(logRecord.PoolReferenceCount > 0, "logRecord PoolReferenceCount value was unexpected");

// Note: AddReference call here prevents the LogRecord from
// being given back to the pool by Batch<LogRecord>.
logRecord.AddReference();
}

logRecords.Add(logRecord);
}

Expand All @@ -50,6 +60,18 @@ internal static void ReturnLogRecordListToPool()
{
foreach (var entry in ScopeLogsList)
{
foreach (var logRecord in entry.Value)
{
if (logRecord.Source == LogRecord.LogRecordSource.FromSharedPool)
{
Debug.Assert(logRecord.PoolReferenceCount > 0, "logRecord PoolReferenceCount value was unexpected");

// Note: Try to return the LogRecord to the shared pool
// now that work is done.
LogRecordSharedPool.Current.Return(logRecord);
}
}

entry.Value.Clear();
LogsListPool.Push(entry.Value);
}
Expand Down

0 comments on commit e3665c9

Please sign in to comment.