open-telemetry / open-telemetry/opentelemetry-python-contrib

A subsequent exception is encountered when django instrumentation is handling the original exception

Open
#288 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog bug good first issue help wanted instrumentation
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe 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__'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with Django 2.2.14, the listed OpenTelemetry packages, and a view that always raises an exception. Start by tracing Django instrumentation while handling that view exception; done means the original exception is handled without the subsequent template or context-manager errors shown in the traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.