diff --git a/agent/csec_metadata.c b/agent/csec_metadata.c index af8af2d91..cab010301 100644 --- a/agent/csec_metadata.c +++ b/agent/csec_metadata.c @@ -13,15 +13,18 @@ #include "php_includes.h" #include "php_compat.h" #include "php_newrelic.h" +#include "util_strings.h" int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) { const char* value = NULL; + char* id_value = NULL; + bool is_allocated = false; if (NULL == p) { return -1; } - if (NULL == NRPRG(app)) { + if (NULL == NRPRG(app) || NULL == NRPRG(txn)) { return -2; } @@ -57,15 +60,28 @@ int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) { case NR_PHP_CSEC_METADATA_PLICENSE: value = NRPRG(app)->plicense; break; + case NR_PHP_CSEC_METADATA_TRACE_ID: + id_value = nr_txn_get_current_trace_id(NRPRG(txn)); + is_allocated = true; + break; + case NR_PHP_CSEC_METADATA_SPAN_ID: + id_value = nr_txn_get_current_span_id(NRPRG(txn)); + is_allocated = true; + break; default: return -4; } - if (NULL == value) { + if (!is_allocated && NULL == value) { return -5; } - *p = nr_strdup(value); + if (is_allocated) { + *p = id_value; + } else { + *p = nr_strdup(value); + } + if (NULL == *p) { return -3; } diff --git a/agent/csec_metadata.h b/agent/csec_metadata.h index a98b79339..bb7c8cc2d 100644 --- a/agent/csec_metadata.h +++ b/agent/csec_metadata.h @@ -7,15 +7,17 @@ #define CSEC_METADATA_H typedef enum { - NR_PHP_CSEC_METADATA_HIGH_SECURITY = 1, - NR_PHP_CSEC_METADATA_ENTITY_NAME, - NR_PHP_CSEC_METADATA_ENTITY_TYPE, - NR_PHP_CSEC_METADATA_ENTITY_GUID, - NR_PHP_CSEC_METADATA_HOST_NAME, - NR_PHP_CSEC_METADATA_AGENT_RUN_ID, - NR_PHP_CSEC_METADATA_ACCOUNT_ID, - NR_PHP_CSEC_METADATA_LICENSE, - NR_PHP_CSEC_METADATA_PLICENSE + NR_PHP_CSEC_METADATA_HIGH_SECURITY = 1, + NR_PHP_CSEC_METADATA_ENTITY_NAME, + NR_PHP_CSEC_METADATA_ENTITY_TYPE, + NR_PHP_CSEC_METADATA_ENTITY_GUID, + NR_PHP_CSEC_METADATA_HOST_NAME, + NR_PHP_CSEC_METADATA_AGENT_RUN_ID, + NR_PHP_CSEC_METADATA_ACCOUNT_ID, + NR_PHP_CSEC_METADATA_LICENSE, + NR_PHP_CSEC_METADATA_PLICENSE, + NR_PHP_CSEC_METADATA_TRACE_ID, + NR_PHP_CSEC_METADATA_SPAN_ID } nr_php_csec_metadata_key_t; /* @@ -33,7 +35,9 @@ typedef enum { * -4 for invalid metadata key * -5 for inability to retrieve metadata value */ -extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, char** value); -typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, char** value); +extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, + char** value); +typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, + char** value); #define NR_PHP_CSEC_GET_METADATA "nr_php_csec_get_metadata" #endif diff --git a/axiom/nr_txn.c b/axiom/nr_txn.c index 2ea39bb26..cb0e11ae4 100644 --- a/axiom/nr_txn.c +++ b/axiom/nr_txn.c @@ -3250,7 +3250,6 @@ char* nr_txn_get_current_trace_id(nrtxn_t* txn) { if ((NULL == trace_id) || (!txn->options.distributed_tracing_enabled)) { return NULL; } - return nr_strdup(trace_id); }