A subsequent exception is encountered when django instrumentation is handling the original exception
See original GitHub issueDescribe your environment opentelemetry-sdk==v0.16b1 opentelemetry-instrumentation==v0.16b1 opentelemetry-instrumentation-django==v0.16b1 opentelemetry-instrumentation-dbapi==v0.16b1 opentelemetry-instrumentation-requests==v0.16b1 opentelemetry-instrumentation-redis==v0.16b1 opentelemetry-instrumentation-celery==v0.16b1
Django==2.2.14
Note This issue is not present when running Django-3.1.5. Things seem to work as expected.
Steps to reproduce Make it so one of your views will always raise an Exception. Launch the server and then make a request to the views endpoint.
The raised exception will cause the following subsequent stack trace to occur:
Traceback (most recent call last):
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/stschenk/code/django-sandbox/mysite/polls/views.py", line 5, in index
raise Exception()
Exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 858, in _resolve_lookup
current = current()
TypeError: __call__() missing 1 required positional argument: 'func'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 125, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/views/debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/views/debug.py", line 334, in get_traceback_html
return t.render(c)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 987, in render
output = self.filter_expression.resolve(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 671, in resolve
obj = self.var.resolve(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 796, in resolve
value = self._resolve_lookup(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 861, in _resolve_lookup
getcallargs(current)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/inspect.py", line 1335, in getcallargs
f_name = func.__name__
AttributeError: '_GeneratorContextManager' object has no attribute '__name__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 858, in _resolve_lookup
current = current()
TypeError: __call__() missing 1 required positional argument: 'func'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/core/handlers/exception.py", line 125, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/views/debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/views/debug.py", line 334, in get_traceback_html
return t.render(c)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 987, in render
output = self.filter_expression.resolve(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 671, in resolve
obj = self.var.resolve(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 796, in resolve
value = self._resolve_lookup(context)
File "/Users/stschenk/.virtualenvs/django-sandbox/lib/python3.7/site-packages/django/template/base.py", line 861, in _resolve_lookup
getcallargs(current)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/inspect.py", line 1335, in getcallargs
f_name = func.__name__
AttributeError: '_GeneratorContextManager' object has no attribute '__name__'
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Django Exceptions
The SuspiciousOperation exception is raised when a user has performed an operation that should be considered suspicious from a security perspective, such as ......
Read more >Learning (not) to Handle Exceptions - Python for the Lab
We are going to cover from the basics of error handling to defining your own exceptions. You will learn why sometimes it is...
Read more >Exceptions - Django REST framework
You can implement custom exception handling by creating a handler function that converts exceptions raised in your API views into response objects. This...
Read more >Professional Error Handling With Python - Code
The call to open_db_connection() may not return a connection or raise an exception itself. In this case there is no need to close...
Read more >How to Define Custom Exception Classes in Python
The construction of custom exception classes can enrich our class design. A custom error class could logs errors, inspect an object. It is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The same error happened to me, using the following environment:
python==3.8.11
Django==2.0.13 opentelemetry-api==1.4.1 opentelemetry-sdk==1.4.1 opentelemetry-exporter-jaeger==1.4.1 opentelemetry-propagator-b3==1.4.1 opentelemetry-instrumentation-django==0.23b2 opentelemetry-instrumentation-logging==0.23b2 opentelemetry-instrumentation-requests==0.23b2 opentelemetry-instrumentation-sqlite3==0.23b2
Another workaround that worked for me:
Yeah, the stack trace is in common django code, but it is being caused by the contextmanager from Trace.use_span() not having a
__name__
property. I do not fully understand why or if the context manager really should have__name__
. But Django 2.2.14 is expecting to find it.I have worked around the issue by subclassing the otel middleware:
Hope this help.