Skip to content

Commit 9f44c72

Browse files
hahuja2mfulb
authored andcommitted
chore(axiom): remove helper function and split up if statements
1 parent a7a519c commit 9f44c72

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
@@ -1553,20 +1553,27 @@ nr_status_t nr_txn_record_error_worthy(const nrtxn_t* txn, int priority) {
15531553
return NR_SUCCESS;
15541554
}
15551555

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

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

16021609
if (current_segment) {
1603-
if (NULL == error_file) {
1604-
nr_segment_set_error(current_segment, error_message, error_class);
1605-
nrl_verbosedebug(NRL_TXN,
1606-
"recording segment error: msg='%.48s' cls='%.48s'"
1607-
"span_id='%.48s'",
1608-
NRSAFESTR(error_message), NRSAFESTR(error_class),
1609-
NRSAFESTR(span_id));
1610-
} else {
1611-
nr_segment_set_error_with_additional_params(
1610+
nr_segment_set_error_with_additional_params(
16121611
current_segment, error_message, error_class, error_file,
16131612
error_line, error_context, error_no);
16141613
nrl_verbosedebug(NRL_TXN,
@@ -1619,18 +1618,12 @@ static void nr_txn_record_error_helper(nrtxn_t* txn,
16191618
NRSAFESTR(error_file), error_line,
16201619
NRSAFESTR(error_context), error_no,
16211620
NRSAFESTR(span_id));
1622-
}
16231621
}
16241622
}
16251623
}
1626-
if (NULL == error_file) {
1627-
error = nr_error_create(priority, error_message, error_class,
1628-
stacktrace_json, span_id, nr_get_time());
1629-
} else {
1630-
error = nr_error_create_additional_params(
1624+
error = nr_error_create_additional_params(
16311625
priority, error_message, error_class, error_file, error_line,
16321626
error_context, error_no, stacktrace_json, span_id, nr_get_time());
1633-
}
16341627

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

16991670
char* nr_txn_create_fn_supportability_metric(const char* function_name,
@@ -2535,8 +2506,10 @@ nr_analytics_event_t* nr_error_to_event(const nrtxn_t* txn) {
25352506
nro_set_hash_string(params, "type", "TransactionError");
25362507
nro_set_hash_double(params, "timestamp", ((double)when) / NR_TIME_DIVISOR_D);
25372508
nro_set_hash_string(params, "error.class", nr_error_get_klass(txn->error));
2538-
nro_set_hash_string(params, "error.message",
2539-
nr_error_get_message(txn->error));
2509+
if (NULL != nr_error_get_message(txn->error)) {
2510+
nro_set_hash_string(params, "error.message",
2511+
nr_error_get_message(txn->error));
2512+
}
25402513
nro_set_hash_string(params, "transactionName", txn->name);
25412514
nro_set_hash_double(params, "duration",
25422515
((double)duration) / NR_TIME_DIVISOR_D);
@@ -2584,19 +2557,41 @@ nr_analytics_event_t* nr_error_to_event(const nrtxn_t* txn) {
25842557
NR_ATTRIBUTE_DESTINATION_ERROR);
25852558
user_attributes = nr_attributes_user_to_obj(txn->attributes,
25862559
NR_ATTRIBUTE_DESTINATION_ERROR);
2587-
if (nr_error_get_file(txn->error) && nr_error_get_context(txn->error)) {
2560+
if (nr_error_get_message(txn->error)) {
2561+
if (NULL == user_attributes) {
2562+
user_attributes = nro_new_hash();
2563+
}
2564+
nro_set_hash_string(user_attributes, "user.error.message",
2565+
nr_error_get_message(txn->error));
2566+
}
2567+
if (nr_error_get_file(txn->error)) {
25882568
if (NULL == user_attributes) {
25892569
user_attributes = nro_new_hash();
25902570
}
25912571
nro_set_hash_string(user_attributes, "user.error.file",
25922572
nr_error_get_file(txn->error));
2593-
nro_set_hash_int(user_attributes, "user.error.line",
2594-
nr_error_get_line(txn->error));
2573+
}
2574+
if (nr_error_get_context(txn->error)) {
2575+
if (NULL == user_attributes) {
2576+
user_attributes = nro_new_hash();
2577+
}
25952578
nro_set_hash_string(user_attributes, "user.error.context",
25962579
nr_error_get_context(txn->error));
2597-
nro_set_hash_int(user_attributes, "user.error.no",
2580+
}
2581+
if (nr_error_get_no(txn->error)) {
2582+
if (NULL == user_attributes) {
2583+
user_attributes = nro_new_hash();
2584+
}
2585+
nro_set_hash_int(user_attributes, "user.error.number",
25982586
nr_error_get_no(txn->error));
25992587
}
2588+
if (nr_error_get_line(txn->error)) {
2589+
if (NULL == user_attributes) {
2590+
user_attributes = nro_new_hash();
2591+
}
2592+
nro_set_hash_int(user_attributes, "user.error.line",
2593+
nr_error_get_line(txn->error));
2594+
}
26002595
event = nr_analytics_event_create(params, agent_attributes, user_attributes);
26012596

26022597
nro_delete(params);

0 commit comments

Comments
 (0)