-
Notifications
You must be signed in to change notification settings - Fork 87
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
fix(protocol): Properly document which timestamps are accepted #1152
Conversation
Also remove use of a `FromStr` impl where chrono's documentation says nothing about the format that is being parsed.
b10f51a
to
30e8c19
Compare
relay-general/src/protocol/types.rs
Outdated
@@ -976,9 +976,9 @@ impl FromValue for Timestamp { | |||
fn from_value(value: Annotated<Value>) -> Annotated<Self> { | |||
let rv = match value { | |||
Annotated(Some(Value::String(value)), mut meta) => { | |||
let parsed = match value.parse::<NaiveDateTime>() { | |||
let parsed = match NaiveDateTime::parse_from_str(&value, "%Y-%m-%dT%H:%M:%S%.f") { |
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.
let parsed = match NaiveDateTime::parse_from_str(&value, "%Y-%m-%dT%H:%M:%S%.f") { | |
// Use the same format as `NaiveDateTime::FromStr`: https://docs.rs/chrono/0.4.19/chrono/naive/struct.NaiveDateTime.html#impl-FromStr | |
let parsed = match NaiveDateTime::parse_from_str(&value, "%Y-%m-%dT%H:%M:%S%.f") { |
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.
This is lenient against spaces, but it's not obvious from the documentation or the format string. Can you please add a test case for something like "2015- 09-18T23:56:04"
?
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.
@jan-auer is this still relevant? are you saying FromStr is lenient as well?
relay-general/src/protocol/types.rs
Outdated
Ok(dt) => Ok(DateTime::from_utc(dt, Utc)), | ||
Err(_) => value.parse(), | ||
Err(_) => DateTime::parse_from_rfc3339(&value).map(|dt| dt.with_timezone(&Utc)), |
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.
Is this a stricter parser, or is it exactly the same?
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's a more lenient parser afaict, but chrono literally does not document what FromStr
actually accepts. So, not sure. Will sit on this PR for a bit.
Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
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'm +1 on the documentation changes.
However, I'm conflicted whether the explicit date time format is better than using the built-in FromStr
, which is both documented and doesn't require parsing a format string over and over again. I would suggest that if we're touching the implementation, we should rather look into parsing full ISO 8601 in addition to RFC 3339 and then add sufficient tests.
Ok(dt) => Ok(DateTime::from_utc(dt, Utc)), | ||
|
||
// XXX: This actually accepts more than RFC 3339. SDKs are strongly discouraged | ||
// from exercising that freedom. We should only support RFC3339. |
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 implementation suggestion for SDKs is in a very hidden spot. If we keep current behavior, I would suggest removing the comment here and moving it to a doc comment or develop docs.
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 "real" docs already tell the SDKs to use RFC 3339, this code comment is intended to explain why the actual relay code accepts more.
relay-general/src/protocol/types.rs
Outdated
@@ -976,9 +976,9 @@ impl FromValue for Timestamp { | |||
fn from_value(value: Annotated<Value>) -> Annotated<Self> { | |||
let rv = match value { | |||
Annotated(Some(Value::String(value)), mut meta) => { | |||
let parsed = match value.parse::<NaiveDateTime>() { | |||
let parsed = match NaiveDateTime::parse_from_str(&value, "%Y-%m-%dT%H:%M:%S%.f") { |
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.
This is lenient against spaces, but it's not obvious from the documentation or the format string. Can you please add a test case for something like "2015- 09-18T23:56:04"
?
relay-general/src/protocol/event.rs
Outdated
@@ -304,14 +304,23 @@ pub struct Event { | |||
/// value representing the number of seconds that have elapsed since the [Unix | |||
/// epoch](https://en.wikipedia.org/wiki/Unix_time). | |||
/// | |||
/// Timezone is assumed to be UTC if unclear. |
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.
/// Timezone is assumed to be UTC if unclear. | |
/// Timezone is assumed to be UTC if missing. |
relay-general/src/protocol/event.rs
Outdated
/// Sub-microsecond precision is not preserved with numeric values due to precision | ||
/// limitations with floats (at least in our systems). With that caveat in mind, just send | ||
/// whatever is easiest to produce. | ||
/// | ||
/// All timestamps in the event protocol are formatted this way. | ||
/// All timestamps in the event protocol, be it errors, transactions or the spans within a |
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 would revert this sentence, it reads strange and doesn't add any insight.
@jan-auer I have reverted most changes and left it at adding code comments |
Also remove use of a
FromStr
impl where chrono's documentation saysnothing about the format that is being parsed.
It is currently unclear to me whether the timestamp format we accept in prod is even all of RFC 3339.