Skip to content

Commit

Permalink
[onecollector] Fix duplicate extension field bug (#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Oct 11, 2024
1 parent 333b346 commit 55b65bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
[CVE-2024-43485](https://msrc.microsoft.com/update-guide/vulnerability/CVE-2024-43485).
([#2196](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2196))

* Fixed a bug causing extension data specified on `LogRecord`s in a batch to
also be applied to subsequent `LogRecord`s in the same batch.
([#2205](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2205))

## 1.10.0-alpha.1

Released 2024-Sep-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ public void Reset(string itemType, Utf8JsonWriter writer)
{
this.itemType = itemType;
this.Writer = writer;
}

public void BeginItem()
{
if (this.allValues.Count <= 0)
{
return;
}

for (int i = 0; i < this.nextKeysToAllValuesLookupIndex; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public void SerializeBatchOfItemsToStream(

while (state.TryGetNextItem(out var item))
{
jsonSerializerState.BeginItem();

this.SerializeItemToJson(resource, item!, jsonSerializerState);

var currentItemSizeInBytes = writer.BytesCommitted + writer.BytesPending + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void LogRecordExtensionsJsonTest()
.Build();

string json = GetLogRecordJson(
1,
2,
(index, logRecord) =>
{
logRecord.Attributes = new List<KeyValuePair<string, object?>> { new KeyValuePair<string, object?>("ext.state.field", "stateValue1") };
Expand All @@ -283,7 +283,8 @@ public void LogRecordExtensionsJsonTest()
scopeProvider);

Assert.Equal(
"""{"ver":"4.0","name":"Namespace.Name","time":"2032-01-18T10:11:12Z","iKey":"o:tenant-token","data":{"severityText":"Trace","severityNumber":1},"ext":{"state":{"field":"stateValue1"},"resource":{"field":"resourceValue1"},"scope":{"field":"scopeValue1"}}}""" + "\n",
"""{"ver":"4.0","name":"Namespace.Name","time":"2032-01-18T10:11:12Z","iKey":"o:tenant-token","data":{"severityText":"Trace","severityNumber":1},"ext":{"state":{"field":"stateValue1"},"resource":{"field":"resourceValue1"},"scope":{"field":"scopeValue1"}}}""" + "\n"
+ """{"ver":"4.0","name":"Namespace.Name","time":"2032-01-18T10:11:12Z","iKey":"o:tenant-token","data":{"severityText":"Trace","severityNumber":1},"ext":{"state":{"field":"stateValue1"},"resource":{"field":"resourceValue1"},"scope":{"field":"scopeValue1"}}}""" + "\n",
json);
}

Expand Down

0 comments on commit 55b65bd

Please sign in to comment.