Skip to content

Commit 2eac250

Browse files
committed
Support per-vhost app naming for FrankenPHP
Read NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY from the request's $_SERVER globals and pass them into nr_php_txn_begin(), so each FrankenPHP virtual host can report under its own application name and license key instead of inheriting a single process-wide config. - php_frankenphp.c: resolve appname/license in the request handler's fcall_begin hook (the FrankenPHP rinit emulation) and free them after the transaction begins. - php_rinit.c: do the same in the standard RINIT path, guarded by ZTS and a frankenphp SAPI check so non-FrankenPHP SAPIs are unaffected.
1 parent 173a048 commit 2eac250

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

agent/php_frankenphp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ static void nr_php_frankenphp_request_handler_fcall_begin(
1515
nrl_verbosedebug(NRL_INSTRUMENT,
1616
"frankenphp_request_handler_fcall_begin started");
1717
// emulate rinit
18-
nr_php_txn_begin(0, 0);
18+
char* appnames = nr_php_get_server_global("NEW_RELIC_APP_NAME");
19+
char* license = nr_php_get_server_global("NEW_RELIC_LICENSE_KEY");
20+
nr_php_txn_begin(appnames, license);
1921
nrl_verbosedebug(NRL_INSTRUMENT,
2022
"frankenphp_request_handler_fcall_begin done");
23+
nr_free(appnames);
24+
nr_free(license);
2125
}
2226

2327
static void nr_php_frankenphp_request_handler_fcall_end(

agent/php_rinit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void zm_activate_newrelic(void); /* ctags landing pad only */
4747
PHP_RINIT_FUNCTION(newrelic) {
4848
(void)type;
4949
(void)module_number;
50+
char* appnames = NULL;
51+
char* license = NULL;
5052

5153
NRPRG_SHARED(current_framework) = NR_FW_UNSET;
5254
NRPRG_CTX(php_cur_stack_depth) = 0;
@@ -150,7 +152,17 @@ PHP_RINIT_FUNCTION(newrelic) {
150152
NRPRG_CTX(datastore_connections) = nr_hashmap_create(
151153
(nr_hashmap_dtor_func_t)nr_php_datastore_instance_destroy);
152154

153-
nr_php_txn_begin(0, 0 TSRMLS_CC);
155+
#ifdef ZTS
156+
if (nr_streq(sapi_module.name, "frankenphp")) {
157+
appnames = nr_php_get_server_global("NEW_RELIC_APP_NAME");
158+
license = nr_php_get_server_global("NEW_RELIC_LICENSE_KEY");
159+
}
160+
#endif
161+
162+
nr_php_txn_begin(appnames, license TSRMLS_CC);
163+
164+
nr_free(appnames);
165+
nr_free(license);
154166

155167
nrl_verbosedebug(NRL_INIT, "RINIT processing done");
156168

0 commit comments

Comments
 (0)