Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[onecollector] Fix duplicate extension field bug #2205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading