From 935280c3b8820351d9761c786148f1ff0e9b120d Mon Sep 17 00:00:00 2001 From: alrex Date: Fri, 24 Jul 2020 08:48:44 -0700 Subject: [PATCH] api/sdk: Rename record_error to record_exception per spec (#927) --- opentelemetry-api/CHANGELOG.md | 2 ++ .../src/opentelemetry/trace/span.py | 6 +++--- opentelemetry-sdk/CHANGELOG.md | 2 ++ .../src/opentelemetry/sdk/trace/__init__.py | 12 ++++++------ opentelemetry-sdk/tests/trace/test_trace.py | 19 ++++++++++++------- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/opentelemetry-api/CHANGELOG.md b/opentelemetry-api/CHANGELOG.md index 413946b85b9..d6348459917 100644 --- a/opentelemetry-api/CHANGELOG.md +++ b/opentelemetry-api/CHANGELOG.md @@ -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 diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index baea6670f63..d207ecf565b 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -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. @@ -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 diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 46ad8b8e29c..6427b2c9b51 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -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 diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 1118b424888..848f571e6a8 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -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(), }, ) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index a43db73a3da..02cc836e882 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -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"], )