Skip to content

Commit 4f7af23

Browse files
SybretTimPansino
andauthored
Pyramid (transaction naming): lower exception view precedence (#237)
* Pyramid (transaction naming): increased priority to 2 for non-exception views so they take precedence * Correct transaction names in tests * Fix cornice test transaction name Co-authored-by: Tim Pansino <[email protected]>
1 parent e2e914c commit 4f7af23

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

newrelic/hooks/framework_pyramid.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ def view_handler_wrapper(wrapped, instance, args, kwargs):
9898

9999
name = callable_name(view_callable)
100100

101-
transaction.set_transaction_name(name)
101+
# set exception views to priority=1 so they won't take precedence over
102+
# the original view callable
103+
transaction.set_transaction_name(
104+
name,
105+
priority=1 if args and isinstance(args[0], Exception) else 2)
102106

103107
with FunctionTrace(name) as trace:
104108
try:
@@ -157,15 +161,15 @@ def _wrapper(context, request):
157161
inst = getattr(request, '__view__', None)
158162
if inst is not None:
159163
name = callable_name(getattr(inst, attr))
160-
transaction.set_transaction_name(name, priority=1)
164+
transaction.set_transaction_name(name, priority=2)
161165
tracer.name = name
162166
else:
163167
inst = getattr(request, '__view__', None)
164168
if inst is not None:
165169
method = getattr(inst, '__call__')
166170
if method:
167171
name = callable_name(method)
168-
transaction.set_transaction_name(name, priority=1)
172+
transaction.set_transaction_name(name, priority=2)
169173
tracer.name = name
170174

171175
return _wrapper

tests/framework_pyramid/test_application.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _test():
8080

8181
@validate_transaction_errors(errors=[])
8282
@validate_transaction_metrics(
83-
'pyramid.httpexceptions:default_exceptionresponse_view',
83+
'_test_application:not_found_exception_response',
8484
scoped_metrics=_test_not_found_as_exception_response_scoped_metrics)
8585
def test_not_found_as_exception_response():
8686
application = target_application()
@@ -98,7 +98,7 @@ def test_not_found_as_exception_response():
9898

9999
@validate_transaction_errors(errors=[])
100100
@validate_transaction_metrics(
101-
'pyramid.httpexceptions:default_exceptionresponse_view',
101+
'_test_application:raise_not_found',
102102
scoped_metrics=_test_not_found_raises_NotFound_scoped_metrics)
103103
def test_application_not_found_raises_NotFound():
104104
application = target_application()
@@ -154,7 +154,7 @@ def test_application_unexpected_exception():
154154

155155
@validate_transaction_errors(errors=[])
156156
@validate_transaction_metrics(
157-
'pyramid.httpexceptions:default_exceptionresponse_view',
157+
'_test_application:redirect',
158158
scoped_metrics=_test_redirect_scoped_metrics)
159159
def test_application_redirect():
160160
application = target_application()

tests/framework_pyramid/test_cornice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_cornice_resource_get():
9191
_test_cornice_error_errors = ['exceptions:RuntimeError']
9292

9393
@validate_transaction_errors(errors=_test_cornice_error_errors)
94-
@validate_transaction_metrics('cornice.pyramidhook:handle_exceptions',
94+
@validate_transaction_metrics('_test_application:cornice_error_get_info',
9595
scoped_metrics=_test_cornice_error_scoped_metrics)
9696
def test_cornice_error():
9797
application = target_application()

0 commit comments

Comments
 (0)