-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat(spans): Retain empty attributes #4174
Conversation
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.
Thanks for tackling this so quickly!
@@ -135,7 +135,7 @@ pub struct TraceContext { | |||
pub sampled: Annotated<bool>, | |||
|
|||
/// Data of the trace's root span. | |||
#[metastructure(pii = "maybe", skip_serialization = "empty")] | |||
#[metastructure(pii = "maybe", skip_serialization = "null")] |
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.
Should we ever skip here? I assume the Python SDK setting data to None
would be serialized as null
which we then skip incorrectly.
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.
Skipping null
would be correct IMO, but a side effect of this change is that data: {}
is not be skipped anymore. I will add some more tests.
#[test] | ||
fn test_span_data_completely_empty() { | ||
let span = r#"{ | ||
"data": {} | ||
}"#; | ||
let span: Annotated<Span> = Annotated::from_json(span).unwrap(); | ||
assert_eq!(span.to_json().unwrap(), r#"{"data":{}}"#); | ||
} |
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.
I verified that this test has the same result on master
. skip_serialization
applies to child elements, not the element itself.
Currently well-known span attributes may be set to
""
, but custom attributes (which end up in theother
field) are removed if their value is empty.To be consistent in itself and with open telemetry, we should allow empty non-null values.
Apply this change also to
event.contexts.trace.data
because it is supposed to be consistent withspan.data
.