-
Notifications
You must be signed in to change notification settings - Fork 147
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
Move from uint63 to uint64 for trace_id span_id and parent_id #1237
Conversation
ext/php7/serializer.c
Outdated
if (string_as_uint64) { | ||
mpack_write_u64(writer, strtoull(ZSTR_VAL(Z_STR_P(trace)), NULL, 10)); | ||
} else { | ||
mpack_write_cstr(writer, ZSTR_VAL(Z_STR_P(trace))); |
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.
Use the more idiomatic variant: Z_STRVAL_P(s) == ZSTR_VAL(Z_STR_P(s))
ext/php7/serializer.c
Outdated
ZEND_EXTERN_MODULE_GLOBALS(ddtrace); | ||
|
||
static int msgpack_write_zval(mpack_writer_t *writer, zval *trace TSRMLS_DC); | ||
static const char *trace_id_keyword = "trace_id"; |
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.
Either use the variable everywhere (i.e. also in the add_assoc_string below) or not at all.
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.
Very good point, did not catch that!
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.
Looks good in general
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.
Nice work so far @labbati! I left some suggestions on the PHP 5 code that applies to 7 & 8 (with the exception of the add_assoc_string
duplication issue which is PHP 5 specific).
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.
ext/php7/serializer.c
Outdated
ZEND_EXTERN_MODULE_GLOBALS(ddtrace); | ||
|
||
static int msgpack_write_zval(mpack_writer_t *writer, zval *trace TSRMLS_DC); | ||
static const char *trace_id_keyword = "trace_id"; |
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.
Very good point, did not catch that!
Co-authored-by: Sammy Kaye Powers <sammyk@datadoghq.com>
ext/php5/serializer.c
Outdated
@@ -17,6 +19,11 @@ | |||
|
|||
ZEND_EXTERN_MODULE_GLOBALS(ddtrace); | |||
|
|||
#define MAX_ID_LEN 20 // 1.8e^19 = 20 chars |
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.
TBH, this is not defensive, it's easy to forget a + 1 when allocating the buffer and it does no harm to have one byte too much allocated on the stack, better do 21 here and call it maybe MAX_ID_BUFSIZ
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.
Very good point @bwoebi. I'll have to change my go-to way of doing this from now on. :)
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.
Like it. Done
ext/php8/serializer.c
Outdated
// Writing the value | ||
if (zval_string_as_uint64) { | ||
mpack_write_u64(writer, strtoull(Z_STRVAL_P(tmp), NULL, 10)); | ||
} else if (msgpack_write_zval(writer, tmp TSRMLS_CC) != 1) { |
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.
Don't add new TSRMLS - maybe rebase it, then compilation would fail (remove it in PHP 7 and PHP 8)
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.
👍🏻 just pulled in master
…gent in integrations tests
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.
Looks good now :-)
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.
Looks great, @labbati! 💯 I left one optional suggestion about future proofing how we're using sprintf
(but this could be a separate PR). LGTM. 👍
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 knocking out that last change! 👍
The two failing tests are unrelated to this PR (master fails as well) and we are going to fix the failures in a separate PR. Merging it right now. |
Motivation
PHP has not a concept of
uint64
, onlyint64
, equivalent tounint63
for this discussion. As a consequence, when a frontend non-PHP service generates a randomuint64
as the trace/span ID, then this ID is wrongly converted to auint63
(orint64
) by PHP and propagated.Description
Move from
uint63
IDs tounit64
. After this R:uint64
;Readiness checklist
Reviewer checklist