@@ -1241,9 +1241,6 @@ void nr_txn_destroy_fields(nrtxn_t* txn) {
1241
1241
nro_delete (txn -> intrinsics );
1242
1242
nr_string_pool_destroy (& txn -> datastore_products );
1243
1243
nr_slowsqls_destroy (& txn -> slowsqls );
1244
- if (nr_error_get_option (txn -> error ) > 0 ) {
1245
- nr_error_destroy_additional_params (& txn -> error );
1246
- }
1247
1244
nr_error_destroy (& txn -> error );
1248
1245
nr_distributed_trace_destroy (& txn -> distributed_trace );
1249
1246
nr_segment_destroy_tree (txn -> segment_root );
@@ -1556,34 +1553,31 @@ nr_status_t nr_txn_record_error_worthy(const nrtxn_t* txn, int priority) {
1556
1553
return NR_SUCCESS ;
1557
1554
}
1558
1555
1559
- void nr_txn_record_error (nrtxn_t * txn ,
1560
- int priority ,
1561
- bool add_to_current_segment ,
1562
- const char * errmsg ,
1563
- const char * errclass ,
1564
- const char * stacktrace_json ) {
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 ) {
1565
1566
nr_segment_t * current_segment = NULL ;
1566
1567
char * span_id = NULL ;
1567
1568
nr_error_t * error = NULL ;
1568
1569
1569
- if (nrunlikely ((0 == txn ) || (0 == txn -> options .err_enabled ) || (0 == errmsg )
1570
- || (0 == errclass ) || (0 == txn -> status .recording )
1571
- || (0 == errmsg [0 ]) || (0 == errclass [0 ])
1572
- || (0 == stacktrace_json ))) {
1573
- return ;
1574
- }
1575
-
1576
1570
if ((txn -> error ) && (priority < nr_error_priority (txn -> error ))) {
1577
1571
/*priority of new error is lower, so we don't need to do anything */
1578
1572
return ;
1579
1573
}
1580
1574
1581
1575
if (txn -> high_security ) {
1582
- errmsg = NR_TXN_HIGH_SECURITY_ERROR_MESSAGE ;
1576
+ error_message = NR_TXN_HIGH_SECURITY_ERROR_MESSAGE ;
1583
1577
}
1584
1578
1585
1579
if (0 == txn -> options .allow_raw_exception_messages ) {
1586
- errmsg = NR_TXN_ALLOW_RAW_EXCEPTION_MESSAGE ;
1580
+ error_message = NR_TXN_ALLOW_RAW_EXCEPTION_MESSAGE ;
1587
1581
}
1588
1582
1589
1583
/* Only try to get a span_id in cases where we know spans should be created.
@@ -1606,17 +1600,38 @@ void nr_txn_record_error(nrtxn_t* txn,
1606
1600
current_segment = nr_txn_get_current_segment (txn , NULL );
1607
1601
1608
1602
if (current_segment ) {
1609
- nr_segment_set_error (current_segment , errmsg , errclass );
1610
- nrl_verbosedebug (NRL_TXN ,
1611
- "recording segment error: msg='%.48s' cls='%.48s'"
1612
- "span_id='%.48s'" ,
1613
- NRSAFESTR (errmsg ), NRSAFESTR (errclass ),
1614
- NRSAFESTR (span_id ));
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 (
1612
+ current_segment , error_message , error_class , error_file ,
1613
+ error_line , error_context , error_no );
1614
+ nrl_verbosedebug (NRL_TXN ,
1615
+ "recording segment error: msg='%.48s' cls='%.48s' "
1616
+ "file='%.48s' line='%d' context='%.48s' num='%d'"
1617
+ "span_id='%.48s'" ,
1618
+ NRSAFESTR (error_message ), NRSAFESTR (error_class ),
1619
+ NRSAFESTR (error_file ), error_line ,
1620
+ NRSAFESTR (error_context ), error_no ,
1621
+ NRSAFESTR (span_id ));
1622
+ }
1615
1623
}
1616
1624
}
1617
1625
}
1618
- error = nr_error_create (priority , errmsg , errclass , stacktrace_json , span_id ,
1619
- nr_get_time ());
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 (
1631
+ priority , error_message , error_class , error_file , error_line ,
1632
+ error_context , error_no , stacktrace_json , span_id , nr_get_time ());
1633
+ }
1634
+
1620
1635
/*
1621
1636
* Ensure previous error is destroyed only we have a valid one to replace it
1622
1637
* with.
@@ -1625,7 +1640,7 @@ void nr_txn_record_error(nrtxn_t* txn,
1625
1640
nrl_verbosedebug (NRL_TXN ,
1626
1641
"The following returned NULL from create error: "
1627
1642
"priority=%d msg='%.48s' cls='%.48s' span_id='%.48s'" ,
1628
- priority , NRSAFESTR (errmsg ), NRSAFESTR (errclass ),
1643
+ priority , NRSAFESTR (error_message ), NRSAFESTR (error_class ),
1629
1644
NRSAFESTR (span_id ));
1630
1645
1631
1646
return ;
@@ -1637,11 +1652,27 @@ void nr_txn_record_error(nrtxn_t* txn,
1637
1652
nrl_verbosedebug (NRL_TXN ,
1638
1653
"recording error priority=%d msg='%.48s' cls='%.48s'"
1639
1654
"span_id='%.48s'" ,
1640
- priority , NRSAFESTR (errmsg ), NRSAFESTR (errclass ),
1655
+ priority , NRSAFESTR (error_message ), NRSAFESTR (error_class ),
1641
1656
NRSAFESTR (span_id ));
1642
1657
nr_free (span_id );
1643
1658
}
1644
1659
1660
+ void nr_txn_record_error (nrtxn_t * txn ,
1661
+ int priority ,
1662
+ bool add_to_current_segment ,
1663
+ const char * errmsg ,
1664
+ const char * errclass ,
1665
+ const char * stacktrace_json ) {
1666
+ if (nrunlikely ((0 == txn ) || (0 == txn -> options .err_enabled ) || (0 == errmsg )
1667
+ || (0 == errclass ) || (0 == txn -> status .recording )
1668
+ || (0 == errmsg [0 ]) || (0 == errclass [0 ])
1669
+ || (0 == stacktrace_json ))) {
1670
+ return ;
1671
+ }
1672
+ nr_txn_record_error_helper (txn , priority , add_to_current_segment , errmsg ,
1673
+ errclass , NULL , 0 , NULL , 0 , stacktrace_json );
1674
+ }
1675
+
1645
1676
void nr_txn_record_error_with_additional_attributes (
1646
1677
nrtxn_t * txn ,
1647
1678
int priority ,
@@ -1653,96 +1684,16 @@ void nr_txn_record_error_with_additional_attributes(
1653
1684
char * error_context ,
1654
1685
int error_no ,
1655
1686
const char * stacktrace_json ) {
1656
- nr_segment_t * current_segment = NULL ;
1657
- char * span_id = NULL ;
1658
- nr_error_t * error = NULL ;
1659
-
1660
1687
if (nrunlikely ((0 == txn ) || (0 == txn -> options .err_enabled )
1661
1688
|| (0 == error_message ) || (0 == txn -> status .recording )
1662
1689
|| (0 == error_message [0 ]) || (0 == stacktrace_json )
1663
1690
|| (0 == error_class ) || (0 == error_file ) || (0 == error_line )
1664
1691
|| (0 == error_context ) || (0 == error_no ))) {
1665
1692
return ;
1666
1693
}
1667
-
1668
- if ((txn -> error ) && (priority < nr_error_priority (txn -> error ))) {
1669
- /*priority of new error is lower, so we don't need to do anything */
1670
- return ;
1671
- }
1672
-
1673
- if (txn -> high_security ) {
1674
- error_message = NR_TXN_HIGH_SECURITY_ERROR_MESSAGE ;
1675
- }
1676
-
1677
- if (0 == txn -> options .allow_raw_exception_messages ) {
1678
- error_message = NR_TXN_ALLOW_RAW_EXCEPTION_MESSAGE ;
1679
- }
1680
-
1681
- /* Only try to get a span_id in cases where we know spans should be created.
1682
- */
1683
- if (nr_txn_should_create_span_events (txn )) {
1684
- span_id = nr_txn_get_current_span_id (txn );
1685
-
1686
- /*
1687
- * The specification says span_id MUST be included so if span events are
1688
- * enabled but the span_id doesn't exist, then don't create the error
1689
- * event.
1690
- */
1691
- if (nrunlikely (NULL == span_id )) {
1692
- nrl_error (NRL_TXN ,
1693
- "Expected span_id to create an error but span_id = NULL." );
1694
- return ;
1695
- }
1696
-
1697
- if (add_to_current_segment ) {
1698
- current_segment = nr_txn_get_current_segment (txn , NULL );
1699
-
1700
- if (current_segment ) {
1701
- nr_segment_set_error_with_additional_params (
1702
- current_segment , error_message , error_class , error_file , error_line ,
1703
- error_context , error_no );
1704
- nrl_verbosedebug (NRL_TXN ,
1705
- "recording segment error: msg='%.48s' cls='%.48s' "
1706
- "file='%.48s' line='%d' context='%.48s' num='%d'"
1707
- "span_id='%.48s'" ,
1708
- NRSAFESTR (error_message ), NRSAFESTR (error_class ),
1709
- NRSAFESTR (error_file ), error_line ,
1710
- NRSAFESTR (error_context ), error_no ,
1711
- NRSAFESTR (span_id ));
1712
- }
1713
- }
1714
- }
1715
- error = nr_error_create_additional_params (
1716
- priority , error_message , error_class , error_file , error_line ,
1717
- error_context , error_no , stacktrace_json , span_id , nr_get_time ());
1718
-
1719
- /*
1720
- * Ensure previous error is destroyed only we have a valid one to replace it
1721
- * with.
1722
- */
1723
-
1724
- if (nrunlikely (NULL == error )) {
1725
- nrl_verbosedebug (NRL_TXN ,
1726
- "The following returned NULL from create error: "
1727
- "priority=%d msg='%.48s' cls='%.48s' file='%.48s' "
1728
- "line='%d' context='%.48s' num='%d' span_id='%.48s'" ,
1729
- priority , NRSAFESTR (error_message ), NRSAFESTR (error_class ),
1730
- NRSAFESTR (error_file ), error_line ,
1731
- NRSAFESTR (error_context ), error_no , NRSAFESTR (span_id ));
1732
- return ;
1733
- }
1734
- if (txn -> error ) {
1735
- nr_error_destroy_additional_params (& txn -> error );
1736
- }
1737
- txn -> error = error ;
1738
- nrl_verbosedebug (NRL_TXN ,
1739
- "recording error priority=%d msg='%.48s' cls='%.48s' "
1740
- "file='%.48s' line='%d' context='%.48s' num='%d'"
1741
- "span_id='%.48s'" ,
1742
- priority , NRSAFESTR (error_message ), NRSAFESTR (error_class ),
1743
- NRSAFESTR (error_file ), error_line , NRSAFESTR (error_context ),
1744
- error_no , NRSAFESTR (span_id ));
1745
- nr_free (span_id );
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 );
1746
1697
}
1747
1698
1748
1699
char * nr_txn_create_fn_supportability_metric (const char * function_name ,
@@ -2586,10 +2537,11 @@ nr_analytics_event_t* nr_error_to_event(const nrtxn_t* txn) {
2586
2537
nro_set_hash_string (params , "error.class" , nr_error_get_klass (txn -> error ));
2587
2538
nro_set_hash_string (params , "error.message" ,
2588
2539
nr_error_get_message (txn -> error ));
2589
- if (nr_error_get_option (txn -> error ) > 0 ) {
2540
+ if (nr_error_get_file (txn -> error ) && nr_error_get_context ( txn -> error )) {
2590
2541
nro_set_hash_string (params , "error.file" , nr_error_get_file (txn -> error ));
2591
2542
nro_set_hash_int (params , "error.line" , nr_error_get_line (txn -> error ));
2592
- nro_set_hash_string (params , "error.context" , nr_error_get_context (txn -> error ));
2543
+ nro_set_hash_string (params , "error.context" ,
2544
+ nr_error_get_context (txn -> error ));
2593
2545
nro_set_hash_int (params , "error.no" , nr_error_get_no (txn -> error ));
2594
2546
}
2595
2547
nro_set_hash_string (params , "transactionName" , txn -> name );
0 commit comments