Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ protected override void OnUnsupportedTagDropped(
this.onUnsupportedTagDropped(tagKey, tagValueTypeFullName);
}

protected override bool TryWriteEmptyTag(ref ConsoleTag consoleTag, string key, object? value)
{
consoleTag.Key = key;
consoleTag.Value = null;
return true;
}

internal struct ConsoleTag
{
public string? Key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Notes](../../RELEASENOTES.md).
`Activity.StatusDescription` exceeds 127 bytes.
([#6119](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6119))

* Fixed incorrect log serialization of attributes with null values, causing
some backends to reject logs.
some backends to reject logs when using OTLP exporter to output protobuf.
([#6149](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6149))

## 1.11.1

Released 2025-Jan-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ protected override void OnUnsupportedTagDropped(
tagValueTypeFullName,
tagKey);

protected override bool TryWriteEmptyTag(ref OtlpTagWriterState state, string key, object? value)
{
state.WritePosition = ProtobufSerializer.WriteStringWithTag(state.Buffer, state.WritePosition, ProtobufOtlpCommonFieldNumberConstants.KeyValue_Key, key);
state.WritePosition = ProtobufSerializer.WriteTagAndLength(state.Buffer, state.WritePosition, 0, ProtobufOtlpCommonFieldNumberConstants.KeyValue_Value, ProtobufWireType.LEN);
return true;
}

internal struct OtlpTagWriterState
{
public byte[] Buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ protected override void OnUnsupportedTagDropped(
tagValueTypeFullName,
tagKey);
}

protected override bool TryWriteEmptyTag(ref Utf8JsonWriter state, string key, object? value) => false;
}
4 changes: 3 additions & 1 deletion src/Shared/TagWriter/TagWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public bool TryWriteTag(
{
if (value == null)
{
return false;
return this.TryWriteEmptyTag(ref state, key, value);
}

switch (value)
Expand Down Expand Up @@ -117,6 +117,8 @@ public bool TryWriteTag(
return true;
}

protected abstract bool TryWriteEmptyTag(ref TTagState state, string key, object? value);

protected abstract void WriteIntegralTag(ref TTagState state, string key, long value);

protected abstract void WriteFloatingPointTag(ref TTagState state, string key, double value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public class OtlpAttributeTests
public void NullValueAttribute()
{
var kvp = new KeyValuePair<string, object?>("key", null);
Assert.False(TryTransformTag(kvp, out _));
Assert.True(TryTransformTag(kvp, out var attribute));
Assert.Equal(OtlpCommon.AnyValue.ValueOneofCase.None, attribute.Value.ValueCase);
Assert.False(attribute.Value.HasBoolValue);
Assert.False(attribute.Value.HasBytesValue);
Assert.False(attribute.Value.HasDoubleValue);
Assert.False(attribute.Value.HasIntValue);
Assert.False(attribute.Value.HasStringValue);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ protected override void OnUnsupportedTagDropped(string tagKey, string tagValueTy
{
}

protected override bool TryWriteEmptyTag(ref Tag state, string key, object? value)
{
throw new NotImplementedException();
}

public struct Tag
{
public string? Key;
Expand Down
Loading