Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy2008 authored Dec 13, 2024
2 parents 87737eb + a658270 commit 4d56a9a
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 46 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Api.ProviderBuilderExtensions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

* Removed the following package references:

* `Google.Protobuf`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ internal static class ProtobufOtlpLogSerializer
private const int TraceIdSize = 16;
private const int SpanIdSize = 8;

private static readonly Stack<List<LogRecord>> LogsListPool = [];
private static readonly Dictionary<string, List<LogRecord>> ScopeLogsList = [];
[ThreadStatic]
private static Stack<List<LogRecord>>? logsListPool;
[ThreadStatic]
private static Dictionary<string, List<LogRecord>>? scopeLogsList;

[ThreadStatic]
private static SerializationState? threadSerializationState;

internal static int WriteLogsData(ref byte[] buffer, int writePosition, SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions, Resources.Resource? resource, in Batch<LogRecord> logRecordBatch)
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpLogFieldNumberConstants.LogsData_Resource_Logs, ProtobufWireType.LEN);
int logsDataLengthPosition = writePosition;
writePosition += ReserveSizeForLength;
logsListPool ??= [];
scopeLogsList ??= [];

foreach (var logRecord in logRecordBatch)
{
var scopeName = logRecord.Logger.Name;
if (!ScopeLogsList.TryGetValue(scopeName, out var logRecords))
if (!scopeLogsList.TryGetValue(scopeName, out var logRecords))
{
logRecords = LogsListPool.Count > 0 ? LogsListPool.Pop() : [];
ScopeLogsList[scopeName] = logRecords;
logRecords = logsListPool.Count > 0 ? logsListPool.Pop() : [];
scopeLogsList[scopeName] = logRecords;
}

if (logRecord.Source == LogRecord.LogRecordSource.FromSharedPool)
Expand All @@ -47,21 +48,29 @@ internal static int WriteLogsData(ref byte[] buffer, int writePosition, SdkLimit
logRecords.Add(logRecord);
}

writePosition = TryWriteResourceLogs(ref buffer, writePosition, sdkLimitOptions, experimentalOptions, resource, ScopeLogsList);
ProtobufSerializer.WriteReservedLength(buffer, logsDataLengthPosition, writePosition - (logsDataLengthPosition + ReserveSizeForLength));
writePosition = TryWriteResourceLogs(ref buffer, writePosition, sdkLimitOptions, experimentalOptions, resource, scopeLogsList);
ReturnLogRecordListToPool();

return writePosition;
}

internal static int TryWriteResourceLogs(ref byte[] buffer, int writePosition, SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions, Resources.Resource? resource, Dictionary<string, List<LogRecord>> scopeLogs)
{
int entryWritePosition = writePosition;

try
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpLogFieldNumberConstants.LogsData_Resource_Logs, ProtobufWireType.LEN);
int logsDataLengthPosition = writePosition;
writePosition += ReserveSizeForLength;

writePosition = WriteResourceLogs(buffer, writePosition, sdkLimitOptions, experimentalOptions, resource, scopeLogs);

