Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion newrelic/hooks/framework_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,21 @@ def wrapper(wrapped, instance, args, kwargs):
if transaction is None:
return wrapped(*args, **kwargs)

transaction.set_transaction_name(name, priority=priority)
# Wagtail is built on top of Django. It uses metaclasses where the route method
# is located on the base class which results in transaction having the same
# name. Use the child class instead of the base class name. Set the priority=6
# to override the priority set in other parts of this hook file so that the
# more explicit name takes precedence.
new_name = name
try:
from wagtail.models.pages import Page
except:
Page = None
if instance and isinstance(instance, Page):
new_name = f"{callable_name(instance)}.{wrapped.__name__}"
transaction.set_transaction_name(new_name, priority=6)
else:
transaction.set_transaction_name(new_name, priority=priority)
with FunctionTrace(name=name, source=wrapped):
try:
return wrapped(*args, **kwargs)
Expand Down
65 changes: 65 additions & 0 deletions newrelic/hooks/framework_wagtail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import functools
import logging
import sys
import threading
import warnings

from newrelic.api.application import register_application
from newrelic.api.background_task import BackgroundTaskWrapper
from newrelic.api.error_trace import wrap_error_trace
from newrelic.api.function_trace import FunctionTrace, FunctionTraceWrapper, wrap_function_trace
from newrelic.api.html_insertion import insert_html_snippet
from newrelic.api.time_trace import notice_error
from newrelic.api.transaction import current_transaction
from newrelic.api.transaction_name import wrap_transaction_name
from newrelic.api.wsgi_application import WSGIApplicationWrapper
from newrelic.common.coroutine import is_asyncio_coroutine, is_coroutine_function

Check failure on line 30 in newrelic/hooks/framework_wagtail.py

View workflow job for this annotation

GitHub Actions / MegaLinter

ruff (F821)

newrelic/hooks/framework_wagtail.py:30:19: F821 Undefined name `is_denied_middleware`
from newrelic.common.object_names import callable_name
from newrelic.common.object_wrapper import (
FunctionWrapper,
function_wrapper,
wrap_function_wrapper,
wrap_in_function,

Check failure on line 36 in newrelic/hooks/framework_wagtail.py

View workflow job for this annotation

GitHub Actions / MegaLinter

ruff (F821)

newrelic/hooks/framework_wagtail.py:36:20: F821 Undefined name `_nr_wrap_converted_middleware_async_`
wrap_post_function,

Check failure on line 37 in newrelic/hooks/framework_wagtail.py

View workflow job for this annotation

GitHub Actions / MegaLinter

ruff (F821)

newrelic/hooks/framework_wagtail.py:37:16: F821 Undefined name `_nr_wrap_converted_middleware_`
)
from newrelic.core.config import global_settings

_logger = logging.getLogger(__name__)

def _nr_wrapper_convert_exception_to_response_(wrapped, instance, args, kwargs):
def _bind_params(original_middleware, *args, **kwargs):
return original_middleware

Check failure on line 45 in newrelic/hooks/framework_wagtail.py

View workflow job for this annotation

GitHub Actions / MegaLinter

ruff (F821)

newrelic/hooks/framework_wagtail.py:45:44: F821 Undefined name `wrap_handle_uncaught_exception`

original_middleware = _bind_params(*args, **kwargs)
converted_middleware = wrapped(*args, **kwargs)
name = callable_name(original_middleware)
do_not_wrap = is_denied_middleware(name)

if do_not_wrap:
return converted_middleware
else:
if is_coroutine_function(converted_middleware) or is_asyncio_coroutine(converted_middleware):
return _nr_wrap_converted_middleware_async_(converted_middleware, name)
return _nr_wrap_converted_middleware_(converted_middleware, name)


def instrument_django_core_handlers_exception(module):
if hasattr(module, "convert_exception_to_response"):
wrap_function_wrapper(module, "convert_exception_to_response", _nr_wrapper_convert_exception_to_response_)

if hasattr(module, "handle_uncaught_exception"):
module.handle_uncaught_exception = wrap_handle_uncaught_exception(module.handle_uncaught_exception)
Loading