|
18 | 18 | import time |
19 | 19 |
|
20 | 20 | from newrelic.api.application import application_instance |
21 | | -from newrelic.api.transaction import current_transaction |
22 | | -from newrelic.api.time_trace import notice_error |
23 | | -from newrelic.api.web_transaction import WSGIWebTransaction |
24 | 21 | from newrelic.api.function_trace import FunctionTrace, FunctionTraceWrapper |
25 | 22 | from newrelic.api.html_insertion import insert_html_snippet, verify_body_exists |
26 | 23 | from newrelic.api.time_trace import notice_error |
@@ -80,12 +77,12 @@ def close(self): |
80 | 77 | self.response_trace = None |
81 | 78 |
|
82 | 79 | try: |
83 | | - with FunctionTrace(name='Finalize', group='Python/WSGI'): |
| 80 | + with FunctionTrace(name="Finalize", group="Python/WSGI"): |
84 | 81 |
|
85 | 82 | if isinstance(self.generator, _WSGIApplicationMiddleware): |
86 | 83 | self.generator.close() |
87 | 84 |
|
88 | | - elif hasattr(self.generator, 'close'): |
| 85 | + elif hasattr(self.generator, "close"): |
89 | 86 | FunctionTraceWrapper(self.generator.close)() |
90 | 87 |
|
91 | 88 | except: # Catch all |
@@ -437,7 +434,7 @@ def close(self): |
437 | 434 | # Call close() on the iterable as required by the |
438 | 435 | # WSGI specification. |
439 | 436 |
|
440 | | - if hasattr(self.iterable, 'close'): |
| 437 | + if hasattr(self.iterable, "close"): |
441 | 438 | FunctionTraceWrapper(self.iterable.close)() |
442 | 439 |
|
443 | 440 | def __iter__(self): |
@@ -510,7 +507,7 @@ def __iter__(self): |
510 | 507 | yield data |
511 | 508 |
|
512 | 509 |
|
513 | | -def WSGIApplicationWrapper(wrapped, application=None, name=None, group=None, framework=None): |
| 510 | +def WSGIApplicationWrapper(wrapped, application=None, name=None, group=None, framework=None, dispatcher=None): |
514 | 511 |
|
515 | 512 | # Python 2 does not allow rebinding nonlocal variables, so to fix this |
516 | 513 | # framework must be stored in list so it can be edited by closure. |
@@ -556,6 +553,9 @@ def _nr_wsgi_application_wrapper_(wrapped, instance, args, kwargs): |
556 | 553 | if framework: |
557 | 554 | transaction.add_framework_info(name=framework[0], version=framework[1]) |
558 | 555 |
|
| 556 | + if dispatcher: |
| 557 | + transaction.add_dispatcher_info(name=dispatcher[0], version=dispatcher[1]) |
| 558 | + |
559 | 559 | # Also override the web transaction name to be the name of |
560 | 560 | # the wrapped callable if not explicitly named, and we want |
561 | 561 | # the default name to be that of the WSGI component for the |
@@ -618,6 +618,9 @@ def _args(environ, start_response, *args, **kwargs): |
618 | 618 | if framework: |
619 | 619 | transaction.add_framework_info(name=framework[0], version=framework[1]) |
620 | 620 |
|
| 621 | + if dispatcher: |
| 622 | + transaction.add_dispatcher_info(name=dispatcher[0], version=dispatcher[1]) |
| 623 | + |
621 | 624 | # Override the initial web transaction name to be the supplied |
622 | 625 | # name, or the name of the wrapped callable if wanting to use |
623 | 626 | # the callable as the default. This will override the use of a |
@@ -672,7 +675,7 @@ def write(data): |
672 | 675 | if "wsgi.input" in environ: |
673 | 676 | environ["wsgi.input"] = _WSGIInputWrapper(transaction, environ["wsgi.input"]) |
674 | 677 |
|
675 | | - with FunctionTrace(name='Application', group='Python/WSGI'): |
| 678 | + with FunctionTrace(name="Application", group="Python/WSGI"): |
676 | 679 | with FunctionTrace(name=callable_name(wrapped), source=wrapped): |
677 | 680 | if settings and settings.browser_monitoring.enabled and not transaction.autorum_disabled: |
678 | 681 | result = _WSGIApplicationMiddleware(wrapped, environ, _start_response, transaction) |
|
0 commit comments