Skip to content

Commit 952f119

Browse files
committed
fifth round of fixes
Make it possible for wraprecs to be created when INI is processed. For that to be possible, two things are necessary: - the wraprec hashmap needs to be created before INI processing starts - the pid stored in wraprec needs to be set using the value returned by nr_getpid because per request global pid (NRPRG(pid)) is not initialized until rinit.
1 parent 998970b commit 952f119

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

agent/php_minit.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,18 @@ PHP_MINIT_FUNCTION(newrelic) {
492492
*/
493493
nr_php_generate_internal_wrap_records();
494494

495+
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
496+
/*
497+
* The user function wraprec hashmap must be initialized before INI processing
498+
* because INI processing adds wraprecs:
499+
* - newrelic.webtransaction.name.functions
500+
* - newrelic.transaction_tracer.custom
501+
*/
502+
if (NR_SUCCESS != nr_php_user_instrument_wraprec_hashmap_init()) {
503+
nrl_error(NRL_AGENT, "Failed to initialize user function instrumentation");
504+
}
505+
#endif
506+
495507
nr_php_register_ini_entries(module_number TSRMLS_CC);
496508

497509
if (0 == NR_PHP_PROCESS_GLOBALS(enabled)) {
@@ -670,9 +682,6 @@ PHP_MINIT_FUNCTION(newrelic) {
670682
NR_ZEND_EXECUTE_HOOK = nr_php_execute;
671683
#else
672684
nr_php_observer_minit();
673-
if (NR_SUCCESS != nr_php_user_instrument_wraprec_hashmap_init()) {
674-
nrl_error(NRL_AGENT, "Failed to initialize user function instrumentation");
675-
}
676685
#endif
677686

678687
if (NR_PHP_PROCESS_GLOBALS(instrument_internal)) {

agent/php_user_instrument.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "util_logging.h"
1414
#include "util_memory.h"
1515
#include "util_strings.h"
16+
#include "util_syscalls.h"
1617

1718
/*
1819
* The mechanism of zend_try .. zend_catch .. zend_end_try
@@ -318,7 +319,9 @@ static void nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSRMLS_DC) {
318319

319320
nruserfn_t* nr_php_user_wraprec_create(void) {
320321
nruserfn_t* wr = (nruserfn_t*)nr_zalloc(sizeof(nruserfn_t));
321-
wr->pid = NRPRG(pid);
322+
/* NRPRG(pid) is set in rinit but it's sometimes needed before rinit,
323+
* i.e. when wraprec is added via INI */
324+
wr->pid = (0 != NRPRG(pid) ? NRPRG(pid) : nr_getpid());
322325
return wr;
323326
}
324327

0 commit comments

Comments
 (0)