Skip to content

Commit 839b098

Browse files
committed
fix(agent): Calling order
1 parent e623e99 commit 839b098

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

agent/lib_php_amqplib.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@ static inline void nr_php_amqplib_insert_dt_headers(zval* amqp_msg) {
389389
ZVAL_STR_COPY(&key_zval_zpd, key_str);
390390
retval_set_table_zvf
391391
= nr_php_call(amqp_headers_table, "set", &key_zval_zpd, val);
392-
zval_ptr_dtor(&key_zval_zpd);
393392
if (NULL == retval_set_table_zvf) {
394393
nrl_verbosedebug(NRL_INSTRUMENT,
395394
"%s didn't exist in the AMQPTable, but couldn't "
396395
"set the key/val to the table.",
397396
NRSAFESTR(ZSTR_VAL(key_str)));
398397
}
398+
zval_ptr_dtor(&key_zval_zpd);
399399
nr_php_zval_free(&retval_set_table_zvf);
400400
}
401401
}
@@ -510,6 +510,7 @@ static inline void nr_php_amqplib_retrieve_dt_headers(zval* amqp_msg) {
510510
*/
511511
nr_php_api_accept_distributed_trace_payload_httpsafe(NRPRG(txn), header_map,
512512
"Queue");
513+
513514
nr_hashmap_destroy(&header_map);
514515
}
515516
nr_php_zval_free(&amqp_headers_native_data_zvf);
@@ -543,8 +544,20 @@ static inline void nr_php_amqplib_retrieve_dt_headers(zval* amqp_msg) {
543544
* @throws AMQPConnectionBlockedException
544545
*
545546
*/
546-
NR_PHP_WRAPPER(nr_rabbitmq_basic_publish) {
547+
548+
NR_PHP_WRAPPER(nr_rabbitmq_basic_publish_before) {
547549
zval* amqp_msg = NULL;
550+
(void)wraprec;
551+
552+
amqp_msg = nr_php_get_user_func_arg(1, NR_EXECUTE_ORIG_ARGS);
553+
/*
554+
* nr_php_amqplib_insert_dt_headers will check the validity of the object.
555+
*/
556+
nr_php_amqplib_insert_dt_headers(amqp_msg);
557+
}
558+
NR_PHP_WRAPPER_END
559+
560+
NR_PHP_WRAPPER(nr_rabbitmq_basic_publish) {
548561
zval* amqp_exchange = NULL;
549562
zval* amqp_routing_key = NULL;
550563
zval* amqp_connection = NULL;
@@ -559,11 +572,15 @@ NR_PHP_WRAPPER(nr_rabbitmq_basic_publish) {
559572

560573
(void)wraprec;
561574

575+
#if ZEND_MODULE_API_NO < ZEND_8_0_X_API_NO /* PHP8.0+ */
576+
zval* amqp_msg = NULL;
562577
amqp_msg = nr_php_get_user_func_arg(1, NR_EXECUTE_ORIG_ARGS);
563578
/*
564579
* nr_php_amqplib_insert_dt_headers will check the validity of the object.
565580
*/
566581
nr_php_amqplib_insert_dt_headers(amqp_msg);
582+
#endif
583+
567584
amqp_exchange = nr_php_get_user_func_arg(2, NR_EXECUTE_ORIG_ARGS);
568585
if (nr_php_is_zval_non_empty_string(amqp_exchange)) {
569586
/*
@@ -789,8 +806,9 @@ void nr_php_amqplib_enable() {
789806

790807
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* less than PHP8.0 */
791808
nr_php_wrap_user_function_before_after_clean(
792-
NR_PSTR("PhpAmqpLib\\Channel\\AMQPChannel::basic_publish"), NULL,
793-
nr_rabbitmq_basic_publish, nr_rabbitmq_basic_publish);
809+
NR_PSTR("PhpAmqpLib\\Channel\\AMQPChannel::basic_publish"),
810+
nr_rabbitmq_basic_publish_before, nr_rabbitmq_basic_publish,
811+
nr_rabbitmq_basic_publish);
794812

795813
nr_php_wrap_user_function_before_after_clean(
796814
NR_PSTR("PhpAmqpLib\\Channel\\AMQPChannel::basic_get"), NULL,

0 commit comments

Comments
 (0)