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