Skip to content

Commit

Permalink
api/sdk: Rename record_error to record_exception per spec (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Jul 24, 2020
1 parent f2c6c85 commit 935280c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Return INVALID_SPAN if no TracerProvider set for get_current_span
([#751](https://github.com/open-telemetry/opentelemetry-python/pull/751))
- Rename record_error to record_exception
([#927](https://github.com/open-telemetry/opentelemetry-python/pull/927))

## 0.9b0

Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-api/src/opentelemetry/trace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def set_status(self, status: Status) -> None:
"""

@abc.abstractmethod
def record_error(self, err: Exception) -> None:
"""Records an error as a span event."""
def record_exception(self, exception: Exception) -> None:
"""Records an exception as a span event."""

def __enter__(self) -> "Span":
"""Invoked when `Span` is used as a context manager.
Expand Down Expand Up @@ -257,7 +257,7 @@ def update_name(self, name: str) -> None:
def set_status(self, status: Status) -> None:
pass

def record_error(self, err: Exception) -> None:
def record_exception(self, exception: Exception) -> None:
pass


Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Add support for resources and resource detector
([#853](https://github.com/open-telemetry/opentelemetry-python/pull/853))
- Rename record_error to record_exception
([#927](https://github.com/open-telemetry/opentelemetry-python/pull/927))

## Version 0.10b0

Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,14 @@ def __exit__(

super().__exit__(exc_type, exc_val, exc_tb)

def record_error(self, err: Exception) -> None:
"""Records an error as a span event."""
def record_exception(self, exception: Exception) -> None:
"""Records an exception as a span event."""
self.add_event(
name="error",
name="exception",
attributes={
"error.type": err.__class__.__name__,
"error.message": str(err),
"error.stack": traceback.format_exc(),
"exception.type": exception.__class__.__name__,
"exception.message": str(exception),
"exception.stacktrace": traceback.format_exc(),
},
)

Expand Down
19 changes: 12 additions & 7 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,18 +801,23 @@ def error_status_test(context):
.start_as_current_span("root")
)

def test_record_error(self):
def test_record_exception(self):
span = trace.Span("name", mock.Mock(spec=trace_api.SpanContext))
try:
raise ValueError("invalid")
except ValueError as err:
span.record_error(err)
error_event = span.events[0]
self.assertEqual("error", error_event.name)
self.assertEqual("invalid", error_event.attributes["error.message"])
self.assertEqual("ValueError", error_event.attributes["error.type"])
span.record_exception(err)
exception_event = span.events[0]
self.assertEqual("exception", exception_event.name)
self.assertEqual(
"invalid", exception_event.attributes["exception.message"]
)
self.assertEqual(
"ValueError", exception_event.attributes["exception.type"]
)
self.assertIn(
"ValueError: invalid", error_event.attributes["error.stack"]
"ValueError: invalid",
exception_event.attributes["exception.stacktrace"],
)


Expand Down

0 comments on commit 935280c

Please sign in to comment.