-
Notifications
You must be signed in to change notification settings - Fork 568
Description
Environment
How do you use Sentry?
Sentry SaaS (sentry.io)
Which SDK and version?
Python sentry-sdk==1.1.0
Steps to Reproduce
Use the python sentry sdk alongside the python NewRelic agent (newrelic-python-agent v6.4.4.161).
Wait for slow transaction traces to appear in NewRelic UI.
Expected Result
The middleware entries in transaction traces should show the names of the middlewares being wrapped.
Actual Result
All middlewares in transaction traces appear listed as sentry_sdk.integrations.django_middleware:_wrap_middleware.<locals>.SentryWrappingMiddleware, as shown in the screenshot below.

I've done some investigation, and the NewRelic agent determines the strings to be displayed
via a callable_name function, that bottoms out in a function called _object_context_py3. This function returns the module name (via object.__module__) and object.__qualname__ attributes of the passed object.
In the sentry_sdk.integrations.django.middleware._wrap_middleware function, the SentryWrappingMiddleware is given the wrapped middleware's __name__ attribute.
if hasattr(middleware, "__name__"):
SentryWrappingMiddleware.__name__ = middleware.__name__In the standard library's functools.wraps(), the wrapping entity is given ('__module__', '__name__', '__qualname__', '__doc__', '__annotations__') of the wrapped object. This implies it should be pretty safe to do the same with SentryWrappingMiddleware, like so:
if hasattr(middleware, "__name__"):
SentryWrappingMiddleware.__name__ = middleware.__name__
if hasattr(middleware, "__module__"):
SentryWrappingMiddleware.__module__ = middleware.__module__
if hasattr(middleware, "__qualname__"):
SentryWrappingMiddleware.__qualname__ = middleware.__qualname__or potentially
for attr in ('__name__', '__module__', '__qualname__', '__doc__', '__annotations__'):
if hasattr(middleware, attr):
setattr(SentryWrappingMiddleware, attr, getattr(middleware, attr))After manually making the first code change listed above, the results were what was expected:
