Skip to content

Commit 8abf1eb

Browse files
committed
simplify user instrumentation initialization handling
The only way nr_php_user_instrument_wraprec_hashmap_init can fail is when memory cannot be allocated, which is already considered a fatal error and causes php process to exit so there's no point in returning failure status in such case. Additionally, nrl_* (logging) does not work until INI has been processed so the error message wouldn't get logged anyway.
1 parent 5383c94 commit 8abf1eb

File tree

4 files changed

+4
-15
lines changed

4 files changed

+4
-15
lines changed

agent/php_minit.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,7 @@ PHP_MINIT_FUNCTION(newrelic) {
499499
* - newrelic.webtransaction.name.functions
500500
* - newrelic.transaction_tracer.custom
501501
*/
502-
if (NR_SUCCESS != nr_php_user_instrument_wraprec_hashmap_init()) {
503-
nrl_error(NRL_AGENT,
504-
"%s: Failed to initialize user function instrumentation and user "
505-
"functions will not be instrumented.",
506-
__func__);
507-
}
502+
nr_php_user_instrument_wraprec_hashmap_init();
508503
#endif
509504

510505
nr_php_register_ini_entries(module_number TSRMLS_CC);

agent/php_user_instrument_wraprec_hashmap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,13 @@ static void nr_php_user_instrument_wraprec_hashmap_name2keys(
380380
func->name_hash = zend_hash_func(func->name, func->name_len);
381381
}
382382

383-
nr_status_t nr_php_user_instrument_wraprec_hashmap_init(void) {
383+
void nr_php_user_instrument_wraprec_hashmap_init(void) {
384384
if (NULL == scope_ht) {
385385
scope_ht = nr_scope_hashmap_create_internal(0);
386386
}
387387
if (NULL == global_funcs_ht) {
388388
global_funcs_ht = nr_func_hashmap_create_internal(0);
389389
}
390-
if (NULL == scope_ht || NULL == global_funcs_ht) {
391-
return NR_FAILURE;
392-
}
393-
return NR_SUCCESS;
394390
}
395391

396392
/* This function expects namestr and namestrlen to be validated with

agent/php_user_instrument_wraprec_hashmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// clang-format off
1212

13-
extern nr_status_t nr_php_user_instrument_wraprec_hashmap_init(void);
13+
extern void nr_php_user_instrument_wraprec_hashmap_init(void);
1414
extern nruserfn_t* nr_php_user_instrument_wraprec_hashmap_add(const char* namestr, size_t namestrlen);
1515
extern nruserfn_t* nr_php_user_instrument_wraprec_hashmap_get(zend_string *func_name, zend_string *scope_name);
1616
extern void nr_php_user_instrument_wraprec_hashmap_destroy(void);

agent/tests/test_user_instrument_wraprec_hashmap.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ tlib_parallel_info_t parallel_info
2020
#define FUNCTION_NAME "global_function"
2121

2222
static void test_wraprecs_hashmap() {
23-
nr_status_t init_status;
2423
nruserfn_t *wraprec, *found_wraprec;
2524
zend_string *func_name, *scope_name, *method_name;
2625

@@ -39,8 +38,7 @@ static void test_wraprecs_hashmap() {
3938
tlib_pass_if_null("adding valid method before init", wraprec);
4039

4140
// Initialize the hashmap
42-
init_status = nr_php_user_instrument_wraprec_hashmap_init();
43-
tlib_pass_if_int_equal("wraprec hashmap init", NR_SUCCESS, init_status);
41+
nr_php_user_instrument_wraprec_hashmap_init();
4442

4543
// Test valid operations after initializing the hashmap
4644
wraprec = nr_php_user_instrument_wraprec_hashmap_add(NR_PSTR(FUNCTION_NAME));

0 commit comments

Comments
 (0)