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

Attempted to add traceback.format_exc() to solve issue with exceptions #3647

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
31 changes: 17 additions & 14 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,21 +962,24 @@ def __exit__(
exc_tb: Optional[TracebackType],
) -> None:
"""Ends context manager and calls `end` on the `Span`."""
if exc_val is not None and self.is_recording():
# Record the exception as an event
# pylint:disable=protected-access
if self._record_exception:
self.record_exception(exception=exc_val, escaped=True)
# Records status if span is used as context manager
# i.e. with tracer.start_span() as span:
if self._set_status_on_exception:
self.set_status(
Status(
status_code=StatusCode.ERROR,
description=f"{exc_type.__name__}: {exc_val}",
try:
if exc_val is not None and self.is_recording():
# Record the exception as an event
# pylint:disable=protected-access
if self._record_exception:
stacktrace = traceback.format_exc()
self.record_exception(exception=exc_val, escaped=True)
# Records status if span is used as context manager
# i.e. with tracer.start_span() as span:
if self._set_status_on_exception:
self.set_status(
Status(
status_code=StatusCode.ERROR,
description=f"{exc_type.__name__}: {exc_val}",
)
)
)

except Exception as record_exception_error:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just hiding any raised exception, how does this solve the issue?

pass
super().__exit__(exc_type, exc_val, exc_tb)
kennykguo marked this conversation as resolved.
Show resolved Hide resolved

def record_exception(
Expand Down
Loading