Skip to content
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

Merged
merged 4 commits into from
Oct 30, 2024
Merged

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Oct 24, 2024

Currently well-known span attributes may be set to "", but custom attributes (which end up in the other 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 with span.data.

Copy link
Member

@Lms24 Lms24 left a 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!

@jjbayer jjbayer marked this pull request as ready for review October 28, 2024 12:10
@jjbayer jjbayer requested a review from a team as a code owner October 28, 2024 12:10
@@ -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")]
Copy link
Member

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.

Copy link
Member Author

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.

Comment on lines +960 to +967
#[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":{}}"#);
}
Copy link
Member Author

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.

@jjbayer jjbayer self-assigned this Oct 30, 2024
@jjbayer jjbayer merged commit b629b62 into master Oct 30, 2024
23 checks passed
@jjbayer jjbayer deleted the feat/spans-empty-attributes branch October 30, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants