Skip to content

Commit d9c23f3

Browse files
authored
Remove record_exception uses in codebase. (#220)
* Remove uses of record_exception. * Update span event tests. * Update tests to use notice_error.. * Fix incorrect metric name in tests.
1 parent 13508df commit d9c23f3

18 files changed

+78
-78
lines changed

newrelic/admin/validate_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _run_validation_test():
2626
from newrelic.api.external_trace import external_trace
2727
from newrelic.api.function_trace import function_trace
2828
from newrelic.api.transaction import add_custom_parameter
29-
from newrelic.api.time_trace import record_exception
29+
from newrelic.api.time_trace import notice_error
3030
from newrelic.api.wsgi_application import wsgi_application
3131

3232
@external_trace(library='test',
@@ -58,7 +58,7 @@ def _function4(params=None, application=None):
5858
try:
5959
_function5()
6060
except:
61-
record_exception(params=(params or {
61+
notice_error(attributes=(params or {
6262
'err-key-2': 2, 'err-key-3': 3.0}),
6363
application=application)
6464

newrelic/api/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def __exit__(self, exc, value, tb):
401401
# Record error if one was registered.
402402

403403
if exc is not None and value is not None and tb is not None:
404-
root.record_exception((exc, value, tb))
404+
root.notice_error((exc, value, tb))
405405

406406
# Record the end time for transaction and then
407407
# calculate the duration.

newrelic/api/wsgi_application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from newrelic.api.application import application_instance
2121
from newrelic.api.transaction import current_transaction
22-
from newrelic.api.time_trace import record_exception
22+
from newrelic.api.time_trace import notice_error
2323
from newrelic.api.web_transaction import WSGIWebTransaction
2424
from newrelic.api.function_trace import FunctionTrace
2525
from newrelic.api.html_insertion import insert_html_snippet, verify_body_exists
@@ -57,7 +57,7 @@ def __iter__(self):
5757
raise
5858

5959
except: # Catch all
60-
record_exception()
60+
notice_error()
6161
raise
6262

6363
finally:

tests/agent_features/test_asgi_distributed_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,6 @@ def _test():
200200
try:
201201
1 / 0
202202
except ZeroDivisionError:
203-
transaction.record_exception()
203+
transaction.notice_error()
204204

205205
_test()

tests/agent_features/test_attributes_in_action.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from newrelic.api.application import application_instance as application
1919
from newrelic.api.message_transaction import message_transaction
2020
from newrelic.api.transaction import add_custom_parameter
21-
from newrelic.api.time_trace import record_exception
21+
from newrelic.api.time_trace import notice_error
2222
from newrelic.api.wsgi_application import wsgi_application
2323
from newrelic.common.object_names import callable_name
2424

@@ -102,7 +102,7 @@ def normal_wsgi_application(environ, start_response):
102102
try:
103103
raise ValueError('Transaction had bad value')
104104
except ValueError:
105-
record_exception(params={ERROR_PARAMS[0]: 'param-value'})
105+
notice_error(attributes={ERROR_PARAMS[0]: 'param-value'})
106106

107107
return [output]
108108

@@ -886,8 +886,8 @@ def test_error_outside_transaction():
886886
raise OutsideWithParamsError("Error outside transaction")
887887
except OutsideWithParamsError:
888888
application_instance = application()
889-
application_instance.record_exception(
890-
params={'test_key': 'test_value'})
889+
application_instance.notice_error(
890+
attributes={'test_key': 'test_value'})
891891

892892

893893
class OutsideNoParamsError(Exception):
@@ -919,8 +919,8 @@ def test_error_outside_transaction_excluded_user_param():
919919
raise OutsideNoParamsError("Error outside transaction")
920920
except OutsideNoParamsError:
921921
application_instance = application()
922-
application_instance.record_exception(
923-
params={'test_key': 'test_value'})
922+
application_instance.notice_error(
923+
attributes={'test_key': 'test_value'})
924924

925925

926926
# Test routing key agent attribute.

tests/agent_features/test_distributed_tracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _test():
195195
try:
196196
raise ValueError('cookies')
197197
except ValueError:
198-
txn.record_exception()
198+
txn.notice_error()
199199

200200
_test()
201201

@@ -220,7 +220,7 @@ def test_distributed_trace_attrs_omitted():
220220
try:
221221
raise ValueError('cookies')
222222
except ValueError:
223-
txn.record_exception()
223+
txn.notice_error()
224224

225225

226226
# test our distributed_trace metrics by creating a transaction and then forcing
@@ -284,7 +284,7 @@ def _test():
284284
try:
285285
1 / 0
286286
except ZeroDivisionError:
287-
transaction.record_exception()
287+
transaction.notice_error()
288288

289289
_test()
290290

tests/agent_features/test_error_events.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from newrelic.api.application import (application_instance as application,
2020
application_settings)
21-
from newrelic.api.time_trace import record_exception
21+
from newrelic.api.time_trace import notice_error
2222
from newrelic.common.object_names import callable_name
2323

2424
from testing_support.fixtures import (validate_error_event_sample_data,
@@ -216,7 +216,7 @@ def test_error_event_outside_transaction():
216216
raise outside_error
217217
except ErrorEventOutsideTransactionError:
218218
app = application()
219-
record_exception(*sys.exc_info(), application=app)
219+
notice_error(sys.exc_info(), application=app)
220220

221221
_err_params = {'key': 'value'}
222222

@@ -228,7 +228,7 @@ def test_error_event_with_params_outside_transaction():
228228
raise outside_error
229229
except ErrorEventOutsideTransactionError:
230230
app = application()
231-
record_exception(*sys.exc_info(), params=_err_params,
231+
notice_error(sys.exc_info(), attributes=_err_params,
232232
application=app)
233233

234234
@reset_core_stats_engine()
@@ -239,7 +239,7 @@ def test_multiple_error_events_outside_transaction():
239239
try:
240240
raise ErrorEventOutsideTransactionError(ERR_MESSAGE+str(i))
241241
except ErrorEventOutsideTransactionError:
242-
record_exception(*sys.exc_info(), application=app)
242+
notice_error(sys.exc_info(), application=app)
243243

244244
@reset_core_stats_engine()
245245
@override_application_settings({'error_collector.enabled' : False})
@@ -249,7 +249,7 @@ def test_error_event_outside_transaction_error_collector_disabled():
249249
raise outside_error
250250
except ErrorEventOutsideTransactionError:
251251
app = application()
252-
record_exception(*sys.exc_info(), application=app)
252+
notice_error(sys.exc_info(), application=app)
253253

254254
@reset_core_stats_engine()
255255
@override_application_settings({'error_collector.capture_events' : False})
@@ -259,7 +259,7 @@ def test_error_event_outside_transaction_capture_events_disabled():
259259
raise outside_error
260260
except ErrorEventOutsideTransactionError:
261261
app = application()
262-
record_exception(*sys.exc_info(), application=app)
262+
notice_error(sys.exc_info(), application=app)
263263

264264
@reset_core_stats_engine()
265265
@override_application_settings({'collect_error_events' : False})
@@ -269,4 +269,4 @@ def test_error_event_outside_transaction_collect_error_events_false():
269269
raise outside_error
270270
except ErrorEventOutsideTransactionError:
271271
app = application()
272-
record_exception(*sys.exc_info(), application=app)
272+
notice_error(sys.exc_info(), application=app)

tests/agent_features/test_exception_messages.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from newrelic.api.application import application_instance as application
2020
from newrelic.api.background_task import background_task
21-
from newrelic.api.time_trace import record_exception
21+
from newrelic.api.time_trace import notice_error
2222

2323
from testing_support.fixtures import (validate_transaction_exception_message,
2424
set_default_encoding, validate_application_exception_message,
@@ -44,7 +44,7 @@ def test_py2_transaction_exception_message_unicode():
4444
try:
4545
raise ValueError(UNICODE_MESSAGE)
4646
except ValueError:
47-
record_exception()
47+
notice_error()
4848

4949
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
5050
@set_default_encoding('ascii')
@@ -56,7 +56,7 @@ def test_py2_transaction_exception_message_unicode_english():
5656
try:
5757
raise ValueError(UNICODE_ENGLISH)
5858
except ValueError:
59-
record_exception()
59+
notice_error()
6060

6161
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
6262
@set_default_encoding('ascii')
@@ -67,7 +67,7 @@ def test_py2_transaction_exception_message_bytes_english():
6767
try:
6868
raise ValueError(BYTES_ENGLISH)
6969
except ValueError:
70-
record_exception()
70+
notice_error()
7171

7272
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
7373
@set_default_encoding('ascii')
@@ -81,7 +81,7 @@ def test_py2_transaction_exception_message_bytes_non_english():
8181
try:
8282
raise ValueError(BYTES_UTF8_ENCODED)
8383
except ValueError:
84-
record_exception()
84+
notice_error()
8585

8686
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
8787
@set_default_encoding('ascii')
@@ -99,7 +99,7 @@ def test_py2_transaction_exception_message_bytes_implicit_encoding_non_english()
9999

100100
raise ValueError('I💜🐍')
101101
except ValueError:
102-
record_exception()
102+
notice_error()
103103

104104
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
105105
@set_default_encoding('utf-8')
@@ -112,7 +112,7 @@ def test_py2_transaction_exception_message_unicode_utf8_encoding():
112112
try:
113113
raise ValueError(UNICODE_MESSAGE)
114114
except ValueError:
115-
record_exception()
115+
notice_error()
116116

117117
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
118118
@set_default_encoding('utf-8')
@@ -129,7 +129,7 @@ def test_py2_transaction_exception_message_bytes_utf8_encoding_non_english():
129129

130130
raise ValueError('I💜🐍')
131131
except ValueError:
132-
record_exception()
132+
notice_error()
133133

134134
# ---------------- Python 3
135135

@@ -142,7 +142,7 @@ def test_py3_transaction_exception_message_bytes_non_english_unicode():
142142
try:
143143
raise ValueError(UNICODE_MESSAGE)
144144
except ValueError:
145-
record_exception()
145+
notice_error()
146146

147147
@pytest.mark.skipif(six.PY2, reason="Testing Python 3 string behavior")
148148
@validate_transaction_exception_message(UNICODE_ENGLISH)
@@ -153,7 +153,7 @@ def test_py3_transaction_exception_message_unicode_english():
153153
try:
154154
raise ValueError(UNICODE_ENGLISH)
155155
except ValueError:
156-
record_exception()
156+
notice_error()
157157

158158
@pytest.mark.skipif(six.PY2, reason="Testing Python 3 string behavior")
159159
@validate_transaction_exception_message(INCORRECTLY_DECODED_BYTES_PY3)
@@ -169,7 +169,7 @@ def test_py3_transaction_exception_message_bytes_non_english():
169169
try:
170170
raise ValueError(BYTES_UTF8_ENCODED)
171171
except ValueError:
172-
record_exception()
172+
notice_error()
173173

174174
# =================== Exception messages outside transaction ====================
175175

@@ -186,7 +186,7 @@ def test_py2_application_exception_message_unicode():
186186
raise ValueError(UNICODE_MESSAGE)
187187
except ValueError:
188188
app = application()
189-
record_exception(application=app)
189+
notice_error(application=app)
190190

191191
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
192192
@reset_core_stats_engine()
@@ -199,7 +199,7 @@ def test_py2_application_exception_message_unicode_english():
199199
raise ValueError(UNICODE_ENGLISH)
200200
except ValueError:
201201
app = application()
202-
record_exception(application=app)
202+
notice_error(application=app)
203203

204204
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
205205
@reset_core_stats_engine()
@@ -211,7 +211,7 @@ def test_py2_application_exception_message_bytes_english():
211211
raise ValueError(BYTES_ENGLISH)
212212
except ValueError:
213213
app = application()
214-
record_exception(application=app)
214+
notice_error(application=app)
215215

216216
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
217217
@reset_core_stats_engine()
@@ -226,7 +226,7 @@ def test_py2_application_exception_message_bytes_non_english():
226226
raise ValueError(BYTES_UTF8_ENCODED)
227227
except ValueError:
228228
app = application()
229-
record_exception(application=app)
229+
notice_error(application=app)
230230

231231
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
232232
@reset_core_stats_engine()
@@ -245,7 +245,7 @@ def test_py2_application_exception_message_bytes_implicit_encoding_non_english()
245245
raise ValueError('I💜🐍')
246246
except ValueError:
247247
app = application()
248-
record_exception(application=app)
248+
notice_error(application=app)
249249

250250
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
251251
@reset_core_stats_engine()
@@ -259,7 +259,7 @@ def test_py2_application_exception_message_unicode_utf8_encoding():
259259
raise ValueError(UNICODE_MESSAGE)
260260
except ValueError:
261261
app = application()
262-
record_exception(application=app)
262+
notice_error(application=app)
263263

264264
@pytest.mark.skipif(six.PY3, reason="Testing Python 2 string behavior")
265265
@reset_core_stats_engine()
@@ -277,7 +277,7 @@ def test_py2_application_exception_message_bytes_utf8_encoding_non_english():
277277
raise ValueError('I💜🐍')
278278
except ValueError:
279279
app = application()
280-
record_exception(application=app)
280+
notice_error(application=app)
281281

282282
# ---------------- Python 3
283283

@@ -291,7 +291,7 @@ def test_py3_application_exception_message_bytes_non_english_unicode():
291291
raise ValueError(UNICODE_MESSAGE)
292292
except ValueError:
293293
app = application()
294-
record_exception(application=app)
294+
notice_error(application=app)
295295

296296
@pytest.mark.skipif(six.PY2, reason="Testing Python 3 string behavior")
297297
@reset_core_stats_engine()
@@ -303,7 +303,7 @@ def test_py3_application_exception_message_unicode_english():
303303
raise ValueError(UNICODE_ENGLISH)
304304
except ValueError:
305305
app = application()
306-
record_exception(application=app)
306+
notice_error(application=app)
307307

308308
@pytest.mark.skipif(six.PY2, reason="Testing Python 3 string behavior")
309309
@reset_core_stats_engine()
@@ -320,4 +320,4 @@ def test_py3_application_exception_message_bytes_non_english():
320320
raise ValueError(BYTES_UTF8_ENCODED)
321321
except ValueError:
322322
app = application()
323-
record_exception(application=app)
323+
notice_error(application=app)

0 commit comments

Comments
 (0)