ProtobufSerializer.WriteReservedLength(buffer, logsDataLengthPosition, writePosition - (logsDataLengthPosition + ReserveSizeForLength));
}
catch (Exception ex) when (ex is IndexOutOfRangeException || ex is ArgumentException)
{
writePosition = entryWritePosition;
if (!ProtobufSerializer.IncreaseBufferSize(ref buffer, OtlpSignalType.Logs))
{
throw;
Expand All @@ -75,9 +84,9 @@ internal static int TryWriteResourceLogs(ref byte[] buffer, int writePosition, S

internal static void ReturnLogRecordListToPool()
{
if (ScopeLogsList.Count != 0)
if (scopeLogsList?.Count != 0)
{
foreach (var entry in ScopeLogsList)
foreach (var entry in scopeLogsList!)
{
foreach (var logRecord in entry.Value)
{
Expand All @@ -92,10 +101,10 @@ internal static void ReturnLogRecordListToPool()
}

entry.Value.Clear();
LogsListPool.Push(entry.Value);
logsListPool?.Push(entry.Value);
}

ScopeLogsList.Clear();
scopeLogsList.Clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,53 @@ internal static class ProtobufOtlpMetricSerializer
private const int TraceIdSize = 16;
private const int SpanIdSize = 8;

private static readonly Stack<List<Metric>> MetricListPool = [];
private static readonly Dictionary<string, List<Metric>> ScopeMetricsList = [];
[ThreadStatic]
private static Stack<List<Metric>>? metricListPool;
[ThreadStatic]
private static Dictionary<string, List<Metric>>? scopeMetricsList;

private delegate int WriteExemplarFunc(byte[] buffer, int writePosition, in Exemplar exemplar);

internal static int WriteMetricsData(ref byte[] buffer, int writePosition, Resources.Resource? resource, in Batch<Metric> batch)
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpMetricFieldNumberConstants.MetricsData_Resource_Metrics, ProtobufWireType.LEN);
int mericsDataLengthPosition = writePosition;
writePosition += ReserveSizeForLength;
metricListPool ??= [];
scopeMetricsList ??= [];

foreach (var metric in batch)
{
var metricName = metric.MeterName;
if (!ScopeMetricsList.TryGetValue(metricName, out var metrics))
if (!scopeMetricsList.TryGetValue(metricName, out var metrics))
{
metrics = MetricListPool.Count > 0 ? MetricListPool.Pop() : new List<Metric>();
ScopeMetricsList[metricName] = metrics;
metrics = metricListPool.Count > 0 ? metricListPool.Pop() : new List<Metric>();
scopeMetricsList[metricName] = metrics;
}

metrics.Add(metric);
}

writePosition = TryWriteResourceMetrics(ref buffer, writePosition, resource, ScopeMetricsList);
ProtobufSerializer.WriteReservedLength(buffer, mericsDataLengthPosition, writePosition - (mericsDataLengthPosition + ReserveSizeForLength));
writePosition = TryWriteResourceMetrics(ref buffer, writePosition, resource, scopeMetricsList);
ReturnMetricListToPool();

return writePosition;
}

internal static int TryWriteResourceMetrics(ref byte[] buffer, int writePosition, Resources.Resource? resource, Dictionary<string, List<Metric>> scopeMetrics)
{
int entryWritePosition = writePosition;

try
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpMetricFieldNumberConstants.MetricsData_Resource_Metrics, ProtobufWireType.LEN);
int mericsDataLengthPosition = writePosition;
writePosition += ReserveSizeForLength;

writePosition = WriteResourceMetrics(buffer, writePosition, resource, scopeMetrics);

ProtobufSerializer.WriteReservedLength(buffer, mericsDataLengthPosition, writePosition - (mericsDataLengthPosition + ReserveSizeForLength));
}
catch (Exception ex) when (ex is IndexOutOfRangeException || ex is ArgumentException)
{
writePosition = entryWritePosition;
if (!ProtobufSerializer.IncreaseBufferSize(ref buffer, OtlpSignalType.Metrics))
{
throw;
Expand All @@ -63,15 +72,15 @@ internal static int TryWriteResourceMetrics(ref byte[] buffer, int writePosition

private static void ReturnMetricListToPool()
{
if (ScopeMetricsList.Count != 0)
if (scopeMetricsList?.Count != 0)
{
foreach (var entry in ScopeMetricsList)
foreach (var entry in scopeMetricsList!)
{
entry.Value.Clear();
MetricListPool.Push(entry.Value);
metricListPool?.Push(entry.Value);
}

ScopeMetricsList.Clear();
scopeMetricsList.Clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,52 @@ internal static class ProtobufOtlpTraceSerializer
private const int TraceIdSize = 16;
private const int SpanIdSize = 8;

private static readonly Stack<List<Activity>> ActivityListPool = [];
private static readonly Dictionary<string, List<Activity>> ScopeTracesList = [];
[ThreadStatic]
private static Stack<List<Activity>>? activityListPool;
[ThreadStatic]
private static Dictionary<string, List<Activity>>? scopeTracesList;

internal static int WriteTraceData(ref byte[] buffer, int writePosition, SdkLimitOptions sdkLimitOptions, Resources.Resource? resource, in Batch<Activity> batch)
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpTraceFieldNumberConstants.TracesData_Resource_Spans, ProtobufWireType.LEN);
int resourceSpansScopeSpansLengthPosition = writePosition;
writePosition += ReserveSizeForLength;
activityListPool ??= [];
scopeTracesList ??= [];

foreach (var activity in batch)
{
var sourceName = activity.Source.Name;
if (!ScopeTracesList.TryGetValue(sourceName, out var activities))
if (!scopeTracesList.TryGetValue(sourceName, out var activities))
{
activities = ActivityListPool.Count > 0 ? ActivityListPool.Pop() : [];
ScopeTracesList[sourceName] = activities;
activities = activityListPool.Count > 0 ? activityListPool.Pop() : [];
scopeTracesList[sourceName] = activities;
}

activities.Add(activity);
}

writePosition = TryWriteResourceSpans(ref buffer, writePosition, sdkLimitOptions, resource);
ReturnActivityListToPool();
ProtobufSerializer.WriteReservedLength(buffer, resourceSpansScopeSpansLengthPosition, writePosition - (resourceSpansScopeSpansLengthPosition + ReserveSizeForLength));

return writePosition;
}

internal static int TryWriteResourceSpans(ref byte[] buffer, int writePosition, SdkLimitOptions sdkLimitOptions, Resources.Resource? resource)
{
int entryWritePosition = writePosition;

try
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpTraceFieldNumberConstants.TracesData_Resource_Spans, ProtobufWireType.LEN);
int resourceSpansScopeSpansLengthPosition = writePosition;
writePosition += ReserveSizeForLength;

writePosition = WriteResourceSpans(buffer, writePosition, sdkLimitOptions, resource);

ProtobufSerializer.WriteReservedLength(buffer, resourceSpansScopeSpansLengthPosition, writePosition - (resourceSpansScopeSpansLengthPosition + ReserveSizeForLength));
}
catch (Exception ex) when (ex is IndexOutOfRangeException || ex is ArgumentException)
{
writePosition = entryWritePosition;

// Attempt to increase the buffer size
if (!ProtobufSerializer.IncreaseBufferSize(ref buffer, OtlpSignalType.Traces))
{
Expand All @@ -69,15 +79,15 @@ internal static int TryWriteResourceSpans(ref byte[] buffer, int writePosition,

internal static void ReturnActivityListToPool()
{
if (ScopeTracesList.Count != 0)
if (scopeTracesList?.Count != 0)
{
foreach (var entry in ScopeTracesList)
foreach (var entry in scopeTracesList!)
{
entry.Value.Clear();
ActivityListPool.Push(entry.Value);
activityListPool?.Push(entry.Value);
}

ScopeTracesList.Clear();
scopeTracesList.Clear();
}
}

Expand All @@ -91,9 +101,9 @@ internal static int WriteResourceSpans(byte[] buffer, int writePosition, SdkLimi

internal static int WriteScopeSpans(byte[] buffer, int writePosition, SdkLimitOptions sdkLimitOptions)
{
if (ScopeTracesList != null)
if (scopeTracesList != null)
{
foreach (KeyValuePair<string, List<Activity>> entry in ScopeTracesList)
foreach (KeyValuePair<string, List<Activity>> entry in scopeTracesList)
{
writePosition = ProtobufSerializer.WriteTag(buffer, writePosition, ProtobufOtlpTraceFieldNumberConstants.ResourceSpans_Scope_Spans, ProtobufWireType.LEN);
int resourceSpansScopeSpansLengthPosition = writePosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,7 @@ internal static bool IncreaseBufferSize(ref byte[] buffer, OtlpSignalType otlpSi
try
{
var newBufferSize = buffer.Length * 2;
var newBuffer = new byte[newBufferSize];
buffer.CopyTo(newBuffer, 0);
buffer = newBuffer;
buffer = new byte[newBufferSize];
return true;
}
catch (OutOfMemoryException)
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Extensions.Propagators/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ covering all components see: [Release Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

## 1.11.0-rc.1

Released 2024-Dec-11

## 1.10.0

Released 2024-Nov-12
Expand Down

0 comments on commit 4d56a9a

Please sign in to comment.