Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragile reporting for poorly implemented exceptions #2683

Open
gregbuehler opened this issue May 13, 2022 · 2 comments · May be fixed by #3647
Open

Fragile reporting for poorly implemented exceptions #2683

gregbuehler opened this issue May 13, 2022 · 2 comments · May be fixed by #3647
Assignees
Labels
bug Something isn't working

Comments

@gregbuehler
Copy link

gregbuehler commented May 13, 2022

Describe your environment
Python 3.9, Cornice 3.6, Pyramid 10.7

Steps to reproduce
Attempt to validate a request using an invalid json payload.

A more testable reproduction is raising an exception with a broken implementation of __str__.

class FooException(Exception):
  def __str__(self):
    return self.foo

What is the expected behavior?
The failure to parse the exception for its attributes results in a new uncaught exception.

What is the actual behavior?
Cornice creates a _JSONError exception (based on HttpException via HttpError) which manages to avoid setting the detail attribute. Since detail is assumed to exist for the implementation of Pyramid's HttpException.__str__() an AttributeError exception is thrown at https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L944.

File "/opt/foo/python/lib/python3.9/site-packages/opentelemetry/instrumentation/pyramid/callbacks.py", line 192, in trace_tween
    activation.__exit__(
  File "/opt/foo/python/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/opt/foo/python/lib/python3.9/site-packages/opentelemetry/trace/__init__.py", line 570, in use_span
    span.record_exception(exc)
  File "/opt/foo/python/lib/python3.9/site-packages/opentelemetry/sdk/trace/__init__.py", line 927, in record_exception
    "exception.message": str(exception),
  File "/opt/foo/python/lib/python3.9/site-packages/pyramid/httpexceptions.py", line 253, in __str__
    return str(self.detail) if self.detail else self.explanation
AttributeError: '_JSONError' object has no attribute 'detail'

Additional context
It seems gathering attributes should have a guard around it in the event the exception type has an unresolvable __str__ implementation. Maybe getting the stack using traceback.format_exc() could supplement the provided exception?

@gregbuehler gregbuehler added the bug Something isn't working label May 13, 2022
@kennykguo
Copy link

Hello, please assign this issue to me, thank you

@kennykguo
Copy link

kennykguo commented Jan 24, 2024

#main...kennykguo:opentelemetry-python:patch-1
I attempted to fix the issue here. Please verify if this is correct or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants