Skip to content

Commit

Permalink
Update attribute value
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
  • Loading branch information
pvaneck committed Apr 2, 2024
1 parent 51aad98 commit eeb848b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def __enter__(self) -> "OpenTelemetrySpan":
def __exit__(self, exception_type, exception_value, traceback) -> None:
# Finish the span.
if exception_type:
self.add_attribute(_ERROR_SPAN_ATTRIBUTE, str(exception_type.__name__))
module = exception_type.__module__ if exception_type.__module__ != "builtins" else ""
error_type = f"{module}.{exception_type.__qualname__}" if module else exception_type.__qualname__
self.add_attribute(_ERROR_SPAN_ATTRIBUTE, error_type)
if self._current_ctxt_manager:
self._current_ctxt_manager.__exit__(exception_type, exception_value, traceback) # pylint: disable=no-member
self._current_ctxt_manager = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import requests


from azure.core.exceptions import ClientAuthenticationError
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
from azure.core.tracing import SpanKind, AbstractSpan
from azure.core import __version__ as core_version
Expand Down Expand Up @@ -370,9 +371,19 @@ def test_span_kind(self, tracing_helper):
with pytest.raises(ValueError):
wrapped_class.kind = "somethingstuid"

def test_error_type_attribute(self, tracer):
with tracer.start_as_current_span("Root") as parent:
def test_error_type_attribute_builtin_error(self, tracing_helper):
with tracing_helper.tracer.start_as_current_span("Root") as parent:
with pytest.raises(ValueError):
with OpenTelemetrySpan() as wrapped_class:
raise ValueError("This is a test error")
assert wrapped_class.span_instance.attributes.get("error.type") == "ValueError"

def test_error_type_attribute_azure_error(self, tracing_helper):
with tracing_helper.tracer.start_as_current_span("Root") as parent:
with pytest.raises(ClientAuthenticationError):
with OpenTelemetrySpan() as wrapped_class:
raise ClientAuthenticationError("This is a test error")
assert (
wrapped_class.span_instance.attributes.get("error.type")
== "azure.core.exceptions.ClientAuthenticationError"
)

0 comments on commit eeb848b

Please sign in to comment.