Skip to content

Commit

Permalink
chore(agent): define major version length
Browse files Browse the repository at this point in the history
  • Loading branch information
hahuja2 committed Apr 15, 2024
1 parent 0fc0bde commit 55c1e1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions agent/fw_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "util_memory.h"
#include "util_strings.h"

#define MAJOR_VERSION_LENGTH 8

void nr_php_framework_add_supportability_metric(const char* framework_name,
const char* name TSRMLS_DC) {
char buf[512];
Expand Down Expand Up @@ -62,13 +64,13 @@ void nr_fw_support_add_package_supportability_metric(
}

char* metname = NULL;
char major_version[5] = {0};
char major_version[MAJOR_VERSION_LENGTH] = {0};

/* The below for loop checks if the major version of the package is more than
* one digit and keeps looping until a '.' is encountered or one of the
* conditions is met.
*/
for (int i = 0; package_version[i] && i < 4; i++) {
for (int i = 0; package_version[i] && i < MAJOR_VERSION_LENGTH - 1; i++) {
if ('.' == package_version[i]) {
break;
}
Expand Down
3 changes: 2 additions & 1 deletion agent/lib_monolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"newrelic_phpagent_monolog_decorating_processor"

#define PHP_PACKAGE_NAME "monolog/monolog"
#define MAJOR_VERSION_LENGTH 8

/*
* Purpose : Convert Monolog\Logger::API to integer
Expand Down Expand Up @@ -375,7 +376,7 @@ 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];
char version[MAJOR_VERSION_LENGTH];
snprintf(version, sizeof(version), "%d", api);
nr_fw_support_add_package_supportability_metric(NRPRG(txn),
PHP_PACKAGE_NAME, version);
Expand Down

0 comments on commit 55c1e1e

Please sign in to comment.