Skip to content

Commit e177f40

Browse files
committed
chore(axiom): remove helper function and split up if statements
1 parent 1886008 commit e177f40

File tree

1 file changed

+52
-57
lines changed

1 file changed

+52
-57
lines changed

axiom/nr_txn.c

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,20 +1552,27 @@ nr_status_t nr_txn_record_error_worthy(const nrtxn_t* txn, int priority) {
15521552
return NR_SUCCESS;
15531553
}
15541554

1555-
static void nr_txn_record_error_helper(nrtxn_t* txn,
1556-
int priority,
1557-
bool add_to_current_segment,
1558-
const char* error_message,
1559-
const char* error_class,
1560-
const char* error_file,
1561-
int error_line,
1562-
char* error_context,
1563-
int error_no,
1564-
const char* stacktrace_json) {
1555+
void nr_txn_record_error_with_additional_attributes(
1556+
nrtxn_t* txn,
1557+
int priority,
1558+
bool add_to_current_segment,
1559+
const char* error_message,
1560+
const char* error_class,
1561+
const char* error_file,
1562+
int error_line,
1563+
char* error_context,
1564+
int error_no,
1565+
const char* stacktrace_json) {
15651566
nr_segment_t* current_segment = NULL;
15661567
char* span_id = NULL;
15671568
nr_error_t* error = NULL;
15681569

1570+
if (nrunlikely((0 == txn) || (0 == txn->options.err_enabled)
1571+
|| (0 == txn->status.recording) || (0 == stacktrace_json)
1572+
|| (0 == error_class))) {
1573+
return;
1574+
}
1575+
15691576
if ((txn->error) && (priority < nr_error_priority(txn->error))) {
15701577
/*priority of new error is lower, so we don't need to do anything */
15711578
return;
@@ -1599,15 +1606,7 @@ static void nr_txn_record_error_helper(nrtxn_t* txn,
15991606
current_segment = nr_txn_get_current_segment(txn, NULL);
16001607

16011608
if (current_segment) {
1602-
if (NULL == error_file) {
1603-
nr_segment_set_error(current_segment, error_message, error_class);
1604-
nrl_verbosedebug(NRL_TXN,
1605-
"recording segment error: msg='%.48s' cls='%.48s'"
1606-
"span_id='%.48s'",
1607-
NRSAFESTR(error_message), NRSAFESTR(error_class),
1608-
NRSAFESTR(span_id));
1609-
} else {
1610-
nr_segment_set_error_with_additional_params(
1609+
nr_segment_set_error_with_additional_params(
16111610
current_segment, error_message, error_class, error_file,
16121611
error_line, error_context, error_no);
16131612
nrl_verbosedebug(NRL_TXN,
@@ -1618,18 +1617,12 @@ static void nr_txn_record_error_helper(nrtxn_t* txn,
16181617
NRSAFESTR(error_file), error_line,
16191618
NRSAFESTR(error_context), error_no,
16201619
NRSAFESTR(span_id));
1621-
}
16221620
}
16231621
}
16241622
}
1625-
if (NULL == error_file) {
1626-
error = nr_error_create(priority, error_message, error_class,
1627-
stacktrace_json, span_id, nr_get_time());
1628-
} else {
1629-
error = nr_error_create_additional_params(
1623+
error = nr_error_create_additional_params(
16301624
priority, error_message, error_class, error_file, error_line,
16311625
error_context, error_no, stacktrace_json, span_id, nr_get_time());
1632-
}
16331626

16341627
/*
16351628
* Ensure previous error is destroyed only we have a valid one to replace it
@@ -1668,31 +1661,9 @@ void nr_txn_record_error(nrtxn_t* txn,
16681661
|| (0 == stacktrace_json))) {
16691662
return;
16701663
}
1671-
nr_txn_record_error_helper(txn, priority, add_to_current_segment, errmsg,
1672-
errclass, NULL, 0, NULL, 0, stacktrace_json);
1673-
}
1674-
1675-
void nr_txn_record_error_with_additional_attributes(
1676-
nrtxn_t* txn,
1677-
int priority,
1678-
bool add_to_current_segment,
1679-
const char* error_message,
1680-
const char* error_class,
1681-
const char* error_file,
1682-
int error_line,
1683-
char* error_context,
1684-
int error_no,
1685-
const char* stacktrace_json) {
1686-
if (nrunlikely((0 == txn) || (0 == txn->options.err_enabled)
1687-
|| (0 == error_message) || (0 == txn->status.recording)
1688-
|| (0 == error_message[0]) || (0 == stacktrace_json)
1689-
|| (0 == error_class) || (0 == error_file) || (0 == error_line)
1690-
|| (0 == error_context) || (0 == error_no))) {
1691-
return;
1692-
}
1693-
nr_txn_record_error_helper(txn, priority, add_to_current_segment,
1694-
error_message, error_class, error_file, error_line,
1695-
error_context, error_no, stacktrace_json);
1664+
nr_txn_record_error_with_additional_attributes(
1665+
txn, priority, add_to_current_segment, errmsg, errclass, NULL, 0, NULL, 0,
1666+
stacktrace_json);
16961667
}
16971668

16981669
char* nr_txn_create_fn_supportability_metric(const char* function_name,
@@ -2534,8 +2505,10 @@ nr_analytics_event_t* nr_error_to_event(const nrtxn_t* txn) {
25342505
nro_set_hash_string(params, "type", "TransactionError");
25352506
nro_set_hash_double(params, "timestamp", ((double)when) / NR_TIME_DIVISOR_D);
25362507
nro_set_hash_string(params, "error.class", nr_error_get_klass(txn->error));
2537-
nro_set_hash_string(params, "error.message",
2538-
nr_error_get_message(txn->error));
2508+
if (NULL != nr_error_get_message(txn->error)) {
2509+
nro_set_hash_string(params, "error.message",
2510+
nr_error_get_message(txn->error));
2511+
}
25392512
nro_set_hash_string(params, "transactionName", txn->name);
25402513
nro_set_hash_double(params, "duration",
25412514
((double)duration) / NR_TIME_DIVISOR_D);
@@ -2583,19 +2556,41 @@ nr_analytics_event_t* nr_error_to_event(const nrtxn_t* txn) {
25832556
NR_ATTRIBUTE_DESTINATION_ERROR);
25842557
user_attributes = nr_attributes_user_to_obj(txn->attributes,
25852558
NR_ATTRIBUTE_DESTINATION_ERROR);
2586-
if (nr_error_get_file(txn->error) && nr_error_get_context(txn->error)) {
2559+
if (nr_error_get_message(txn->error)) {
2560+
if (NULL == user_attributes) {
2561+
user_attributes = nro_new_hash();
2562+
}
2563+
nro_set_hash_string(user_attributes, "user.error.message",
2564+
nr_error_get_message(txn->error));
2565+
}
2566+
if (nr_error_get_file(txn->error)) {
25872567
if (NULL == user_attributes) {
25882568
user_attributes = nro_new_hash();
25892569
}
25902570
nro_set_hash_string(user_attributes, "user.error.file",
25912571
nr_error_get_file(txn->error));
2592-
nro_set_hash_int(user_attributes, "user.error.line",
2593-
nr_error_get_line(txn->error));
2572+
}
2573+
if (nr_error_get_context(txn->error)) {
2574+
if (NULL == user_attributes) {
2575+
user_attributes = nro_new_hash();
2576+
}
25942577
nro_set_hash_string(user_attributes, "user.error.context",
25952578
nr_error_get_context(txn->error));
2596-
nro_set_hash_int(user_attributes, "user.error.no",
2579+
}
2580+
if (nr_error_get_no(txn->error)) {
2581+
if (NULL == user_attributes) {
2582+
user_attributes = nro_new_hash();
2583+
}
2584+
nro_set_hash_int(user_attributes, "user.error.number",
25972585
nr_error_get_no(txn->error));
25982586
}
2587+
if (nr_error_get_line(txn->error)) {
2588+
if (NULL == user_attributes) {
2589+
user_attributes = nro_new_hash();
2590+
}
2591+
nro_set_hash_int(user_attributes, "user.error.line",
2592+
nr_error_get_line(txn->error));
2593+
}
25992594
event = nr_analytics_event_create(params, agent_attributes, user_attributes);
26002595

26012596
nro_delete(params);

0 commit comments

Comments
 (0)