From 33e1737f042f1baabc4acdf5e9c27ee6efc2159c Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 21 Apr 2025 15:08:15 -0500 Subject: [PATCH 01/12] feat(agent): composer api package detection on by default --- agent/php_nrini.c | 2 +- agent/scripts/newrelic.ini.template | 4 ++-- .../autoloader/test_autoloader_with_composer_disabled.php | 1 + .../autoloader/test_autoloader_without_composer_disabled.php | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/agent/php_nrini.c b/agent/php_nrini.c index dce25a27a..489e79548 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -3135,7 +3135,7 @@ STD_PHP_INI_ENTRY_EX("newrelic.vulnerability_management.package_detection.enable nr_enabled_disabled_dh) STD_PHP_INI_ENTRY_EX("newrelic.vulnerability_management.composer_api.enabled", - "0", + "1", NR_PHP_REQUEST, nr_boolean_mh, vulnerability_management_composer_api_enabled, diff --git a/agent/scripts/newrelic.ini.template b/agent/scripts/newrelic.ini.template index aeaf75641..95bafcd29 100644 --- a/agent/scripts/newrelic.ini.template +++ b/agent/scripts/newrelic.ini.template @@ -1363,11 +1363,11 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log" ; Setting: newrelic.vulnerability_management.composer_api.enabled ; Type : boolean ; Scope : per-directory -; Default: false +; Default: true ; Info : Toggles whether the agent should try using Composer's runtime API ; to gather package information for vulnerability management. ; -;newrelic.vulnerability_management.composer_api.enabled = false +;newrelic.vulnerability_management.composer_api.enabled = true ; Setting: newrelic.message_tracer.segment_parameters.enabled ; Type : boolean diff --git a/tests/integration/autoloader/test_autoloader_with_composer_disabled.php b/tests/integration/autoloader/test_autoloader_with_composer_disabled.php index f564c0a63..e995d21de 100644 --- a/tests/integration/autoloader/test_autoloader_with_composer_disabled.php +++ b/tests/integration/autoloader/test_autoloader_with_composer_disabled.php @@ -12,6 +12,7 @@ */ /*INI +newrelic.vulnerability_management.composer_api.enabled = false */ /*EXPECT_PHP_PACKAGES null*/ diff --git a/tests/integration/autoloader/test_autoloader_without_composer_disabled.php b/tests/integration/autoloader/test_autoloader_without_composer_disabled.php index 8e527a220..31b210fee 100644 --- a/tests/integration/autoloader/test_autoloader_without_composer_disabled.php +++ b/tests/integration/autoloader/test_autoloader_without_composer_disabled.php @@ -11,6 +11,7 @@ */ /*INI +newrelic.vulnerability_management.composer_api.enabled = false */ /*EXPECT_METRICS_DONT_EXIST From 8050f4336e51edea5fb76b685a459a87dc375ae1 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 21 Apr 2025 16:03:29 -0500 Subject: [PATCH 02/12] fix guzzle 6/7 expect metrics --- tests/integration/external/guzzle6/test_cat.php | 2 ++ tests/integration/external/guzzle6/test_dt.php | 2 ++ .../external/guzzle6/test_dt_newrelic_header_disabled.php | 2 ++ tests/integration/external/guzzle6/test_dt_synthetics.php | 2 ++ .../external/guzzle6/test_dt_synthetics_logging_off.php | 2 ++ tests/integration/external/guzzle6/test_no_cat_no_dt.php | 2 ++ tests/integration/external/guzzle7/test_cat.php | 2 ++ tests/integration/external/guzzle7/test_dt.php | 2 ++ .../external/guzzle7/test_dt_newrelic_header_disabled.php | 2 ++ tests/integration/external/guzzle7/test_dt_synthetics.php | 2 ++ tests/integration/external/guzzle7/test_no_cat_no_dt.php | 2 ++ 11 files changed, 22 insertions(+) diff --git a/tests/integration/external/guzzle6/test_cat.php b/tests/integration/external/guzzle6/test_cat.php index 834185ad4..e097dabbe 100644 --- a/tests/integration/external/guzzle6/test_cat.php +++ b/tests/integration/external/guzzle6/test_cat.php @@ -54,6 +54,8 @@ [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"},[1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle6/test_dt.php b/tests/integration/external/guzzle6/test_dt.php index d405abdfa..59e0c70c0 100644 --- a/tests/integration/external/guzzle6/test_dt.php +++ b/tests/integration/external/guzzle6/test_dt.php @@ -44,6 +44,8 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle6/test_dt_newrelic_header_disabled.php b/tests/integration/external/guzzle6/test_dt_newrelic_header_disabled.php index 290ca52e7..18efa6d6d 100644 --- a/tests/integration/external/guzzle6/test_dt_newrelic_header_disabled.php +++ b/tests/integration/external/guzzle6/test_dt_newrelic_header_disabled.php @@ -45,6 +45,8 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle6/test_dt_synthetics.php b/tests/integration/external/guzzle6/test_dt_synthetics.php index ccfc8ac31..6fb8de3b7 100644 --- a/tests/integration/external/guzzle6/test_dt_synthetics.php +++ b/tests/integration/external/guzzle6/test_dt_synthetics.php @@ -67,6 +67,8 @@ [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle6/test_dt_synthetics_logging_off.php b/tests/integration/external/guzzle6/test_dt_synthetics_logging_off.php index 3981082e5..f27c17f9e 100644 --- a/tests/integration/external/guzzle6/test_dt_synthetics_logging_off.php +++ b/tests/integration/external/guzzle6/test_dt_synthetics_logging_off.php @@ -70,6 +70,8 @@ [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle6/test_no_cat_no_dt.php b/tests/integration/external/guzzle6/test_no_cat_no_dt.php index 8d42dff85..39db807a9 100644 --- a/tests/integration/external/guzzle6/test_no_cat_no_dt.php +++ b/tests/integration/external/guzzle6/test_no_cat_no_dt.php @@ -44,6 +44,8 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"},[1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle7/test_cat.php b/tests/integration/external/guzzle7/test_cat.php index c865cc94f..7f081b47e 100644 --- a/tests/integration/external/guzzle7/test_cat.php +++ b/tests/integration/external/guzzle7/test_cat.php @@ -54,6 +54,8 @@ [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/7/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle7/test_dt.php b/tests/integration/external/guzzle7/test_dt.php index 3b4375c5d..d21811b98 100644 --- a/tests/integration/external/guzzle7/test_dt.php +++ b/tests/integration/external/guzzle7/test_dt.php @@ -44,6 +44,8 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/7/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php b/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php index 3f98fd74d..d7849538a 100644 --- a/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php +++ b/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php @@ -45,6 +45,8 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/7/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle7/test_dt_synthetics.php b/tests/integration/external/guzzle7/test_dt_synthetics.php index 18541bfad..0a6c63116 100644 --- a/tests/integration/external/guzzle7/test_dt_synthetics.php +++ b/tests/integration/external/guzzle7/test_dt_synthetics.php @@ -67,6 +67,8 @@ [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/7/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle7/test_no_cat_no_dt.php b/tests/integration/external/guzzle7/test_no_cat_no_dt.php index 5d6413715..1c3e39699 100644 --- a/tests/integration/external/guzzle7/test_no_cat_no_dt.php +++ b/tests/integration/external/guzzle7/test_no_cat_no_dt.php @@ -44,6 +44,8 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/7/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]], From 9abe044618f443b46b0c46ca0319d8f8c8a5418f Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 21 Apr 2025 16:30:25 -0500 Subject: [PATCH 03/12] fix guzzle 5 tests --- tests/integration/external/guzzle5/test_cat.php | 2 ++ tests/integration/external/guzzle5/test_dt.php | 2 ++ .../external/guzzle5/test_dt_newrelic_header_disabled.php | 2 ++ tests/integration/external/guzzle5/test_dt_synthetics.php | 2 ++ .../external/guzzle5/test_dt_synthetics_logging_off.php | 2 ++ tests/integration/external/guzzle5/test_no_cat_no_dt.php | 2 ++ 6 files changed, 12 insertions(+) diff --git a/tests/integration/external/guzzle5/test_cat.php b/tests/integration/external/guzzle5/test_cat.php index 9e01532df..5605b774a 100644 --- a/tests/integration/external/guzzle5/test_cat.php +++ b/tests/integration/external/guzzle5/test_cat.php @@ -52,6 +52,8 @@ [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt.php b/tests/integration/external/guzzle5/test_dt.php index 4992d91f4..e5d7d3a82 100644 --- a/tests/integration/external/guzzle5/test_dt.php +++ b/tests/integration/external/guzzle5/test_dt.php @@ -41,6 +41,8 @@ [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [1, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php b/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php index 0a3352ba6..c2e32886b 100644 --- a/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php +++ b/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php @@ -42,6 +42,8 @@ [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [1, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt_synthetics.php b/tests/integration/external/guzzle5/test_dt_synthetics.php index 042f9f3eb..1be3952cd 100644 --- a/tests/integration/external/guzzle5/test_dt_synthetics.php +++ b/tests/integration/external/guzzle5/test_dt_synthetics.php @@ -72,6 +72,8 @@ [{"name":"WebTransactionTotalTime/Uri__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php b/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php index 559517104..2daceb659 100644 --- a/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php +++ b/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php @@ -75,6 +75,8 @@ [{"name":"WebTransactionTotalTime/Uri__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_no_cat_no_dt.php b/tests/integration/external/guzzle5/test_no_cat_no_dt.php index 241a01fa9..b1e7d7f7e 100644 --- a/tests/integration/external/guzzle5/test_no_cat_no_dt.php +++ b/tests/integration/external/guzzle5/test_no_cat_no_dt.php @@ -43,6 +43,8 @@ [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], + [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"},[1, "??", "??", "??", "??", "??"]], From 75f3ad38ba06d311c845e203a3f04ebf5c1e1f8a Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 21 Apr 2025 17:09:17 -0500 Subject: [PATCH 04/12] formatting change to trigger PR test suite --- .../external/guzzle7/test_dt_newrelic_header_disabled.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php b/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php index d7849538a..f609c203e 100644 --- a/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php +++ b/tests/integration/external/guzzle7/test_dt_newrelic_header_disabled.php @@ -44,7 +44,7 @@ [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/PHP/package/guzzlehttp/guzzle/7/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], + [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], From 5fcf9c740d03bf94b95259c9e60bdfa32ab1b2c6 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 21 Apr 2025 19:41:09 -0500 Subject: [PATCH 05/12] remove composer metric from guzzle 5 expects --- tests/integration/external/guzzle5/test_cat.php | 1 - tests/integration/external/guzzle5/test_dt.php | 1 - .../external/guzzle5/test_dt_newrelic_header_disabled.php | 1 - tests/integration/external/guzzle5/test_dt_synthetics.php | 1 - .../external/guzzle5/test_dt_synthetics_logging_off.php | 1 - tests/integration/external/guzzle5/test_no_cat_no_dt.php | 1 - 6 files changed, 6 deletions(-) diff --git a/tests/integration/external/guzzle5/test_cat.php b/tests/integration/external/guzzle5/test_cat.php index 5605b774a..254bc23f3 100644 --- a/tests/integration/external/guzzle5/test_cat.php +++ b/tests/integration/external/guzzle5/test_cat.php @@ -53,7 +53,6 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt.php b/tests/integration/external/guzzle5/test_dt.php index e5d7d3a82..bbd19ba7b 100644 --- a/tests/integration/external/guzzle5/test_dt.php +++ b/tests/integration/external/guzzle5/test_dt.php @@ -42,7 +42,6 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [1, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php b/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php index c2e32886b..de432cacb 100644 --- a/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php +++ b/tests/integration/external/guzzle5/test_dt_newrelic_header_disabled.php @@ -43,7 +43,6 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [1, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt_synthetics.php b/tests/integration/external/guzzle5/test_dt_synthetics.php index 1be3952cd..e23f4f466 100644 --- a/tests/integration/external/guzzle5/test_dt_synthetics.php +++ b/tests/integration/external/guzzle5/test_dt_synthetics.php @@ -73,7 +73,6 @@ [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php b/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php index 2daceb659..8bc244e3b 100644 --- a/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php +++ b/tests/integration/external/guzzle5/test_dt_synthetics_logging_off.php @@ -76,7 +76,6 @@ [{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allWeb"}, [1, "??", "??", "??", "??", "??"]], diff --git a/tests/integration/external/guzzle5/test_no_cat_no_dt.php b/tests/integration/external/guzzle5/test_no_cat_no_dt.php index b1e7d7f7e..93a3e477e 100644 --- a/tests/integration/external/guzzle5/test_no_cat_no_dt.php +++ b/tests/integration/external/guzzle5/test_no_cat_no_dt.php @@ -44,7 +44,6 @@ [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/library/Guzzle 4-5/detected"}, [1, 0, 0, 0, 0, 0]], [{"name":"Supportability/library/Autoloader/detected"}, [1, "??", "??", "??", "??", "??"]], - [{"name":"Supportability/library/Composer/detected"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"},[1, "??", "??", "??", "??", "??"]], From 37ad626aa2486ce50127a60233392f3c820432a1 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 5 May 2025 15:01:28 -0500 Subject: [PATCH 06/12] feat: add per process composer package sampling --- agent/lib_composer.c | 8 ++++++++ agent/php_globals.h | 6 ++++++ agent/php_minit.c | 1 + agent/php_nrini.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/agent/lib_composer.c b/agent/lib_composer.c index f6596639a..674bff3c3 100644 --- a/agent/lib_composer.c +++ b/agent/lib_composer.c @@ -7,6 +7,7 @@ #include "fw_hooks.h" #include "fw_support.h" #include "nr_txn.h" +#include "php_globals.h" #include "util_logging.h" #include "util_memory.h" #include "util_syscalls.h" @@ -136,6 +137,13 @@ static void nr_execute_handle_autoload_composer_get_packages_information( __func__); return; } + + if (NR_PHP_PROCESS_GLOBALS(composer_api_per_process_detection)) { + // set the per-process flag to true to avoid re-running composer api + // detection when the per-process detection is enabled. + NR_PHP_PROCESS_GLOBALS(composer_packages_detected) = 1; + } + if (IS_ARRAY == Z_TYPE(retval)) { zend_string* package_name = NULL; zval* package_version = NULL; diff --git a/agent/php_globals.h b/agent/php_globals.h index ff9a9824f..4d0a2fe24 100644 --- a/agent/php_globals.h +++ b/agent/php_globals.h @@ -75,6 +75,12 @@ typedef struct _nrphpglobals_t { int apache_threaded; /* 1 if a threaded MPM is in use, 0 otherwise */ int preload_framework_library_detection; /* Enables preloading framework and library detection */ + int composer_api_per_process_detection; /* Enables per-process VM package + detection when Composer API is also + enabled */ + int composer_packages_detected; /* Flag to indicate that Composer package + detection has run. Used in conjunction with + composer_api_per_process_detection. */ char* docker_id; /* 64 byte hex docker ID parsed from /proc/self/mountinfo */ /* Original PHP callback pointer contents */ diff --git a/agent/php_minit.c b/agent/php_minit.c index 08f5a02c5..7cd14bc59 100644 --- a/agent/php_minit.c +++ b/agent/php_minit.c @@ -456,6 +456,7 @@ PHP_MINIT_FUNCTION(newrelic) { = nr_php_check_for_upgrade_license_key(); NR_PHP_PROCESS_GLOBALS(high_security) = 0; NR_PHP_PROCESS_GLOBALS(preload_framework_library_detection) = 1; + NR_PHP_PROCESS_GLOBALS(composer_packages_detected) = 0; nr_php_populate_apache_process_globals(); nr_php_api_distributed_trace_register_userland_class(TSRMLS_C); /* diff --git a/agent/php_nrini.c b/agent/php_nrini.c index 489e79548..50280a544 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -537,6 +537,28 @@ static PHP_INI_MH(nr_preload_framework_library_detection_mh) { return SUCCESS; } +static PHP_INI_MH(nr_composer_per_process_detection_mh) { + int val; + + (void)entry; + (void)NEW_VALUE_LEN; + (void)mh_arg1; + (void)mh_arg2; + (void)mh_arg3; + (void)stage; + NR_UNUSED_TSRMLS; + + val = nr_bool_from_str(NEW_VALUE); + + if (-1 == val) { + return FAILURE; + } + + NR_PHP_PROCESS_GLOBALS(composer_api_per_process_detection) = val ? 1 : 0; + + return SUCCESS; +} + static PHP_INI_MH(nr_loglevel_mh) { nr_status_t rv; @@ -2055,6 +2077,17 @@ PHP_INI_ENTRY_EX("newrelic.preload_framework_library_detection", nr_preload_framework_library_detection_mh, 0) +/* + * Enables per-process Composer API package detection and reporting. Depends on + * newrelic.vulnerability_management.composer_api.enabled. + */ +PHP_INI_ENTRY_EX( + "newrelic.vulnerability_management.composer_api.per_process_detection", + "1", + NR_PHP_SYSTEM, + nr_composer_per_process_detection_mh, + 0) + /* * Daemon */ From 41406b82a3025ee41075c66f20525046de304803 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 5 May 2025 15:13:05 -0500 Subject: [PATCH 07/12] add composer per process to the ini template --- agent/scripts/newrelic.ini.template | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agent/scripts/newrelic.ini.template b/agent/scripts/newrelic.ini.template index 95bafcd29..c5ae501cc 100644 --- a/agent/scripts/newrelic.ini.template +++ b/agent/scripts/newrelic.ini.template @@ -1369,6 +1369,16 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log" ; ;newrelic.vulnerability_management.composer_api.enabled = true +; Setting: newrelic.vulnerability_management.composer_api.per_process_detection +; Type : boolean +; Scope : system +; Default: true +; Info : Controls the frequency at which Composer API samples the runtime environment +; for package data. When set to `true`, sampling will only occur once per process. +; If false, Composer will sample the environment every request. +; +;newrelic.vulnerability_management.composer_api.per_process_detection = true + ; Setting: newrelic.message_tracer.segment_parameters.enabled ; Type : boolean ; Scope : per-directory From 3f9e8c23d06094c4ec0d035ac7dfb7164fcc4a31 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 5 May 2025 17:04:49 -0500 Subject: [PATCH 08/12] fix: re-add composer bailout lost trying to play nice with autoformat --- agent/php_execute.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agent/php_execute.c b/agent/php_execute.c index fb8b8cb2f..7257f7471 100644 --- a/agent/php_execute.c +++ b/agent/php_execute.c @@ -904,6 +904,13 @@ static void nr_execute_handle_autoload(const char* filename, return; } + if (NR_PHP_PROCESS_GLOBALS(composer_api_per_process_detection) + && NR_PHP_PROCESS_GLOBALS(composer_packages_detected)) { + // do nothing if per-process detection is enabled and the flag to track + // detection is true + return; + } + if (!nr_striendswith(STR_AND_LEN(filename), AUTOLOAD_MAGIC_FILE, AUTOLOAD_MAGIC_FILE_LEN)) { // not an autoload file From 37abb653a3976819c0d22dff4102a6cf929ea33c Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Thu, 22 May 2025 15:36:18 -0500 Subject: [PATCH 09/12] add warning msg for invalid config --- agent/php_nrini.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/agent/php_nrini.c b/agent/php_nrini.c index 50280a544..a8e1d7c7a 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -551,6 +551,11 @@ static PHP_INI_MH(nr_composer_per_process_detection_mh) { val = nr_bool_from_str(NEW_VALUE); if (-1 == val) { + nrl_warning(NRL_INIT, + "The value %d is not valid for the " + "newrelic.vulnerability_management.composer_api.per_process_" + "detection setting, using default value instead.", + val); return FAILURE; } From 789e5d3ea9bea26a729f50b72c7ae51f1a9507b1 Mon Sep 17 00:00:00 2001 From: bduranleau-nr <106178551+bduranleau-nr@users.noreply.github.com> Date: Thu, 22 May 2025 15:36:52 -0500 Subject: [PATCH 10/12] Update agent/scripts/newrelic.ini.template Co-authored-by: Michael Fulbright <89205663+mfulb@users.noreply.github.com> --- agent/scripts/newrelic.ini.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/scripts/newrelic.ini.template b/agent/scripts/newrelic.ini.template index c5ae501cc..cecc1486c 100644 --- a/agent/scripts/newrelic.ini.template +++ b/agent/scripts/newrelic.ini.template @@ -1375,7 +1375,7 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log" ; Default: true ; Info : Controls the frequency at which Composer API samples the runtime environment ; for package data. When set to `true`, sampling will only occur once per process. -; If false, Composer will sample the environment every request. +; If false, Composer will sample the environment every request, increasing the frequency which this package detection is performed. ; ;newrelic.vulnerability_management.composer_api.per_process_detection = true From 3b5d88c1646b38b2a8cccc802e966e770b4d96f4 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Fri, 23 May 2025 11:17:23 -0500 Subject: [PATCH 11/12] print string value --- agent/php_nrini.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/php_nrini.c b/agent/php_nrini.c index a8e1d7c7a..6f316190b 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -552,10 +552,10 @@ static PHP_INI_MH(nr_composer_per_process_detection_mh) { if (-1 == val) { nrl_warning(NRL_INIT, - "The value %d is not valid for the " + "The value %s is not valid for the " "newrelic.vulnerability_management.composer_api.per_process_" "detection setting, using default value instead.", - val); + NEW_VALUE); return FAILURE; } From a004604cc41795e2d460ff82a3b6f81ce0fa714e Mon Sep 17 00:00:00 2001 From: bduranleau-nr <106178551+bduranleau-nr@users.noreply.github.com> Date: Fri, 23 May 2025 11:54:41 -0500 Subject: [PATCH 12/12] Update agent/php_nrini.c Co-authored-by: Michael Fulbright <89205663+mfulb@users.noreply.github.com> --- agent/php_nrini.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/php_nrini.c b/agent/php_nrini.c index 6f316190b..6cddef5b2 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -552,7 +552,7 @@ static PHP_INI_MH(nr_composer_per_process_detection_mh) { if (-1 == val) { nrl_warning(NRL_INIT, - "The value %s is not valid for the " + "The value \"%s\" is not valid for the " "newrelic.vulnerability_management.composer_api.per_process_" "detection setting, using default value instead.", NEW_VALUE);