|
38 | 38 | )
|
39 | 39 | from newrelic.config import extra_settings
|
40 | 40 | from newrelic.core.config import global_settings
|
41 |
| -from newrelic.hooks.framework_django_py3 import ( |
42 |
| - _nr_wrap_converted_middleware_async_, |
43 |
| - _nr_wrapper_BaseHandler_get_response_async_, |
44 |
| -) |
45 | 41 |
|
46 | 42 | _logger = logging.getLogger(__name__)
|
47 | 43 |
|
@@ -420,6 +416,36 @@ def _nr_wrapper_BaseHandler_get_response_(wrapped, instance, args, kwargs):
|
420 | 416 | return response
|
421 | 417 |
|
422 | 418 |
|
| 419 | +async def _nr_wrapper_BaseHandler_get_response_async_(wrapped, instance, args, kwargs): |
| 420 | + response = await wrapped(*args, **kwargs) |
| 421 | + |
| 422 | + if current_transaction() is None: |
| 423 | + return response |
| 424 | + |
| 425 | + request = _bind_get_response(*args, **kwargs) |
| 426 | + |
| 427 | + if hasattr(request, "_nr_exc_info"): |
| 428 | + notice_error(error=request._nr_exc_info, status_code=response.status_code) |
| 429 | + delattr(request, "_nr_exc_info") |
| 430 | + |
| 431 | + return response |
| 432 | + |
| 433 | + |
| 434 | +def _nr_wrap_converted_middleware_async_(middleware, name): |
| 435 | + @function_wrapper |
| 436 | + async def _wrapper(wrapped, instance, args, kwargs): |
| 437 | + transaction = current_transaction() |
| 438 | + |
| 439 | + if transaction is None: |
| 440 | + return await wrapped(*args, **kwargs) |
| 441 | + |
| 442 | + transaction.set_transaction_name(name, priority=2) |
| 443 | + |
| 444 | + return await FunctionTraceWrapper(wrapped, name=name)(*args, **kwargs) |
| 445 | + |
| 446 | + return _wrapper(middleware) |
| 447 | + |
| 448 | + |
423 | 449 | # Post import hooks for modules.
|
424 | 450 |
|
425 | 451 |
|
|
0 commit comments