-
Notifications
You must be signed in to change notification settings - Fork 67
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
refactor(agent): cleanup guzzle instrumentation #498
base: dev
Are you sure you want to change the base?
Changes from 1 commit
d04bf87
4c98d5a
ca5c948
a20c93d
4b45445
734784e
48f8e9e
6ac5c13
d4dea40
566b26e
6a879ff
6222a51
29f4551
8065805
40ab8cf
f3ac653
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 |
---|---|---|
|
@@ -343,6 +343,25 @@ const zend_function_entry nr_guzzle6_requesthandler_functions[] | |
nr_guzzle6_requesthandler_onrejected_arginfo, | ||
ZEND_ACC_PUBLIC) PHP_FE_END}; | ||
|
||
static void nr_guzzle_minit(const int guzzle_version){ | ||
zend_class_entry ce; | ||
char guzzle_path[] = "newrelic\\Guzzle6\\RequestHandler"; | ||
if (guzzle_version == 7){ | ||
nr_strcpy(guzzle_path, "newrelic\\Guzzle7\\RequestHandler"); | ||
} | ||
if (0 == NRINI(guzzle_enabled)) { | ||
return; | ||
} | ||
|
||
INIT_CLASS_ENTRY(ce, guzzle_path, | ||
nr_guzzle6_requesthandler_functions); | ||
nr_guzzle6_requesthandler_ce | ||
= nr_php_zend_register_internal_class_ex(&ce, NULL TSRMLS_CC); | ||
|
||
zend_declare_property_null(nr_guzzle6_requesthandler_ce, NR_PSTR("request"), | ||
ZEND_ACC_PRIVATE TSRMLS_CC); | ||
} | ||
|
||
/* | ||
* Guzzle 7 requires PHP 7.2.0 or later, which is why we will not build Guzzle 7 | ||
* support on older versions and will instead provide simple stubs for the two | ||
|
@@ -468,19 +487,7 @@ void nr_guzzle7_enable(TSRMLS_D) { | |
} | ||
|
||
void nr_guzzle7_minit(TSRMLS_D) { | ||
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. This function differs from
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. Fixed, I have added a helper function called nr_guzzle_minit, which reduces code duplication. 566b26e |
||
zend_class_entry ce; | ||
|
||
if (0 == NRINI(guzzle_enabled)) { | ||
return; | ||
} | ||
|
||
INIT_CLASS_ENTRY(ce, "newrelic\\Guzzle7\\RequestHandler", | ||
nr_guzzle6_requesthandler_functions); | ||
nr_guzzle6_requesthandler_ce | ||
= nr_php_zend_register_internal_class_ex(&ce, NULL TSRMLS_CC); | ||
|
||
zend_declare_property_null(nr_guzzle6_requesthandler_ce, NR_PSTR("request"), | ||
ZEND_ACC_PRIVATE TSRMLS_CC); | ||
nr_guzzle_minit(7); | ||
} | ||
|
||
|
||
|
@@ -597,19 +604,7 @@ void nr_guzzle6_enable(TSRMLS_D) { | |
} | ||
|
||
void nr_guzzle6_minit(TSRMLS_D) { | ||
zend_class_entry ce; | ||
|
||
if (0 == NRINI(guzzle_enabled)) { | ||
return; | ||
} | ||
|
||
INIT_CLASS_ENTRY(ce, "newrelic\\Guzzle6\\RequestHandler", | ||
nr_guzzle6_requesthandler_functions); | ||
nr_guzzle6_requesthandler_ce | ||
= nr_php_zend_register_internal_class_ex(&ce, NULL TSRMLS_CC); | ||
|
||
zend_declare_property_null(nr_guzzle6_requesthandler_ce, NR_PSTR("request"), | ||
ZEND_ACC_PRIVATE TSRMLS_CC); | ||
nr_guzzle_minit(6); | ||
} | ||
|
||
#else /* PHP < 5.5 */ | ||
|
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 doesn't seem the right approach. Luckily declaration (and initialization) on line 348 creates char array of exactly the size enough to fit this strcpy. Maybe consider turning guzzle_path into a function that will return const char * based on guzzle_version? Something like this:
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.
Yes, I also agree that using nr_strcpy is not the most efficient way. I have fixed this by removing the guzzle version from the namespace! 40ab8cf