Skip to content

Commit 7eb5a8e

Browse files
committed
Merge branch 'feat/rabbitmq_instrumentation' of github.com:newrelic/newrelic-php-agent into feat/rabbitmq_instrumentation
2 parents 87f641e + ba45e6c commit 7eb5a8e

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

agent/fw_laravel_queue.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ static void nr_laravel_queue_set_cat_txn(zval* job TSRMLS_DC) {
136136
}
137137

138138
if (headers.dt_payload || headers.traceparent) {
139-
140139
nr_hashmap_t* header_map = nr_header_create_distributed_trace_map(
141140
headers.dt_payload, headers.traceparent, headers.tracestate);
142141

@@ -225,6 +224,11 @@ static char* nr_laravel_queue_job_txn_name(zval* job TSRMLS_DC) {
225224

226225
name = nr_formatf("%s (%s:%s)", resolve_name, connection_name, queue_name);
227226

227+
nr_free(connection_name);
228+
nr_free(resolve_name);
229+
nr_free(queue_name);
230+
231+
/* Caller is responsible for freeing name. */
228232
return name;
229233
}
230234

@@ -252,6 +256,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_syncqueue_raiseBeforeJobEvent_before) {
252256

253257
job = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS);
254258

259+
/* txn_name needs to be freed by the caller. */
255260
txn_name = nr_laravel_queue_job_txn_name(job);
256261

257262
/*
@@ -271,6 +276,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_syncqueue_raiseBeforeJobEvent_before) {
271276
NR_OK_TO_OVERWRITE);
272277
}
273278
nr_php_arg_release(&job);
279+
nr_free(txn_name);
274280
NR_PHP_WRAPPER_CALL;
275281
}
276282
NR_PHP_WRAPPER_END
@@ -317,6 +323,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_raiseBeforeJobEvent_after) {
317323
nr_txn_set_path("Laravel", NRPRG(txn), txn_name, NR_PATH_TYPE_CUSTOM,
318324
NR_OK_TO_OVERWRITE);
319325
}
326+
nr_free(txn_name);
320327
nr_php_arg_release(&job);
321328
NR_PHP_WRAPPER_CALL;
322329
}
@@ -574,7 +581,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_process) {
574581
* as the first parameter.
575582
*/
576583
char* connection_name = NULL;
577-
char* job_name;
584+
char* job_name = NULL;
578585
char* txn_name = NULL;
579586

580587
connection = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);

agent/lib_php_amqplib.c

+4
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ static inline void nr_php_amqplib_get_host_and_port(
200200
}
201201

202202
/*
203+
<<<<<<< HEAD
203204
* Purpose : Applies DT headers to an inbound AMQPMessage.
205+
=======
206+
* Purpose : Applies DT headers to an outbound AMQPMessage.
207+
>>>>>>> ba45e6c624f8575435f798c92b85808924e32bfb
204208
* Note:
205209
* The DT header 'newrelic' will only be added if both
206210
* newrelic.distributed_tracing_enabled is enabled and

axiom/nr_header.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ nr_hashmap_t* nr_header_create_distributed_trace_map(const char* nr_header,
4848
return NULL;
4949
}
5050

51-
header_map = nr_hashmap_create(NULL);
51+
header_map = nr_hashmap_create((nr_hashmap_dtor_func_t)nr_hashmap_dtor_str);
52+
5253
if (nr_header) {
5354
nr_hashmap_set(header_map, NR_PSTR(NEWRELIC), nr_strdup(nr_header));
5455
}

axiom/tests/test_header.c

+70
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,75 @@ static void test_account_id_from_cross_process_id(void) {
17021702
nr_header_account_id_from_cross_process_id("10#10"));
17031703
}
17041704

1705+
static void test_nr_header_create_distributed_trace_map(void) {
1706+
nr_hashmap_t* header_map = NULL;
1707+
char* tracestate = "tracestate";
1708+
char* traceparent = "traceparent";
1709+
char* dt_payload = "newrelic";
1710+
1711+
header_map = nr_header_create_distributed_trace_map(NULL, NULL, NULL);
1712+
tlib_pass_if_null(
1713+
"NULL payload and NULL traceparent should return NULL header map",
1714+
header_map);
1715+
1716+
header_map = nr_header_create_distributed_trace_map(NULL, NULL, tracestate);
1717+
tlib_pass_if_null(
1718+
"NULL payload and NULL traceparent should return NULL header map",
1719+
header_map);
1720+
1721+
header_map = nr_header_create_distributed_trace_map(dt_payload, NULL, NULL);
1722+
tlib_pass_if_not_null("if valid dt_payload should return a header map",
1723+
header_map);
1724+
tlib_pass_if_size_t_equal(
1725+
"1 header passed in so should expect headers hashmap size of 1", 1,
1726+
nr_hashmap_count(header_map));
1727+
nr_hashmap_destroy(&header_map);
1728+
1729+
header_map
1730+
= nr_header_create_distributed_trace_map(dt_payload, traceparent, NULL);
1731+
tlib_pass_if_not_null("if valid dt_payload should return a header map",
1732+
header_map);
1733+
tlib_pass_if_size_t_equal(
1734+
"2 headers passed in so should expect headers hashmap size of 2", 2,
1735+
nr_hashmap_count(header_map));
1736+
nr_hashmap_destroy(&header_map);
1737+
1738+
header_map
1739+
= nr_header_create_distributed_trace_map(dt_payload, NULL, tracestate);
1740+
tlib_pass_if_not_null("if valid dt_payload should return a header map",
1741+
header_map);
1742+
tlib_pass_if_size_t_equal(
1743+
"2 headers passed in so should expect headers hashmap size of 2", 2,
1744+
nr_hashmap_count(header_map));
1745+
nr_hashmap_destroy(&header_map);
1746+
1747+
header_map = nr_header_create_distributed_trace_map(dt_payload, traceparent,
1748+
tracestate);
1749+
tlib_pass_if_not_null("if valid dt_payload should return a header map",
1750+
header_map);
1751+
tlib_pass_if_size_t_equal(
1752+
"3 headers passed in so should expect headers hashmap size of 3", 3,
1753+
nr_hashmap_count(header_map));
1754+
nr_hashmap_destroy(&header_map);
1755+
1756+
header_map
1757+
= nr_header_create_distributed_trace_map(NULL, traceparent, tracestate);
1758+
tlib_pass_if_not_null("if valid traceparent should return a header map",
1759+
header_map);
1760+
tlib_pass_if_size_t_equal(
1761+
"Two headers passed in so should expect headers hashmap size of 2", 2,
1762+
nr_hashmap_count(header_map));
1763+
nr_hashmap_destroy(&header_map);
1764+
1765+
header_map = nr_header_create_distributed_trace_map(NULL, traceparent, NULL);
1766+
tlib_pass_if_not_null("if valid traceparent should return a header map",
1767+
header_map);
1768+
tlib_pass_if_size_t_equal(
1769+
"1 header passed in so should expect headers hashmap size of 1", 1,
1770+
nr_hashmap_count(header_map));
1771+
nr_hashmap_destroy(&header_map);
1772+
}
1773+
17051774
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 2, .state_size = 0};
17061775

17071776
void test_main(void* p NRUNUSED) {
@@ -1721,4 +1790,5 @@ void test_main(void* p NRUNUSED) {
17211790
test_set_cat_txn();
17221791
test_set_synthetics_txn();
17231792
test_account_id_from_cross_process_id();
1793+
test_nr_header_create_distributed_trace_map();
17241794
}

0 commit comments

Comments
 (0)