Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fc58607

Browse files
committedJul 2, 2024·
add trace id and span id to metadata
1 parent 1a4bc74 commit fc58607

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed
 

‎agent/csec_metadata.c

+19-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313
#include "php_includes.h"
1414
#include "php_compat.h"
1515
#include "php_newrelic.h"
16+
#include "util_strings.h"
1617

1718
int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) {
1819
const char* value = NULL;
20+
char* id_value = NULL;
21+
bool is_allocated = false;
1922

2023
if (NULL == p) {
2124
return -1;
2225
}
2326

24-
if (NULL == NRPRG(app)) {
27+
if (NULL == NRPRG(app) || NULL == NRPRG(txn)) {
2528
return -2;
2629
}
2730

@@ -57,15 +60,28 @@ int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) {
5760
case NR_PHP_CSEC_METADATA_PLICENSE:
5861
value = NRPRG(app)->plicense;
5962
break;
63+
case NR_PHP_CSEC_METADATA_TRACE_ID:
64+
id_value = nr_txn_get_current_trace_id(NRPRG(txn));
65+
is_allocated = true;
66+
break;
67+
case NR_PHP_CSEC_METADATA_SPAN_ID:
68+
id_value = nr_txn_get_current_span_id(NRPRG(txn));
69+
is_allocated = true;
70+
break;
6071
default:
6172
return -4;
6273
}
6374

64-
if (NULL == value) {
75+
if (!is_allocated && NULL == value) {
6576
return -5;
6677
}
6778

68-
*p = nr_strdup(value);
79+
if (is_allocated) {
80+
*p = id_value;
81+
} else {
82+
*p = nr_strdup(value);
83+
}
84+
6985
if (NULL == *p) {
7086
return -3;
7187
}

‎agent/csec_metadata.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
#define CSEC_METADATA_H
88

99
typedef enum {
10-
NR_PHP_CSEC_METADATA_HIGH_SECURITY = 1,
11-
NR_PHP_CSEC_METADATA_ENTITY_NAME,
12-
NR_PHP_CSEC_METADATA_ENTITY_TYPE,
13-
NR_PHP_CSEC_METADATA_ENTITY_GUID,
14-
NR_PHP_CSEC_METADATA_HOST_NAME,
15-
NR_PHP_CSEC_METADATA_AGENT_RUN_ID,
16-
NR_PHP_CSEC_METADATA_ACCOUNT_ID,
17-
NR_PHP_CSEC_METADATA_LICENSE,
18-
NR_PHP_CSEC_METADATA_PLICENSE
10+
NR_PHP_CSEC_METADATA_HIGH_SECURITY = 1,
11+
NR_PHP_CSEC_METADATA_ENTITY_NAME,
12+
NR_PHP_CSEC_METADATA_ENTITY_TYPE,
13+
NR_PHP_CSEC_METADATA_ENTITY_GUID,
14+
NR_PHP_CSEC_METADATA_HOST_NAME,
15+
NR_PHP_CSEC_METADATA_AGENT_RUN_ID,
16+
NR_PHP_CSEC_METADATA_ACCOUNT_ID,
17+
NR_PHP_CSEC_METADATA_LICENSE,
18+
NR_PHP_CSEC_METADATA_PLICENSE,
19+
NR_PHP_CSEC_METADATA_TRACE_ID,
20+
NR_PHP_CSEC_METADATA_SPAN_ID
1921
} nr_php_csec_metadata_key_t;
2022

2123
/*
@@ -33,7 +35,9 @@ typedef enum {
3335
* -4 for invalid metadata key
3436
* -5 for inability to retrieve metadata value
3537
*/
36-
extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, char** value);
37-
typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, char** value);
38+
extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k,
39+
char** value);
40+
typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k,
41+
char** value);
3842
#define NR_PHP_CSEC_GET_METADATA "nr_php_csec_get_metadata"
3943
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.