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