diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs index b33f5e7b6a..0af597fc82 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs @@ -228,7 +228,9 @@ private bool AddFieldToLookupForExtension( out var fieldInformation)) { OneCollectorExporterEventSource.Log.AttributeDropped(this.itemType, extensionName, "Extension field name was not specified"); - return false; + + // Note: Return true here to allow other fields to potentially succeed. + return true; } return this.AddFieldToLookupForExtension(ref keyLookup, fieldInformation!, fieldValue); @@ -243,6 +245,8 @@ private bool AddFieldToLookupForExtension( if (keyCount >= MaxNumberOfExtensionValuesPerKey) { OneCollectorExporterEventSource.Log.AttributeDropped(this.itemType, fieldInformation.ExtensionName!, "Extension field limit reached"); + + // Note: Return false here to prevent other fields from being attempted when we know they will also fail. return false; } diff --git a/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationStateTests.cs b/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationStateTests.cs index 7a70eccb54..4e2083bd42 100644 --- a/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationStateTests.cs +++ b/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationStateTests.cs @@ -151,7 +151,11 @@ public void AddExtensionAttributeMixedFieldAndPropertyTest() state.AddExtensionAttribute(new KeyValuePair("ext.foo", new List> { new KeyValuePair(" foo.field2 ", 2) })); state.AddExtensionAttribute(new KeyValuePair("ext.foo .foo_field3 ", 3)); - state.AddExtensionAttribute(new KeyValuePair("ext. bar ", new Dictionary { ["bar_field1"] = 1 })); + state.AddExtensionAttribute(new KeyValuePair("ext. bar ", new Dictionary + { + [" "] = 99, // Note: This will be dropped but the second entry will be added. + ["bar_field1"] = 1, + })); state.AddExtensionAttribute(new KeyValuePair("ext. bar .bar.field2", 2)); state.AddExtensionAttribute(new KeyValuePair("ext.bar.bar_field3", 3));