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
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Allow profile chunks without release. ([#4155](https://github.com/getsentry/relay/pull/4155))
- Add validation for timestamps sent from the future. ([#4163](https://github.com/getsentry/relay/pull/4163))


**Features:**

- Retain empty string values in `span.data` and `event.contexts.trace.data`. ([#4174](https://github.com/getsentry/relay/pull/4174))

**Internal:**

- Add a metric that counts span volume in the root project for dynamic sampling (`c:spans/count_per_root_project@none`). ([#4134](https://github.com/getsentry/relay/pull/4134))
Expand Down
21 changes: 11 additions & 10 deletions relay-event-schema/src/protocol/contexts/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

pub data: Annotated<SpanData>,

/// Additional arbitrary fields for forwards compatibility.
Expand Down Expand Up @@ -197,7 +197,8 @@ mod tests {
"tok": "test"
},
"custom_field": "something"
}
},
"custom_field_empty": ""
},
"other": "value",
"type": "trace"
Expand All @@ -222,15 +223,15 @@ mod tests {
);
map
}),
other: {
let mut map = Object::new();
map.insert(
"custom_field".into(),
Annotated::new(Value::String("something".into())),
);
map
},
other: Object::from([(
"custom_field".into(),
Annotated::new(Value::String("something".into())),
)]),
}),
other: Object::from([(
"custom_field_empty".into(),
Annotated::new(Value::String("".into())),
)]),
..Default::default()
}),
other: {
Expand Down
36 changes: 35 additions & 1 deletion relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ pub struct SpanData {
additional_properties,
pii = "true",
retain = "true",
skip_serialization = "empty"
skip_serialization = "null" // applies to child elements
)]
pub other: Object<Value>,
}
Expand Down Expand Up @@ -931,4 +931,38 @@ mod tests {
assert_eq!(data.get_value("code\\.namespace"), Some(Val::String("ns")));
assert_eq!(data.get_value("unknown"), None);
}

#[test]
fn test_span_data_empty_well_known_field() {
let span = r#"{
"data": {
"lcp.url": ""
}
}"#;
let span: Annotated<Span> = Annotated::from_json(span).unwrap();
assert_eq!(span.to_json().unwrap(), r#"{"data":{"lcp.url":""}}"#);
}

#[test]
fn test_span_data_empty_custom_field() {
let span = r#"{
"data": {
"custom_field_empty": ""
}
}"#;
let span: Annotated<Span> = Annotated::from_json(span).unwrap();
assert_eq!(
span.to_json().unwrap(),
r#"{"data":{"custom_field_empty":""}}"#
);
}

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

}
Loading