Skip to content

Commit

Permalink
chore(agent): add supportability metrics for guzzle and monolog by ma…
Browse files Browse the repository at this point in the history
…jor version
  • Loading branch information
hahuja2 committed Mar 29, 2024
1 parent e32440d commit 5248b97
Show file tree
Hide file tree
Showing 93 changed files with 108 additions and 4 deletions.
5 changes: 4 additions & 1 deletion agent/fw_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ void nr_fw_support_add_package_supportability_metric(
}
}

if ('\0' == major_version[0]) {
if ('\0' == major_version[0] && '\0' == package_version[0]) {
return;
} else {
strncpy(major_version, package_version, 1);
major_version[1] = '\0';
}

if (NR_FW_UNSET == NRINI(force_framework)) {
Expand Down
3 changes: 3 additions & 0 deletions agent/lib_guzzle6.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ NR_PHP_WRAPPER_START(nr_guzzle6_client_construct) {

if (NRINI(vulnerability_management_package_detection_enabled)) {
char* version = nr_php_get_object_constant(this_var, "VERSION");
if (NULL == version) {
version = nr_php_get_object_constant(this_var, "MAJOR_VERSION");
}
// Add php package to transaction
nr_txn_add_php_package(NRPRG(txn), "guzzlehttp/guzzle", version);
nr_fw_support_add_package_supportability_metric(
Expand Down
4 changes: 4 additions & 0 deletions agent/lib_monolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ NR_PHP_WRAPPER(nr_monolog_logger_addrecord) {
api = nr_monolog_version(this_var TSRMLS_CC);
timestamp
= nr_monolog_get_timestamp(api, argc, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
char version[5];
snprintf(version, sizeof(version), "%d", api);
nr_fw_support_add_package_supportability_metric(NRPRG(txn),
"monolog/monolog", version);
}

/* Record the log event */
Expand Down
11 changes: 8 additions & 3 deletions agent/php_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,15 @@ char* nr_php_get_object_constant(zval* app, const char* name) {

if (nr_php_is_zval_valid_string(version)) {
retval = nr_strndup(Z_STRVAL_P(version), Z_STRLEN_P(version));
} else if (nr_php_is_zval_valid_integer(version)) {
zend_string* zstr = zend_long_to_str(Z_LVAL_P(version));
retval = nr_strndup(ZSTR_VAL(zstr), ZSTR_LEN(zstr));
zend_string_release(zstr);
} else {
nrl_verbosedebug(NRL_FRAMEWORK,
"%s: expected VERSION be a valid string, got type %d",
__func__, Z_TYPE_P(version));
nrl_verbosedebug(
NRL_FRAMEWORK,
"%s: expected VERSION to be a valid string or int, got type %d",
__func__, Z_TYPE_P(version));
}

nr_php_zval_free(&version);
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle7/test_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"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/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle7/test_dt.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"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/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"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/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle7/test_dt_synthetics.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
[{"name":"WebTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"WebTransactionTotalTime/Uri__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"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/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle7/test_no_cat_no_dt.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"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/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/logging/monolog2/test_monolog_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [8, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/logging/monolog2/test_monolog_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [8, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/PHP/package/monolog/monolog/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Loading

0 comments on commit 5248b97

Please sign in to comment.