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

Add is_recording for exception recording #1386

Merged
merged 2 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions opentelemetry-api/src/opentelemetry/trace/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
logger = logging.getLogger(__name__)


EXCEPTION_STATUS_FIELD = "_otel_status_code"


class StatusCode(enum.Enum):
"""Represents the canonical set of status codes of a finished Span."""

Expand Down
10 changes: 3 additions & 7 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanContext
from opentelemetry.trace.propagation import SPAN_KEY
from opentelemetry.trace.status import (
EXCEPTION_STATUS_FIELD,
Status,
StatusCode,
)
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.util import time_ns, types

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -666,7 +662,7 @@ def __exit__(
exc_tb: Optional[TracebackType],
) -> None:
"""Ends context manager and calls `end` on the `Span`."""
if exc_val is not None:
if exc_val is not None and self.is_recording():
# Record the exception as an event
# pylint:disable=protected-access
if self._record_exception:
Expand Down Expand Up @@ -857,7 +853,7 @@ def use_span(

except Exception as exc: # pylint: disable=broad-except
# Record the exception as an event
if isinstance(span, Span):
if isinstance(span, Span) and span.is_recording():
# pylint:disable=protected-access
if span._record_exception:
span.record_exception(exc)
Expand Down