-
Notifications
You must be signed in to change notification settings - Fork 21
feat(libdd-trace-utils): check for empty value in header datadog-client-computed-stats #1900
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
Changes from 1 commit
17c3f1d
dd9f5ac
9da57c8
b2bcec9
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -133,8 +133,8 @@ impl<'a> From<&'a HeaderMap<HeaderValue>> for TracerHeaderTags<'a> { | |||||||
| if headers.get("datadog-client-computed-top-level").is_some() { | ||||||||
| tags.client_computed_top_level = true; | ||||||||
| } | ||||||||
| if headers.get("datadog-client-computed-stats").is_some() { | ||||||||
| tags.client_computed_stats = true; | ||||||||
| if let Some(v) = headers.get("datadog-client-computed-stats") { | ||||||||
| tags.client_computed_stats = !is_header_empty(v.to_str().unwrap_or_default()); | ||||||||
| } | ||||||||
| if let Some(count) = headers.get("datadog-client-dropped-p0-traces") { | ||||||||
| tags.dropped_p0_traces = count | ||||||||
|
|
@@ -150,6 +150,10 @@ impl<'a> From<&'a HeaderMap<HeaderValue>> for TracerHeaderTags<'a> { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| fn is_header_empty(value: &str) -> bool { | ||||||||
|
Contributor
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. Nitpick: I'm not sure it's worth making a bespoke function to just proxy
Contributor
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. Fair enough! I removed this function and check for the empty string directly: libdatadog/libdd-trace-utils/src/tracer_header_tags.rs Lines 136 to 138 in 9da57c8
|
||||||||
| value.is_empty() | ||||||||
| } | ||||||||
|
|
||||||||
| #[cfg(test)] | ||||||||
| mod tests { | ||||||||
| use super::*; | ||||||||
|
|
@@ -262,4 +266,40 @@ mod tests { | |||||||
| assert_eq!(tags.dropped_p0_traces, 12); | ||||||||
| assert_eq!(tags.dropped_p0_spans, 0); | ||||||||
| } | ||||||||
|
|
||||||||
| #[test] | ||||||||
| fn test_is_header_empty() { | ||||||||
| // Empty string is true | ||||||||
| assert!(is_header_empty("")); | ||||||||
|
|
||||||||
| // Truthy and arbitrary non-empty values are false | ||||||||
| for val in &["1", "t", "T", "TRUE", "True", "true"] { | ||||||||
| assert!( | ||||||||
| !is_header_empty(val), | ||||||||
| "expected is_header_empty({val:?}) to be false" | ||||||||
| ); | ||||||||
| } | ||||||||
| } | ||||||||
|
Contributor
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. Nitpick: we're basically testing the implementation of
Contributor
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. Removed this test, see #1900 (comment) |
||||||||
|
|
||||||||
| #[test] | ||||||||
| fn test_header_map_to_tags_computed_stats_empty_string() { | ||||||||
| let val = ""; | ||||||||
| let mut header_map = HeaderMap::new(); | ||||||||
| header_map.insert("datadog-client-computed-stats", val.parse().unwrap()); | ||||||||
| let tags: TracerHeaderTags = (&header_map).into(); | ||||||||
| assert!( | ||||||||
| !tags.client_computed_stats, | ||||||||
| "expected client_computed_stats=false for datadog-client-computed-stats header value {val:?}" | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| #[test] | ||||||||
| fn test_header_map_to_tags_computed_stats_not_set() { | ||||||||
| let header_map = HeaderMap::new(); | ||||||||
| let tags: TracerHeaderTags = (&header_map).into(); | ||||||||
| assert!( | ||||||||
| !tags.client_computed_stats, | ||||||||
| "expected client_computed_stats=false when datadog-client-computed-stats header is not set" | ||||||||
| ); | ||||||||
| } | ||||||||
| } | ||||||||
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.
datadog-client-computed-top-levelis still treated as enabled solely by header presence (is_some()), so an explicitly empty header value (""), if sent, will setclient_computed_top_level=true. This conflicts with the struct doc comment (“Any non-empty value will mean 'yes'”) and now differs from thedatadog-client-computed-statshandling in the next lines. Consider parsing the value and requiring it to be non-empty (similar toclient_computed_stats) to make the semantics consistent.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.
The
datadog-client-computed-top-levelheader is outside the scope of this change. Will leave this header handling as is until the need arises to change it.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 still at least fix the struct doc (potentially in a separate PR? If the Codex assessment is true, contradicting doc and implementation can be confusing.
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 updated the
TracerHeaderTagsstruct doc to accurately reflect the behavior of these fields:libdatadog/libdd-trace-utils/src/tracer_header_tags.rs
Lines 30 to 35 in 9da57c8