5151 "false" : False ,
5252 "off" : False ,
5353}
54+
55+ global WAGTAIL_PAGE
5456WAGTAIL_PAGE = None
5557
5658
@@ -491,7 +493,8 @@ def wrapper(wrapped, instance, args, kwargs):
491493 # to override the priority set in other parts of this hook file so that the
492494 # more explicit name takes precedence.
493495 new_name = name
494- if WAGTAIL_PAGE and instance and isinstance (instance , Page ):
496+ global WAGTAIL_PAGE
497+ if WAGTAIL_PAGE and instance and isinstance (instance , WAGTAIL_PAGE ):
495498 new_name = f"{ callable_name (instance )} .{ wrapped .__name__ } "
496499 transaction .set_transaction_name (new_name , priority = 6 )
497500 else :
@@ -1224,6 +1227,21 @@ def _bind_params(original_middleware, *args, **kwargs):
12241227 return _nr_wrap_converted_middleware_ (converted_middleware , name )
12251228
12261229
1230+ def _nr_wrapper_route_for_request (wrapped , instance , args , kwargs ):
1231+ transaction = current_transaction ()
1232+
1233+ if not transaction :
1234+ return wrapped (* args , ** kwargs )
1235+
1236+ route_result = wrapped (* args , ** kwargs )
1237+ if route_result :
1238+ page , args , kwargs = route_result
1239+ name = callable_name (page .route )
1240+ transaction .set_transaction_name (name , priority = 6 )
1241+
1242+ return route_result
1243+
1244+
12271245def instrument_django_core_handlers_exception (module ):
12281246 if hasattr (module , "convert_exception_to_response" ):
12291247 wrap_function_wrapper (module , "convert_exception_to_response" , _nr_wrapper_convert_exception_to_response_ )
@@ -1242,6 +1260,10 @@ def instrument_django_core_handlers_asgi(module):
12421260
12431261 wrap_asgi_application (module , "ASGIHandler.__call__" , framework = framework )
12441262
1263+
12451264def instrument_wagtail_models_pages (module ):
1246- if hasattr (module , "Page" )
1265+ if hasattr (module , "Page" ):
1266+ global WAGTAIL_PAGE
12471267 WAGTAIL_PAGE = module .Page
1268+ if hasattr (module .Page , "route_for_request" ):
1269+ wrap_function_wrapper (module , "Page.route_for_request" , _nr_wrapper_route_for_request )
0 commit comments