-
Notifications
You must be signed in to change notification settings - Fork 938
Fix OTLP marshaling for empty string attributes #8014
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,8 +147,14 @@ void toProtoSpan(MarshalerSource marshalerSource) { | |
| .put("long_array", 12L, 23L) | ||
| .put("double_array", 12.3, 23.1) | ||
| .put("boolean_array", true, false) | ||
| .put("empty_string", "") | ||
| .put("false_value", false) | ||
| .put("zero_int", 0L) | ||
| .put("zero_double", 0.0) | ||
| // TODO: add empty array, empty map, empty bytes, and true empty value | ||
| // after https://github.com/open-telemetry/opentelemetry-java/pull/7973 | ||
| .build()) | ||
| .setTotalAttributeCount(9) | ||
| .setTotalAttributeCount(13) | ||
| .setEvents( | ||
| Collections.singletonList( | ||
| EventData.create(12347, "my_event", Attributes.empty()))) | ||
|
|
@@ -231,6 +237,22 @@ void toProtoSpan(MarshalerSource marshalerSource) { | |
| .addValues(AnyValue.newBuilder().setBoolValue(false).build()) | ||
| .build()) | ||
| .build()) | ||
| .build(), | ||
| KeyValue.newBuilder() | ||
| .setKey("empty_string") | ||
| .setValue(AnyValue.newBuilder().setStringValue("").build()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC correctly, this is the only new difference resulting from this PR. The other test cases are demonstrating existing logic. What's the current behavior of empty string? Presumably it would just be some sort of null / emtpy value, like What's the spec language that leads to the conclusion that empty strings should be included vs. omitted? I see this line that empty values are meaningful and must be passed to exporters, but should the OTLP exporter serialize those or omit?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍
👍
to me it follows from protobuf specification itself https://protobuf.dev/programming-guides/proto3/#oneof
(sorry, should have linked to open-telemetry/opentelemetry-specification#4660 (comment) in case you hadn't seen that)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah got it! Makes sense. |
||
| .build(), | ||
| KeyValue.newBuilder() | ||
| .setKey("false_value") | ||
| .setValue(AnyValue.newBuilder().setBoolValue(false).build()) | ||
| .build(), | ||
| KeyValue.newBuilder() | ||
| .setKey("zero_int") | ||
| .setValue(AnyValue.newBuilder().setIntValue(0).build()) | ||
| .build(), | ||
| KeyValue.newBuilder() | ||
| .setKey("zero_double") | ||
| .setValue(AnyValue.newBuilder().setDoubleValue(0.0).build()) | ||
| .build()); | ||
| assertThat(protoSpan.getDroppedAttributesCount()).isEqualTo(1); | ||
| assertThat(protoSpan.getEventsList()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the new implementations are performing the function of
sizeStringWithContext, but without theif (value == null || value.isEmpty())short circuiting:What about the
if (context.marshalStringNoAllocation()) {} else {}block? Would it be better to include an overload ofserializeStringWithContext/sizeStringWithContextwhich ignores theif (value == null || value.isEmpty())short circuiting?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, for some reason I thought the stateless marshalers was always no allocation
fixed in 11b7188