@@ -1553,20 +1553,27 @@ nr_status_t nr_txn_record_error_worthy(const nrtxn_t* txn, int priority) {
1553
1553
return NR_SUCCESS ;
1554
1554
}
1555
1555
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 ) {
1566
1567
nr_segment_t * current_segment = NULL ;
1567
1568
char * span_id = NULL ;
1568
1569
nr_error_t * error = NULL ;
1569
1570
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
+
1570
1577
if ((txn -> error ) && (priority < nr_error_priority (txn -> error ))) {
1571
1578
/*priority of new error is lower, so we don't need to do anything */
1572
1579
return ;
@@ -1600,15 +1607,7 @@ static void nr_txn_record_error_helper(nrtxn_t* txn,
1600
1607
current_segment = nr_txn_get_current_segment (txn , NULL );
1601
1608
1602
1609
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 (
1612
1611
current_segment , error_message , error_class , error_file ,
1613
1612
error_line , error_context , error_no );
1614
1613
nrl_verbosedebug (NRL_TXN ,
@@ -1619,18 +1618,12 @@ static void nr_txn_record_error_helper(nrtxn_t* txn,
1619
1618
NRSAFESTR (error_file ), error_line ,
1620
1619
NRSAFESTR (error_context ), error_no ,
1621
1620
NRSAFESTR (span_id ));
1622
- }
1623
1621
}
1624
1622
}
1625
1623
}
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 (
1631
1625
priority , error_message , error_class , error_file , error_line ,
1632
1626
error_context , error_no , stacktrace_json , span_id , nr_get_time ());
1633
- }
1634
1627
1635
1628
/*
1636
1629
* 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,
1669
1662
|| (0 == stacktrace_json ))) {
1670
1663
return ;
1671
1664
}
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 );
1697
1668
}
1698
1669
1699
1670
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) {
2535
2506
nro_set_hash_string (params , "type" , "TransactionError" );
2536
2507
nro_set_hash_double (params , "timestamp" , ((double )when ) / NR_TIME_DIVISOR_D );
2537
2508
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
+ }
2540
2513
nro_set_hash_string (params , "transactionName" , txn -> name );
2541
2514
nro_set_hash_double (params , "duration" ,
2542
2515
((double )duration ) / NR_TIME_DIVISOR_D );
@@ -2584,19 +2557,41 @@ nr_analytics_event_t* nr_error_to_event(const nrtxn_t* txn) {
2584
2557
NR_ATTRIBUTE_DESTINATION_ERROR );
2585
2558
user_attributes = nr_attributes_user_to_obj (txn -> attributes ,
2586
2559
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 )) {
2588
2568
if (NULL == user_attributes ) {
2589
2569
user_attributes = nro_new_hash ();
2590
2570
}
2591
2571
nro_set_hash_string (user_attributes , "user.error.file" ,
2592
2572
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
+ }
2595
2578
nro_set_hash_string (user_attributes , "user.error.context" ,
2596
2579
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" ,
2598
2586
nr_error_get_no (txn -> error ));
2599
2587
}
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
+ }
2600
2595
event = nr_analytics_event_create (params , agent_attributes , user_attributes );
2601
2596
2602
2597
nro_delete (params );
0 commit comments