Skip to content

Commit

Permalink
[onecollector-1.9.2] Patch extension data fix (#2208)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Oct 11, 2024
1 parent 4c34ab4 commit 7146c0a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

* 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.
([#2208](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2208))

* Bumped the `System.Text.Json` reference to `6.0.10` for the `net462`,
`netstandard2.0`, and `netstandard2.1` targets in response to
[CVE-2024-43485](https://github.com/advisories/GHSA-8g4q-xg66-9fp4).
([#2208](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2208))

## 1.9.2

Released 2024-Aug-12
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 @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="$(OTelSdkVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonPkgVer)" Condition="'$(TargetFramework)' != 'net7.0' AND '$(TargetFramework)' != 'net6.0'" />
<PackageReference Include="System.Text.Json" Version="6.0.10" Condition="'$(TargetFramework)' != 'net7.0' AND '$(TargetFramework)' != 'net6.0'" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsConfigurationBinderPkgVer)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public void AddExtensionAttributeTest()

var state = new CommonSchemaJsonSerializationState("Test", writer);

state.BeginItem();

state.AddExtensionAttribute(new KeyValuePair<string, object?>("ext.something.field1", 1));
state.AddExtensionAttribute(new KeyValuePair<string, object?>("ext.something.field2", 2));
state.AddExtensionAttribute(new KeyValuePair<string, object?>("ext.something.field3", 3));
Expand All @@ -42,8 +44,11 @@ public void AddExtensionAttributeTest()

stream.SetLength(0);
writer.Reset(stream);

state.Reset("Test", writer);

state.BeginItem();

Assert.Equal(0, state.ExtensionPropertyCount);
Assert.Equal(0, state.ExtensionAttributeCount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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 @@ -252,7 +252,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 7146c0a

Please sign in to comment.