From f3cdfa2cdb9cb1c442189e2ead3788f45d92352d Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Wed, 28 Oct 2020 17:28:58 -0400 Subject: [PATCH] Change status codes from grpc status codes, remove setting status in instrumentations except on ERROR (#1282) --- docs/examples/auto-instrumentation/README.rst | 4 +- docs/examples/django/README.rst | 2 +- docs/getting-started.rst | 6 +- .../exporter/datadog/exporter.py | 3 +- .../opentelemetry/exporter/jaeger/__init__.py | 6 +- .../tests/test_jaeger_exporter.py | 13 +- .../opencensus/trace_exporter/__init__.py | 2 +- .../tests/test_otcollector_trace_exporter.py | 10 +- .../exporter/otlp/trace_exporter/__init__.py | 8 +- .../opentelemetry/exporter/zipkin/__init__.py | 2 +- .../tests/test_zipkin_exporter.py | 16 +- .../aiohttp_client/__init__.py | 26 +-- .../tests/test_aiohttp_client_integration.py | 27 ++-- .../aiopg/aiopg_integration.py | 8 +- .../tests/test_aiopg_integration.py | 6 +- .../instrumentation/asgi/__init__.py | 8 +- .../instrumentation/asyncpg/__init__.py | 21 +-- .../instrumentation/celery/__init__.py | 5 +- .../instrumentation/dbapi/__init__.py | 8 +- .../tests/test_dbapi_integration.py | 6 +- .../tests/test_middleware.py | 12 +- .../instrumentation/elasticsearch/__init__.py | 8 +- .../tests/test_elasticsearch.py | 8 +- .../instrumentation/falcon/__init__.py | 4 +- .../tests/test_falcon.py | 12 +- .../instrumentation/grpc/_client.py | 16 +- .../tests/test_client_interceptor.py | 20 +-- .../instrumentation/jinja2/__init__.py | 2 +- .../tests/test_pymemcache.py | 15 +- .../instrumentation/pymongo/__init__.py | 12 +- .../tests/test_pymongo.py | 12 +- .../instrumentation/requests/__init__.py | 23 +-- .../tests/test_requests_integration.py | 29 +--- .../instrumentation/sqlalchemy/engine.py | 7 +- .../instrumentation/tornado/__init__.py | 4 +- .../instrumentation/tornado/client.py | 4 +- .../instrumentation/wsgi/__init__.py | 10 +- .../tests/test_wsgi_middleware.py | 4 +- opentelemetry-api/CHANGELOG.md | 2 + .../src/opentelemetry/trace/__init__.py | 4 +- .../src/opentelemetry/trace/status.py | 152 ++---------------- opentelemetry-api/tests/trace/test_status.py | 10 +- .../opentelemetry/instrumentation/utils.py | 35 ++-- .../tests/test_utils.py | 53 +++--- opentelemetry-sdk/CHANGELOG.md | 1 + .../src/opentelemetry/sdk/trace/__init__.py | 28 ++-- opentelemetry-sdk/tests/trace/test_trace.py | 38 +++-- .../tests/asyncpg/test_asyncpg_functional.py | 37 ++--- .../tests/celery/test_celery_functional.py | 12 +- .../tests/redis/test_redis_functional.py | 4 +- .../tests/sqlalchemy_tests/mixins.py | 4 +- .../tests/sqlalchemy_tests/test_instrument.py | 4 +- .../tests/sqlalchemy_tests/test_mysql.py | 3 +- .../tests/sqlalchemy_tests/test_postgres.py | 3 +- .../tests/sqlalchemy_tests/test_sqlite.py | 3 +- 55 files changed, 265 insertions(+), 517 deletions(-) diff --git a/docs/examples/auto-instrumentation/README.rst b/docs/examples/auto-instrumentation/README.rst index e4af3c6bd56..a023acaa940 100644 --- a/docs/examples/auto-instrumentation/README.rst +++ b/docs/examples/auto-instrumentation/README.rst @@ -112,7 +112,7 @@ similar to: "start_time": "2020-04-30T17:28:57.886397Z", "end_time": "2020-04-30T17:28:57.886490Z", "status": { - "canonical_code": "OK" + "status_code": "OK" }, "attributes": { "component": "http", @@ -164,7 +164,7 @@ similar to: "start_time": "2020-04-30T17:10:02.400604Z", "end_time": "2020-04-30T17:10:02.401858Z", "status": { - "canonical_code": "OK" + "status_code": "OK" }, "attributes": { "component": "http", diff --git a/docs/examples/django/README.rst b/docs/examples/django/README.rst index 6f40cf7aeba..64ff0b32cfa 100644 --- a/docs/examples/django/README.rst +++ b/docs/examples/django/README.rst @@ -77,7 +77,7 @@ output similar to this one: "start_time": "2020-04-26T01:49:57.205833Z", "end_time": "2020-04-26T01:49:57.206214Z", "status": { - "canonical_code": "OK" + "status_code": "OK" }, "attributes": { "component": "http", diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 213989fbe56..49d1ad3ee21 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -49,7 +49,7 @@ We can run it, and see the traces print to your console: "start_time": "2020-05-07T14:39:52.906272Z", "end_time": "2020-05-07T14:39:52.906343Z", "status": { - "canonical_code": "OK" + "status_code": "OK" }, "attributes": {}, "events": [], @@ -67,7 +67,7 @@ We can run it, and see the traces print to your console: "start_time": "2020-05-07T14:39:52.906230Z", "end_time": "2020-05-07T14:39:52.906601Z", "status": { - "canonical_code": "OK" + "status_code": "OK" }, "attributes": {}, "events": [], @@ -85,7 +85,7 @@ We can run it, and see the traces print to your console: "start_time": "2020-05-07T14:39:52.906157Z", "end_time": "2020-05-07T14:39:52.906743Z", "status": { - "canonical_code": "OK" + "status_code": "OK" }, "attributes": {}, "events": [], diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py index 36335c23588..2b1bd900417 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py @@ -23,7 +23,6 @@ import opentelemetry.trace as trace_api from opentelemetry.sdk.trace import sampling from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult -from opentelemetry.trace.status import StatusCanonicalCode # pylint:disable=relative-beyond-top-level from .constants import ( @@ -145,7 +144,7 @@ def _translate_to_datadog(self, spans): datadog_span.start_ns = span.start_time datadog_span.duration_ns = span.end_time - span.start_time - if span.status.canonical_code is not StatusCanonicalCode.OK: + if not span.status.is_ok: datadog_span.error = 1 if span.status.description: exc_type, exc_val = _get_exc_info(span) diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py index 7c6d8bd679f..3271fdd5ba6 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py @@ -70,7 +70,7 @@ from opentelemetry.exporter.jaeger.gen.agent import Agent as agent from opentelemetry.exporter.jaeger.gen.jaeger import Collector as jaeger from opentelemetry.sdk.trace.export import Span, SpanExporter, SpanExportResult -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode DEFAULT_AGENT_HOST_NAME = "localhost" DEFAULT_AGENT_PORT = 6831 @@ -224,7 +224,7 @@ def _translate_to_jaeger(spans: Span): tags.extend( [ - _get_long_tag("status.code", status.canonical_code.value), + _get_long_tag("status.code", status.status_code.value), _get_string_tag("status.message", status.description), _get_string_tag("span.kind", span.kind.name), ] @@ -245,7 +245,7 @@ def _translate_to_jaeger(spans: Span): ) # Ensure that if Status.Code is not OK, that we set the "error" tag on the Jaeger span. - if status.canonical_code is not StatusCanonicalCode.OK: + if not status.is_ok: tags.append(_get_bool_tag("error", True)) refs = _extract_refs_from_span(span) diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py index 3daeacb7fd3..23afdefd78e 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py @@ -25,7 +25,7 @@ from opentelemetry.sdk import trace from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode class TestJaegerSpanExporter(unittest.TestCase): @@ -210,7 +210,7 @@ def test_translate_to_jaeger(self): jaeger.Tag( key="status.code", vType=jaeger.TagType.LONG, - vLong=StatusCanonicalCode.OK.value, + vLong=StatusCode.UNSET.value, ), jaeger.Tag( key="status.message", vType=jaeger.TagType.STRING, vStr=None @@ -249,7 +249,7 @@ def test_translate_to_jaeger(self): attributes={"key_resource": "some_resource"} ) otel_spans[0].set_status( - Status(StatusCanonicalCode.UNKNOWN, "Example description") + Status(StatusCode.ERROR, "Example description") ) otel_spans[0].end(end_time=end_times[0]) @@ -259,6 +259,7 @@ def test_translate_to_jaeger(self): otel_spans[2].start(start_time=start_times[2]) otel_spans[2].resource = Resource({}) + otel_spans[2].set_status(Status(StatusCode.OK, "Example description")) otel_spans[2].end(end_time=end_times[2]) otel_spans[2].instrumentation_info = InstrumentationInfo( name="name", version="version" @@ -304,7 +305,7 @@ def test_translate_to_jaeger(self): jaeger.Tag( key="status.code", vType=jaeger.TagType.LONG, - vLong=StatusCanonicalCode.UNKNOWN.value, + vLong=StatusCode.ERROR.value, ), jaeger.Tag( key="status.message", @@ -380,12 +381,12 @@ def test_translate_to_jaeger(self): jaeger.Tag( key="status.code", vType=jaeger.TagType.LONG, - vLong=StatusCanonicalCode.OK.value, + vLong=StatusCode.OK.value, ), jaeger.Tag( key="status.message", vType=jaeger.TagType.STRING, - vStr=None, + vStr="Example description", ), jaeger.Tag( key="span.kind", diff --git a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py index e5eb4eaf770..613ee6482ba 100644 --- a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py @@ -93,7 +93,7 @@ def translate_to_collector(spans: Sequence[Span]): status = None if span.status is not None: status = trace_pb2.Status( - code=span.status.canonical_code.value, + code=span.status.status_code.value, message=span.status.description, ) diff --git a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py index c49310b30a6..b61cf333cc8 100644 --- a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py +++ b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py @@ -148,15 +148,14 @@ def test_translate_to_collector(self): otel_spans[0].set_attribute("key_int", 333) otel_spans[0].set_status( trace_api.Status( - trace_api.status.StatusCanonicalCode.INTERNAL, - "test description", + trace_api.status.StatusCode.OK, "test description", ) ) otel_spans[0].end(end_time=end_times[0]) otel_spans[1].start(start_time=start_times[1]) otel_spans[1].set_status( trace_api.Status( - trace_api.status.StatusCanonicalCode.INTERNAL, {"test", "val"}, + trace_api.status.StatusCode.ERROR, {"test", "val"}, ) ) otel_spans[1].end(end_time=end_times[1]) @@ -197,8 +196,7 @@ def test_translate_to_collector(self): output_spans[2].parent_span_id, b"\x11\x11\x11\x11\x11\x11\x11\x11" ) self.assertEqual( - output_spans[0].status.code, - trace_api.status.StatusCanonicalCode.INTERNAL.value, + output_spans[0].status.code, trace_api.status.StatusCode.OK.value, ) self.assertEqual(output_spans[0].status.message, "test description") self.assertEqual(len(output_spans[0].tracestate.entries), 1) @@ -270,7 +268,7 @@ def test_translate_to_collector(self): ) self.assertEqual( output_spans[1].status.code, - trace_api.status.StatusCanonicalCode.INTERNAL.value, + trace_api.status.StatusCode.ERROR.value, ) self.assertEqual( output_spans[2].links.link[0].type, diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py index 8acd2dea55a..870e8fab0f7 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py @@ -41,6 +41,7 @@ from opentelemetry.proto.trace.v1.trace_pb2 import Status from opentelemetry.sdk.trace import Span as SDKSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult +from opentelemetry.trace.status import StatusCode logger = logging.getLogger(__name__) @@ -198,9 +199,12 @@ def _translate_links(self, sdk_span: SDKSpan) -> None: def _translate_status(self, sdk_span: SDKSpan) -> None: if sdk_span.status is not None: + # TODO: Update this when the proto definitions are updated to include UNSET and ERROR + proto_status_code = Status.STATUS_CODE_OK + if sdk_span.status.status_code is StatusCode.ERROR: + proto_status_code = Status.STATUS_CODE_UNKNOWN_ERROR self._collector_span_kwargs["status"] = Status( - code=sdk_span.status.canonical_code.value, - message=sdk_span.status.description, + code=proto_status_code, message=sdk_span.status.description, ) def _translate_data( diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index c8578c9649c..bd3cdbb26af 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -193,7 +193,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]): if span.status is not None: zipkin_span["tags"]["otel.status_code"] = str( - span.status.canonical_code.value + span.status.status_code.value ) if span.status.description is not None: zipkin_span["tags"][ diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index c3098da8847..12d85a0dc45 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -24,7 +24,7 @@ from opentelemetry.sdk.trace.export import SpanExportResult from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace import TraceFlags -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode class MockResponse: @@ -179,7 +179,7 @@ def test_export(self): otel_spans[0].set_attribute("key_string", "hello_world") otel_spans[0].set_attribute("key_float", 111.22) otel_spans[0].set_status( - Status(StatusCanonicalCode.UNKNOWN, "Example description") + Status(StatusCode.ERROR, "Example description") ) otel_spans[0].end(end_time=end_times[0]) @@ -248,7 +248,7 @@ def test_export(self): "kind": None, "tags": { "key_resource": "some_resource", - "otel.status_code": "0", + "otel.status_code": "1", }, "annotations": None, }, @@ -263,7 +263,7 @@ def test_export(self): "tags": { "key_string": "hello_world", "key_resource": "some_resource", - "otel.status_code": "0", + "otel.status_code": "1", }, "annotations": None, }, @@ -278,7 +278,7 @@ def test_export(self): "tags": { "otel.instrumentation_library.name": "name", "otel.instrumentation_library.version": "version", - "otel.status_code": "0", + "otel.status_code": "1", }, "annotations": None, }, @@ -356,7 +356,7 @@ def test_zero_padding(self): "duration": duration // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": {"otel.status_code": "0"}, + "tags": {"otel.status_code": "1"}, "annotations": None, "debug": True, "parentId": "0aaaaaaaaaaaaaaa", @@ -400,9 +400,7 @@ def test_max_tag_length(self): # added here to preserve order span.set_attribute("k1", "v" * 500) span.set_attribute("k2", "v" * 50) - span.set_status( - Status(StatusCanonicalCode.UNKNOWN, "Example description") - ) + span.set_status(Status(StatusCode.ERROR, "Example description")) span.end() exporter = ZipkinSpanExporter(service_name) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py index 6606c483314..c708802a926 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py @@ -74,11 +74,11 @@ def strip_query_params(url: yarl.URL) -> str: from opentelemetry.instrumentation.aiohttp_client.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import ( - http_status_to_canonical_code, + http_status_to_status_code, unwrap, ) from opentelemetry.trace import SpanKind, TracerProvider, get_tracer -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode _UrlFilterT = typing.Optional[typing.Callable[[str], str]] _SpanNameT = typing.Optional[ @@ -194,9 +194,7 @@ async def on_request_end( if trace_config_ctx.span.is_recording(): trace_config_ctx.span.set_status( - Status( - http_status_to_canonical_code(int(params.response.status)) - ) + Status(http_status_to_status_code(int(params.response.status))) ) trace_config_ctx.span.set_attribute( "http.status_code", params.response.status @@ -214,22 +212,8 @@ async def on_request_exception( if trace_config_ctx.span is None: return - if trace_config_ctx.span.is_recording(): - if isinstance( - params.exception, - (aiohttp.ServerTimeoutError, aiohttp.TooManyRedirects), - ): - status = StatusCanonicalCode.DEADLINE_EXCEEDED - # Assume any getaddrinfo error is a DNS failure. - elif isinstance( - params.exception, aiohttp.ClientConnectorError - ) and isinstance(params.exception.os_error, socket.gaierror): - # DNS resolution failed - status = StatusCanonicalCode.UNKNOWN - else: - status = StatusCanonicalCode.UNAVAILABLE - - trace_config_ctx.span.set_status(Status(status)) + if trace_config_ctx.span.is_recording() and params.exception: + trace_config_ctx.span.set_status(Status(StatusCode.ERROR)) trace_config_ctx.span.record_exception(params.exception) _end_trace(trace_config_ctx) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index fb5b6aac6ae..f0734653488 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -31,7 +31,7 @@ AioHttpClientInstrumentor, ) from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode def run_with_test_server( @@ -61,7 +61,7 @@ def assert_spans(self, spans): [ ( span.name, - (span.status.canonical_code, span.status.description), + (span.status.status_code, span.status.description), dict(span.attributes), ) for span in self.memory_exporter.get_finished_spans() @@ -111,13 +111,10 @@ async def client_request(server: aiohttp.test_utils.TestServer): def test_status_codes(self): for status_code, span_status in ( - (HTTPStatus.OK, StatusCanonicalCode.OK), - (HTTPStatus.TEMPORARY_REDIRECT, StatusCanonicalCode.OK), - (HTTPStatus.SERVICE_UNAVAILABLE, StatusCanonicalCode.UNAVAILABLE), - ( - HTTPStatus.GATEWAY_TIMEOUT, - StatusCanonicalCode.DEADLINE_EXCEEDED, - ), + (HTTPStatus.OK, StatusCode.UNSET), + (HTTPStatus.TEMPORARY_REDIRECT, StatusCode.UNSET), + (HTTPStatus.SERVICE_UNAVAILABLE, StatusCode.ERROR), + (HTTPStatus.GATEWAY_TIMEOUT, StatusCode.ERROR,), ): with self.subTest(status_code=status_code): host, port = self._http_request( @@ -188,7 +185,7 @@ def test_span_name_option(self): [ ( expected, - (StatusCanonicalCode.OK, None), + (StatusCode.UNSET, None), { "component": "http", "http.method": method, @@ -220,7 +217,7 @@ def strip_query_params(url: yarl.URL) -> str: [ ( "HTTP GET", - (StatusCanonicalCode.OK, None), + (StatusCode.UNSET, None), { "component": "http", "http.method": "GET", @@ -238,8 +235,8 @@ def test_connection_errors(self): trace_configs = [aiohttp_client.create_trace_config()] for url, expected_status in ( - ("http://this-is-unknown.local/", StatusCanonicalCode.UNKNOWN), - ("http://127.0.0.1:1/", StatusCanonicalCode.UNAVAILABLE), + ("http://this-is-unknown.local/", StatusCode.ERROR), + ("http://127.0.0.1:1/", StatusCode.ERROR), ): with self.subTest(expected_status=expected_status): @@ -286,7 +283,7 @@ async def request_handler(request): [ ( "HTTP GET", - (StatusCanonicalCode.DEADLINE_EXCEEDED, None), + (StatusCode.ERROR, None), { "component": "http", "http.method": "GET", @@ -316,7 +313,7 @@ async def request_handler(request): [ ( "HTTP GET", - (StatusCanonicalCode.DEADLINE_EXCEEDED, None), + (StatusCode.ERROR, None), { "component": "http", "http.method": "GET", diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py index 1455f23e629..14f986da065 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py @@ -8,7 +8,7 @@ TracedCursor, ) from opentelemetry.trace import SpanKind -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode # pylint: disable=abstract-method @@ -108,14 +108,10 @@ async def traced_execution( self._populate_span(span, *args) try: result = await query_method(*args, **kwargs) - if span.is_recording(): - span.set_status(Status(StatusCanonicalCode.OK)) return result except Exception as ex: # pylint: disable=broad-except if span.is_recording(): - span.set_status( - Status(StatusCanonicalCode.UNKNOWN, str(ex)) - ) + span.set_status(Status(StatusCode.ERROR, str(ex))) raise ex diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py index 135f9ee9a78..78ea4552e23 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py @@ -226,8 +226,7 @@ def test_span_succeeded(self): self.assertEqual(span.attributes["net.peer.name"], "testhost") self.assertEqual(span.attributes["net.peer.port"], 123) self.assertIs( - span.status.canonical_code, - trace_api.status.StatusCanonicalCode.OK, + span.status.status_code, trace_api.status.StatusCode.UNSET, ) def test_span_not_recording(self): @@ -278,8 +277,7 @@ def test_span_failed(self): span = spans_list[0] self.assertEqual(span.attributes["db.statement"], "Test query") self.assertIs( - span.status.canonical_code, - trace_api.status.StatusCanonicalCode.UNKNOWN, + span.status.status_code, trace_api.status.StatusCode.ERROR, ) self.assertEqual(span.status.description, "Test Exception") diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 879662ddcfb..1a0bb47a644 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -28,8 +28,8 @@ from opentelemetry import context, propagators, trace from opentelemetry.instrumentation.asgi.version import __version__ # noqa -from opentelemetry.instrumentation.utils import http_status_to_canonical_code -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.instrumentation.utils import http_status_to_status_code +from opentelemetry.trace.status import Status, StatusCode def get_header_from_scope(scope: dict, header_name: str) -> typing.List[str]: @@ -98,13 +98,13 @@ def set_status_code(span, status_code): except ValueError: span.set_status( Status( - StatusCanonicalCode.UNKNOWN, + StatusCode.ERROR, "Non-integer HTTP status: " + repr(status_code), ) ) else: span.set_attribute("http.status_code", status_code) - span.set_status(Status(http_status_to_canonical_code(status_code))) + span.set_status(Status(http_status_to_status_code(status_code))) def get_default_span_details(scope: dict) -> Tuple[str, dict]: diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py index 6af816b39df..2f4ecaf3af6 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py @@ -43,21 +43,11 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap from opentelemetry.trace import SpanKind -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode _APPLIED = "_opentelemetry_tracer" -def _exception_to_canonical_code(exc: Exception) -> StatusCanonicalCode: - if isinstance( - exc, (exceptions.InterfaceError, exceptions.SyntaxOrAccessError), - ): - return StatusCanonicalCode.INVALID_ARGUMENT - if isinstance(exc, exceptions.IdleInTransactionSessionTimeoutError): - return StatusCanonicalCode.DEADLINE_EXCEEDED - return StatusCanonicalCode.UNKNOWN - - def _hydrate_span_from_args(connection, query, parameters) -> dict: span_attributes = {"db.type": "sql"} @@ -134,12 +124,7 @@ async def _do_execute(self, func, instance, args, kwargs): exception = exc raise finally: - if span.is_recording(): - if exception is not None: - span.set_status( - Status(_exception_to_canonical_code(exception)) - ) - else: - span.set_status(Status(StatusCanonicalCode.OK)) + if span.is_recording() and exception is not None: + span.set_status(Status(StatusCode.ERROR)) return result diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index ab0cdf39b10..a5897f8b6e5 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -68,7 +68,7 @@ def add(x, y): from opentelemetry.instrumentation.celery.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.trace.propagation import get_current_span -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode logger = logging.getLogger(__name__) @@ -214,7 +214,7 @@ def _trace_failure(*args, **kwargs): if span is None or not span.is_recording(): return - status_kwargs = {"canonical_code": StatusCanonicalCode.UNKNOWN} + status_kwargs = {"status_code": StatusCode.ERROR} ex = kwargs.get("einfo") @@ -227,7 +227,6 @@ def _trace_failure(*args, **kwargs): if ex is not None: status_kwargs["description"] = str(ex) - span.set_status(Status(**status_kwargs)) @staticmethod diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py index 0dcdd5ba606..0047ab18517 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -50,7 +50,7 @@ from opentelemetry.instrumentation.dbapi.version import __version__ from opentelemetry.instrumentation.utils import unwrap from opentelemetry.trace import SpanKind, TracerProvider, get_tracer -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode logger = logging.getLogger(__name__) @@ -343,14 +343,10 @@ def traced_execution( self._populate_span(span, *args) try: result = query_method(*args, **kwargs) - if span.is_recording(): - span.set_status(Status(StatusCanonicalCode.OK)) return result except Exception as ex: # pylint: disable=broad-except if span.is_recording(): - span.set_status( - Status(StatusCanonicalCode.UNKNOWN, str(ex)) - ) + span.set_status(Status(StatusCode.ERROR, str(ex))) raise ex diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py index e342e15aa34..f2abb8b6dca 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py @@ -65,8 +65,7 @@ def test_span_succeeded(self): self.assertEqual(span.attributes["net.peer.name"], "testhost") self.assertEqual(span.attributes["net.peer.port"], 123) self.assertIs( - span.status.canonical_code, - trace_api.status.StatusCanonicalCode.OK, + span.status.status_code, trace_api.status.StatusCode.UNSET, ) def test_span_not_recording(self): @@ -117,8 +116,7 @@ def test_span_failed(self): span = spans_list[0] self.assertEqual(span.attributes["db.statement"], "Test query") self.assertIs( - span.status.canonical_code, - trace_api.status.StatusCanonicalCode.UNKNOWN, + span.status.status_code, trace_api.status.StatusCode.ERROR, ) self.assertEqual(span.status.description, "Test Exception") diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index 4aa794f0de2..d087dc2d9d1 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -27,7 +27,7 @@ from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase from opentelemetry.trace import SpanKind -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode from opentelemetry.util import ExcludeList # pylint: disable=import-error @@ -87,7 +87,7 @@ def test_templated_route_get(self): else "tests.views.traced", ) self.assertEqual(span.kind, SpanKind.SERVER) - self.assertEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertEqual(span.status.status_code, StatusCode.UNSET) self.assertEqual(span.attributes["http.method"], "GET") self.assertEqual( span.attributes["http.url"], @@ -113,7 +113,7 @@ def test_traced_get(self): span.name, "^traced/" if DJANGO_2_2 else "tests.views.traced" ) self.assertEqual(span.kind, SpanKind.SERVER) - self.assertEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertEqual(span.status.status_code, StatusCode.UNSET) self.assertEqual(span.attributes["http.method"], "GET") self.assertEqual( span.attributes["http.url"], "http://testserver/traced/" @@ -170,7 +170,7 @@ def test_traced_post(self): span.name, "^traced/" if DJANGO_2_2 else "tests.views.traced" ) self.assertEqual(span.kind, SpanKind.SERVER) - self.assertEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertEqual(span.status.status_code, StatusCode.UNSET) self.assertEqual(span.attributes["http.method"], "POST") self.assertEqual( span.attributes["http.url"], "http://testserver/traced/" @@ -193,9 +193,7 @@ def test_error(self): span.name, "^error/" if DJANGO_2_2 else "tests.views.error" ) self.assertEqual(span.kind, SpanKind.SERVER) - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.INTERNAL - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) self.assertEqual(span.attributes["http.method"], "GET") self.assertEqual( span.attributes["http.url"], "http://testserver/error/" diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py index 6e9f411f8a4..541cdbfa6e3 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py @@ -64,7 +64,7 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap from opentelemetry.trace import SpanKind, get_tracer -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode logger = getLogger(__name__) @@ -156,11 +156,7 @@ def wrapper(wrapped, _, args, kwargs): return rv except Exception as ex: # pylint: disable=broad-except if span.is_recording(): - if isinstance(ex, elasticsearch.exceptions.NotFoundError): - status = StatusCanonicalCode.NOT_FOUND - else: - status = StatusCanonicalCode.UNKNOWN - span.set_status(Status(status, str(ex))) + span.set_status(Status(StatusCode.ERROR, str(ex))) raise ex return wrapper diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 3d93838fe81..ea0e6ce2fbf 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -27,7 +27,7 @@ ElasticsearchInstrumentor, ) from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode major_version = elasticsearch.VERSION[0] @@ -153,14 +153,14 @@ def test_result_values(self, request_mock): def test_trace_error_unknown(self, request_mock): exc = RuntimeError("custom error") request_mock.side_effect = exc - self._test_trace_error(StatusCanonicalCode.UNKNOWN, exc) + self._test_trace_error(StatusCode.ERROR, exc) def test_trace_error_not_found(self, request_mock): msg = "record not found" exc = elasticsearch.exceptions.NotFoundError(404, msg) request_mock.return_value = (1, {}, {}) request_mock.side_effect = exc - self._test_trace_error(StatusCanonicalCode.NOT_FOUND, exc) + self._test_trace_error(StatusCode.ERROR, exc) def _test_trace_error(self, code, exc): es = Elasticsearch() @@ -173,7 +173,7 @@ def _test_trace_error(self, code, exc): self.assertEqual(1, len(spans)) span = spans[0] self.assertFalse(span.status.is_ok) - self.assertEqual(span.status.canonical_code, code) + self.assertEqual(span.status.status_code, code) self.assertEqual(span.status.description, str(exc)) def test_parent(self, request_mock): diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index 0a93fe01388..66e6563dfff 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -55,7 +55,7 @@ def on_get(self, req, resp): from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import ( extract_attributes_from_object, - http_status_to_canonical_code, + http_status_to_status_code, ) from opentelemetry.trace.status import Status from opentelemetry.util import ExcludeList, time_ns @@ -216,7 +216,7 @@ def process_response( span.set_attribute("http.status_code", status_code) span.set_status( Status( - canonical_code=http_status_to_canonical_code(status_code), + status_code=http_status_to_status_code(status_code), description=reason, ) ) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index d64154a7770..fe33a2f2dd1 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -18,7 +18,7 @@ from opentelemetry.instrumentation.falcon import FalconInstrumentor from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode from opentelemetry.util import ExcludeList from .app import make_app @@ -64,7 +64,7 @@ def _test_method(self, method): self.assertEqual( span.name, "HelloWorldResource.on_{0}".format(method.lower()) ) - self.assertEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertEqual(span.status.status_code, StatusCode.UNSET) self.assert_span_has_attributes( span, { @@ -91,9 +91,7 @@ def test_404(self): self.assertEqual(len(spans), 1) span = spans[0] self.assertEqual(span.name, "HTTP GET") - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.NOT_FOUND - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) self.assert_span_has_attributes( span, { @@ -122,9 +120,7 @@ def test_500(self): span = spans[0] self.assertEqual(span.name, "ErrorResource.on_get") self.assertFalse(span.status.is_ok) - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.INTERNAL - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) self.assertEqual( span.status.description, "NameError: name 'non_existent_var' is not defined", diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py index 028804f599c..f8a72931f90 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_client.py @@ -26,7 +26,7 @@ from opentelemetry import metrics, propagators, trace from opentelemetry.sdk.metrics.export.controller import PushController -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode from . import grpcext from ._utilities import RpcInfo, TimedMetricRecorder @@ -169,9 +169,9 @@ def intercept_unary(self, request, metadata, client_info, invoker): try: result = invoker(request, metadata) - except grpc.RpcError as exc: + except grpc.RpcError: guarded_span.generated_span.set_status( - Status(StatusCanonicalCode(exc.code().value[0])) + Status(StatusCode.ERROR) ) raise @@ -224,10 +224,8 @@ def _intercept_server_stream( response.ByteSize(), client_info.full_method ) yield response - except grpc.RpcError as exc: - span.set_status( - Status(StatusCanonicalCode(exc.code().value[0])) - ) + except grpc.RpcError: + span.set_status(Status(StatusCode.ERROR)) raise def intercept_stream( @@ -264,9 +262,9 @@ def intercept_stream( try: result = invoker(request_or_iterator, metadata) - except grpc.RpcError as exc: + except grpc.RpcError: guarded_span.generated_span.set_status( - Status(StatusCanonicalCode(exc.code().value[0])) + Status(StatusCode.ERROR) ) raise diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py index 3ed40c141c8..f351c6fdd46 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py @@ -220,9 +220,8 @@ def test_error_simple(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) span = spans[0] - self.assertEqual( - span.status.canonical_code.value, - grpc.StatusCode.INVALID_ARGUMENT.value[0], + self.assertIs( + span.status.status_code, trace.status.StatusCode.ERROR, ) def test_error_stream_unary(self): @@ -233,9 +232,8 @@ def test_error_stream_unary(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) span = spans[0] - self.assertEqual( - span.status.canonical_code.value, - grpc.StatusCode.INVALID_ARGUMENT.value[0], + self.assertIs( + span.status.status_code, trace.status.StatusCode.ERROR, ) def test_error_unary_stream(self): @@ -247,9 +245,8 @@ def test_error_unary_stream(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) span = spans[0] - self.assertEqual( - span.status.canonical_code.value, - grpc.StatusCode.INVALID_ARGUMENT.value[0], + self.assertIs( + span.status.status_code, trace.status.StatusCode.ERROR, ) def test_error_stream_stream(self): @@ -263,9 +260,8 @@ def test_error_stream_stream(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) span = spans[0] - self.assertEqual( - span.status.canonical_code.value, - grpc.StatusCode.INVALID_ARGUMENT.value[0], + self.assertIs( + span.status.status_code, trace.status.StatusCode.ERROR, ) diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/__init__.py b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/__init__.py index 4123f7de526..63f23ae79b4 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/__init__.py @@ -52,7 +52,7 @@ from opentelemetry.instrumentation.jinja2.version import __version__ from opentelemetry.instrumentation.utils import unwrap from opentelemetry.trace import SpanKind, get_tracer -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode logger = logging.getLogger(__name__) diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py b/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py index b38bedf3fd8..4efb50eb4f8 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py @@ -26,7 +26,6 @@ from opentelemetry.instrumentation.pymemcache import PymemcacheInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace import get_tracer -from opentelemetry.trace.status import StatusCanonicalCode from .utils import MockSocket, _str @@ -278,7 +277,7 @@ def _delete(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["delete key"]) @@ -304,7 +303,7 @@ def _incr(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["incr key"]) @@ -321,7 +320,7 @@ def _get(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["get key"]) @@ -338,7 +337,7 @@ def _get(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["get key"]) @@ -373,7 +372,7 @@ def _set(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["set key"]) @@ -390,7 +389,7 @@ def _set(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["set key"]) @@ -407,7 +406,7 @@ def _set(): span = spans[0] - self.assertNotEqual(span.status.canonical_code, StatusCanonicalCode.OK) + self.assertFalse(span.status.is_ok) self.check_spans(spans, 1, ["set key has space"]) diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py index bb20fd5442c..adc51b1c847 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -46,7 +46,7 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.pymongo.version import __version__ from opentelemetry.trace import SpanKind, get_tracer -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode DATABASE_TYPE = "mongodb" COMMAND_ATTRIBUTES = ["filter", "sort", "skip", "limit", "pipeline"] @@ -92,11 +92,8 @@ def started(self, event: monitoring.CommandStartedEvent): # Add Span to dictionary self._span_dict[_get_span_dict_key(event)] = span except Exception as ex: # noqa pylint: disable=broad-except - if span is not None: - if span.is_recording(): - span.set_status( - Status(StatusCanonicalCode.INTERNAL, str(ex)) - ) + if span is not None and span.is_recording(): + span.set_status(Status(StatusCode.ERROR, str(ex))) span.end() self._pop_span(event) @@ -111,7 +108,6 @@ def succeeded(self, event: monitoring.CommandSucceededEvent): span.set_attribute( "db.mongo.duration_micros", event.duration_micros ) - span.set_status(Status(StatusCanonicalCode.OK, event.reply)) span.end() def failed(self, event: monitoring.CommandFailedEvent): @@ -125,7 +121,7 @@ def failed(self, event: monitoring.CommandFailedEvent): span.set_attribute( "db.mongo.duration_micros", event.duration_micros ) - span.set_status(Status(StatusCanonicalCode.UNKNOWN, event.failure)) + span.set_status(Status(StatusCode.ERROR, event.failure)) span.end() def _pop_span(self, event): diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py index d5f67cafe8c..a3bb7b2223c 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py @@ -86,9 +86,8 @@ def test_succeeded(self): span.attributes["db.mongo.duration_micros"], "duration_micros" ) self.assertIs( - span.status.canonical_code, trace_api.status.StatusCanonicalCode.OK + span.status.status_code, trace_api.status.StatusCode.UNSET ) - self.assertEqual(span.status.description, "reply") self.assertIsNotNone(span.end_time) def test_not_recording(self): @@ -121,8 +120,7 @@ def test_failed(self): span.attributes["db.mongo.duration_micros"], "duration_micros" ) self.assertIs( - span.status.canonical_code, - trace_api.status.StatusCanonicalCode.UNKNOWN, + span.status.status_code, trace_api.status.StatusCode.ERROR, ) self.assertEqual(span.status.description, "failure") self.assertIsNotNone(span.end_time) @@ -143,15 +141,13 @@ def test_multiple_commands(self): self.assertEqual(first_span.attributes["db.mongo.request_id"], "first") self.assertIs( - first_span.status.canonical_code, - trace_api.status.StatusCanonicalCode.OK, + first_span.status.status_code, trace_api.status.StatusCode.UNSET, ) self.assertEqual( second_span.attributes["db.mongo.request_id"], "second" ) self.assertIs( - second_span.status.canonical_code, - trace_api.status.StatusCanonicalCode.UNKNOWN, + second_span.status.status_code, trace_api.status.StatusCode.ERROR, ) def test_int_command(self): diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index 770eacf5e27..b4738647dba 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -49,12 +49,12 @@ MetricMixin, ) from opentelemetry.instrumentation.requests.version import __version__ -from opentelemetry.instrumentation.utils import http_status_to_canonical_code +from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.trace import SpanKind, get_tracer from opentelemetry.trace.status import ( EXCEPTION_STATUS_FIELD, Status, - StatusCanonicalCode, + StatusCode, ) # A key to a context variable to avoid creating duplicate spans when instrumenting @@ -155,9 +155,7 @@ def _instrumented_requests_call( except Exception as exc: # pylint: disable=W0703 exception = exc setattr( - exception, - EXCEPTION_STATUS_FIELD, - _exception_to_canonical_code(exception), + exception, EXCEPTION_STATUS_FIELD, StatusCode.ERROR, ) result = getattr(exc, "response", None) finally: @@ -171,9 +169,7 @@ def _instrumented_requests_call( span.set_attribute("http.status_text", result.reason) span.set_status( Status( - http_status_to_canonical_code( - result.status_code - ) + http_status_to_status_code(result.status_code) ) ) labels["http.status_code"] = str(result.status_code) @@ -221,17 +217,6 @@ def _uninstrument_from(instr_root, restore_as_bound_func=False): setattr(instr_root, instr_func_name, original) -def _exception_to_canonical_code(exc: Exception) -> StatusCanonicalCode: - if isinstance( - exc, - (InvalidURL, InvalidSchema, MissingSchema, URLRequired, ValueError), - ): - return StatusCanonicalCode.INVALID_ARGUMENT - if isinstance(exc, Timeout): - return StatusCanonicalCode.DEADLINE_EXCEEDED - return StatusCanonicalCode.UNKNOWN - - class RequestsInstrumentor(BaseInstrumentor, MetricMixin): """An instrumentor for requests See `BaseInstrumentor` diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index f41e597b23e..f5209108e33 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -25,7 +25,7 @@ from opentelemetry.sdk.util import get_dict_as_key from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode class RequestsIntegrationTestBase(abc.ABC): @@ -81,9 +81,7 @@ def test_basic(self): }, ) - self.assertIs( - span.status.canonical_code, trace.status.StatusCanonicalCode.OK - ) + self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) self.check_span_instrumentation_info( span, opentelemetry.instrumentation.requests @@ -123,8 +121,7 @@ def test_not_foundbasic(self): self.assertEqual(span.attributes.get("http.status_text"), "Not Found") self.assertIs( - span.status.canonical_code, - trace.status.StatusCanonicalCode.NOT_FOUND, + span.status.status_code, trace.status.StatusCode.ERROR, ) def test_uninstrument(self): @@ -263,9 +260,7 @@ def test_requests_exception_without_response(self, *_, **__): span.attributes, {"component": "http", "http.method": "GET", "http.url": self.URL}, ) - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.UNKNOWN - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) self.assertIsNotNone(RequestsInstrumentor().meter) self.assertEqual(len(RequestsInstrumentor().meter.metrics), 1) @@ -307,9 +302,7 @@ def test_requests_exception_with_response(self, *_, **__): "http.status_text": "Internal Server Error", }, ) - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.INTERNAL - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) self.assertIsNotNone(RequestsInstrumentor().meter) self.assertEqual(len(RequestsInstrumentor().meter.metrics), 1) recorder = RequestsInstrumentor().meter.metrics.pop() @@ -334,9 +327,7 @@ def test_requests_basic_exception(self, *_, **__): self.perform_request(self.URL) span = self.assert_span() - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.UNKNOWN - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) @mock.patch( "requests.adapters.HTTPAdapter.send", side_effect=requests.Timeout @@ -346,9 +337,7 @@ def test_requests_timeout_exception(self, *_, **__): self.perform_request(self.URL) span = self.assert_span() - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.DEADLINE_EXCEEDED - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) class TestRequestsIntegration(RequestsIntegrationTestBase, TestBase): @@ -371,9 +360,7 @@ def test_invalid_url(self): span.attributes, {"component": "http", "http.method": "POST", "http.url": url}, ) - self.assertEqual( - span.status.canonical_code, StatusCanonicalCode.INVALID_ARGUMENT - ) + self.assertEqual(span.status.status_code, StatusCode.ERROR) def test_if_headers_equals_none(self): result = requests.get(self.URL, headers=None) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index 83a5b82b235..7c97c685da5 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -16,7 +16,7 @@ from opentelemetry import trace from opentelemetry.instrumentation.sqlalchemy.version import __version__ -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode # Network attribute semantic convention here: # https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes @@ -112,10 +112,7 @@ def _handle_error(self, context): try: if self.current_span.is_recording(): self.current_span.set_status( - Status( - StatusCanonicalCode.UNKNOWN, - str(context.original_exception), - ) + Status(StatusCode.ERROR, str(context.original_exception),) ) finally: self.current_span.end() diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index f6ae8b321d0..9a7959ab956 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -51,7 +51,7 @@ def get(self): from opentelemetry.instrumentation.tornado.version import __version__ from opentelemetry.instrumentation.utils import ( extract_attributes_from_object, - http_status_to_canonical_code, + http_status_to_status_code, unwrap, ) from opentelemetry.trace.status import Status @@ -269,7 +269,7 @@ def _finish_span(tracer, handler, error=None): ctx.span.set_attribute("http.status_code", status_code) ctx.span.set_status( Status( - canonical_code=http_status_to_canonical_code(status_code), + status_code=http_status_to_status_code(status_code), description=reason, ) ) diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py index 12330c0919d..5ec001bdab4 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py @@ -3,7 +3,7 @@ from tornado.httpclient import HTTPError, HTTPRequest from opentelemetry import propagators, trace -from opentelemetry.instrumentation.utils import http_status_to_canonical_code +from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.trace.status import Status from opentelemetry.util import time_ns @@ -74,7 +74,7 @@ def _finish_tracing_callback(future, span): span.set_attribute("http.status_code", status_code) span.set_status( Status( - canonical_code=http_status_to_canonical_code(status_code), + status_code=http_status_to_status_code(status_code), description=description, ) ) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 56c8b755c5c..62eef43251e 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -59,9 +59,9 @@ def hello(): import wsgiref.util as wsgiref_util from opentelemetry import context, propagators, trace -from opentelemetry.instrumentation.utils import http_status_to_canonical_code +from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.instrumentation.wsgi.version import __version__ -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode _HTTP_VERSION_PREFIX = "HTTP/" @@ -146,13 +146,13 @@ def add_response_attributes( except ValueError: span.set_status( Status( - StatusCanonicalCode.UNKNOWN, + StatusCode.ERROR, "Non-integer HTTP status: " + repr(status_code), ) ) else: span.set_attribute("http.status_code", status_code) - span.set_status(Status(http_status_to_canonical_code(status_code))) + span.set_status(Status(http_status_to_status_code(status_code))) def get_default_span_name(environ): @@ -217,7 +217,7 @@ def __call__(self, environ, start_response): ) except Exception as ex: if span.is_recording(): - span.set_status(Status(StatusCanonicalCode.INTERNAL, str(ex))) + span.set_status(Status(StatusCode.ERROR, str(ex))) span.end() context.detach(token) raise diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index baab50d96bb..144b4cf0692 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -21,7 +21,7 @@ import opentelemetry.instrumentation.wsgi as otel_wsgi from opentelemetry import trace as trace_api from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode class Response: @@ -177,7 +177,7 @@ def test_wsgi_internal_error(self): span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) self.assertEqual( - span_list[0].status.canonical_code, StatusCanonicalCode.INTERNAL, + span_list[0].status.status_code, StatusCode.ERROR, ) def test_override_span_name(self): diff --git a/opentelemetry-api/CHANGELOG.md b/opentelemetry-api/CHANGELOG.md index 5f576318324..977dd6375c0 100644 --- a/opentelemetry-api/CHANGELOG.md +++ b/opentelemetry-api/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Updating status codes to adhere to specs ([#1282](https://github.com/open-telemetry/opentelemetry-python/pull/1282)) + ## Version 0.14b0 Released 2020-10-13 diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index f10cb0312a0..d747734629a 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -268,9 +268,9 @@ def start_span( start_time: Sets the start time of a span set_status_on_exception: Only relevant if the returned span is used in a with/context manager. Defines wether the span status will - be automatically set to UNKNOWN when an uncaught exception is + be automatically set to ERROR when an uncaught exception is raised in the span with block. The span status won't be set by - this mechanism if it was previousy set manually. + this mechanism if it was previously set manually. Returns: The newly-created span. diff --git a/opentelemetry-api/src/opentelemetry/trace/status.py b/opentelemetry-api/src/opentelemetry/trace/status.py index 9df5493e3b9..70897935799 100644 --- a/opentelemetry-api/src/opentelemetry/trace/status.py +++ b/opentelemetry-api/src/opentelemetry/trace/status.py @@ -22,157 +22,34 @@ EXCEPTION_STATUS_FIELD = "_otel_status_code" -class StatusCanonicalCode(enum.Enum): +class StatusCode(enum.Enum): """Represents the canonical set of status codes of a finished Span.""" OK = 0 - """Not an error, returned on success.""" + """The operation has been validated by an Application developer or Operator to have completed successfully.""" - CANCELLED = 1 - """The operation was cancelled, typically by the caller.""" + UNSET = 1 + """The default status.""" - UNKNOWN = 2 - """Unknown error. - - For example, this error may be returned when a Status value received from - another address space belongs to an error space that is not known in this - address space. Also errors raised by APIs that do not return enough error - information may be converted to this error. - """ - - INVALID_ARGUMENT = 3 - """The client specified an invalid argument. - - Note that this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates - arguments that are problematic regardless of the state of the system (e.g., - a malformed file name). - """ - - DEADLINE_EXCEEDED = 4 - """The deadline expired before the operation could complete. - - For operations that change the state of the system, this error may be - returned even if the operation has completed successfully. For example, a - successful response from a server could have been delayed long - """ - - NOT_FOUND = 5 - """Some requested entity (e.g., file or directory) was not found. - - Note to server developers: if a request is denied for an entire class of - users, such as gradual feature rollout or undocumented whitelist, NOT_FOUND - may be used. If a request is denied for some users within a class of users, - such as user-based access control, PERMISSION_DENIED must be used. - """ - - ALREADY_EXISTS = 6 - """The entity that a client attempted to create (e.g., file or directory) - already exists. - """ - - PERMISSION_DENIED = 7 - """The caller does not have permission to execute the specified operation. - - PERMISSION_DENIED must not be used for rejections caused by exhausting some - resource (use RESOURCE_EXHAUSTED instead for those errors). - PERMISSION_DENIED must not be used if the caller can not be identified (use - UNAUTHENTICATED instead for those errors). This error code does not imply - the request is valid or the requested entity exists or satisfies other - pre-conditions. - """ - - RESOURCE_EXHAUSTED = 8 - """Some resource has been exhausted, perhaps a per-user quota, or perhaps - the entire file system is out of space. - """ - - FAILED_PRECONDITION = 9 - """The operation was rejected because the system is not in a state required - for the operation's execution. - - For example, the directory to be deleted is non-empty, an rmdir operation - is applied to a non-directory, etc. Service implementors can use the - following guidelines to decide between FAILED_PRECONDITION, ABORTED, and - UNAVAILABLE: - - (a) Use UNAVAILABLE if the client can retry just the failing call. - (b) Use ABORTED if the client should retry at a higher level (e.g., - when a client-specified test-and-set fails, indicating the client - should restart a read-modify-write sequence). - (c) Use FAILED_PRECONDITION if the client should not retry until the - system state has been explicitly fixed. - - E.g., if an "rmdir" fails because the directory is non-empty, - FAILED_PRECONDITION should be returned since the client should not retry - unless the files are deleted from the directory. - """ - - ABORTED = 10 - """The operation was aborted, typically due to a concurrency issue such as a - sequencer check failure or transaction abort. - - See the guidelines above for deciding between FAILED_PRECONDITION, ABORTED, - and UNAVAILABLE. - """ - - OUT_OF_RANGE = 11 - """The operation was attempted past the valid range. - - E.g., seeking or reading past end-of-file. Unlike INVALID_ARGUMENT, this - error indicates a problem that may be fixed if the system state changes. - For example, a 32-bit file system will generate INVALID_ARGUMENT if asked - to read at an offset that is not in the range [0,2^32-1],but it will - generate OUT_OF_RANGE if asked to read from an offset past the current file - size. There is a fair bit of overlap between FAILED_PRECONDITION and - OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error) - when it applies so that callers who are iterating through a space can - easily look for an OUT_OF_RANGE error to detect when they are done. - """ - - UNIMPLEMENTED = 12 - """The operation is not implemented or is not supported/enabled in this - service. - """ - - INTERNAL = 13 - """Internal errors. - - This means that some invariants expected by the underlying system have been - broken. This error code is reserved for serious errors. - """ - - UNAVAILABLE = 14 - """The service is currently unavailable. - - This is most likely a transient condition, which can be corrected by - retrying with a backoff. Note that it is not always safe to retry - non-idempotent operations. - """ - - DATA_LOSS = 15 - """Unrecoverable data loss or corruption.""" - - UNAUTHENTICATED = 16 - """The request does not have valid authentication credentials for the - operation. - """ + ERROR = 2 + """The operation contains an error.""" class Status: """Represents the status of a finished Span. Args: - canonical_code: The canonical status code that describes the result + status_code: The canonical status code that describes the result status of the operation. description: An optional description of the status. """ def __init__( self, - canonical_code: StatusCanonicalCode = StatusCanonicalCode.OK, + status_code: StatusCode = StatusCode.UNSET, description: typing.Optional[str] = None, ): - self._canonical_code = canonical_code + self._status_code = status_code self._description = None if description is not None and not isinstance(description, str): logger.warning("Invalid status description type, expected str") @@ -180,9 +57,9 @@ def __init__( self._description = description @property - def canonical_code(self) -> StatusCanonicalCode: + def status_code(self) -> StatusCode: """Represents the canonical status code of a finished Span.""" - return self._canonical_code + return self._status_code @property def description(self) -> typing.Optional[str]: @@ -192,4 +69,9 @@ def description(self) -> typing.Optional[str]: @property def is_ok(self) -> bool: """Returns false if this represents an error, true otherwise.""" - return self._canonical_code is StatusCanonicalCode.OK + return self.is_unset or self._status_code is StatusCode.OK + + @property + def is_unset(self) -> bool: + """Returns true if unset, false otherwise.""" + return self._status_code is StatusCode.UNSET diff --git a/opentelemetry-api/tests/trace/test_status.py b/opentelemetry-api/tests/trace/test_status.py index 6c086f3ae04..cd0f678d13b 100644 --- a/opentelemetry-api/tests/trace/test_status.py +++ b/opentelemetry-api/tests/trace/test_status.py @@ -15,21 +15,21 @@ import unittest from logging import WARNING -from opentelemetry.trace.status import Status, StatusCanonicalCode +from opentelemetry.trace.status import Status, StatusCode class TestStatus(unittest.TestCase): def test_constructor(self): status = Status() - self.assertIs(status.canonical_code, StatusCanonicalCode.OK) + self.assertIs(status.status_code, StatusCode.UNSET) self.assertIsNone(status.description) - status = Status(StatusCanonicalCode.UNAVAILABLE, "unavailable") - self.assertIs(status.canonical_code, StatusCanonicalCode.UNAVAILABLE) + status = Status(StatusCode.ERROR, "unavailable") + self.assertIs(status.status_code, StatusCode.ERROR) self.assertEqual(status.description, "unavailable") def test_invalid_description(self): with self.assertLogs(level=WARNING): status = Status(description={"test": "val"}) # type: ignore - self.assertIs(status.canonical_code, StatusCanonicalCode.OK) + self.assertIs(status.status_code, StatusCode.UNSET) self.assertEqual(status.description, None) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py index 6220854ad59..22ba7a20572 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py @@ -16,7 +16,7 @@ from wrapt import ObjectProxy -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode def extract_attributes_from_object( @@ -32,42 +32,43 @@ def extract_attributes_from_object( return extracted -def http_status_to_canonical_code( +def http_status_to_status_code( status: int, allow_redirect: bool = True -) -> StatusCanonicalCode: +) -> StatusCode: """Converts an HTTP status code to an OpenTelemetry canonical status code Args: status (int): HTTP status code """ # pylint:disable=too-many-branches,too-many-return-statements + # See: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status if status < 100: - return StatusCanonicalCode.UNKNOWN + return StatusCode.ERROR if status <= 299: - return StatusCanonicalCode.OK + return StatusCode.UNSET if status <= 399: if allow_redirect: - return StatusCanonicalCode.OK - return StatusCanonicalCode.DEADLINE_EXCEEDED + return StatusCode.UNSET + return StatusCode.ERROR if status <= 499: if status == 401: # HTTPStatus.UNAUTHORIZED: - return StatusCanonicalCode.UNAUTHENTICATED + return StatusCode.ERROR if status == 403: # HTTPStatus.FORBIDDEN: - return StatusCanonicalCode.PERMISSION_DENIED + return StatusCode.ERROR if status == 404: # HTTPStatus.NOT_FOUND: - return StatusCanonicalCode.NOT_FOUND + return StatusCode.ERROR if status == 429: # HTTPStatus.TOO_MANY_REQUESTS: - return StatusCanonicalCode.RESOURCE_EXHAUSTED - return StatusCanonicalCode.INVALID_ARGUMENT + return StatusCode.ERROR + return StatusCode.ERROR if status <= 599: if status == 501: # HTTPStatus.NOT_IMPLEMENTED: - return StatusCanonicalCode.UNIMPLEMENTED + return StatusCode.ERROR if status == 503: # HTTPStatus.SERVICE_UNAVAILABLE: - return StatusCanonicalCode.UNAVAILABLE + return StatusCode.ERROR if status == 504: # HTTPStatus.GATEWAY_TIMEOUT: - return StatusCanonicalCode.DEADLINE_EXCEEDED - return StatusCanonicalCode.INTERNAL - return StatusCanonicalCode.UNKNOWN + return StatusCode.ERROR + return StatusCode.ERROR + return StatusCode.ERROR def unwrap(obj, attr: str): diff --git a/opentelemetry-instrumentation/tests/test_utils.py b/opentelemetry-instrumentation/tests/test_utils.py index 660a6bbe863..edd23204734 100644 --- a/opentelemetry-instrumentation/tests/test_utils.py +++ b/opentelemetry-instrumentation/tests/test_utils.py @@ -14,43 +14,32 @@ from http import HTTPStatus -from opentelemetry.instrumentation.utils import http_status_to_canonical_code +from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode class TestUtils(TestBase): - def test_http_status_to_canonical_code(self): + # See https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status + def test_http_status_to_status_code(self): for status_code, expected in ( - (HTTPStatus.OK, StatusCanonicalCode.OK), - (HTTPStatus.ACCEPTED, StatusCanonicalCode.OK), - (HTTPStatus.IM_USED, StatusCanonicalCode.OK), - (HTTPStatus.MULTIPLE_CHOICES, StatusCanonicalCode.OK), - (HTTPStatus.BAD_REQUEST, StatusCanonicalCode.INVALID_ARGUMENT), - (HTTPStatus.UNAUTHORIZED, StatusCanonicalCode.UNAUTHENTICATED), - (HTTPStatus.FORBIDDEN, StatusCanonicalCode.PERMISSION_DENIED), - (HTTPStatus.NOT_FOUND, StatusCanonicalCode.NOT_FOUND), - ( - HTTPStatus.UNPROCESSABLE_ENTITY, - StatusCanonicalCode.INVALID_ARGUMENT, - ), - ( - HTTPStatus.TOO_MANY_REQUESTS, - StatusCanonicalCode.RESOURCE_EXHAUSTED, - ), - (HTTPStatus.NOT_IMPLEMENTED, StatusCanonicalCode.UNIMPLEMENTED), - (HTTPStatus.SERVICE_UNAVAILABLE, StatusCanonicalCode.UNAVAILABLE), - ( - HTTPStatus.GATEWAY_TIMEOUT, - StatusCanonicalCode.DEADLINE_EXCEEDED, - ), - ( - HTTPStatus.HTTP_VERSION_NOT_SUPPORTED, - StatusCanonicalCode.INTERNAL, - ), - (600, StatusCanonicalCode.UNKNOWN), - (99, StatusCanonicalCode.UNKNOWN), + (HTTPStatus.OK, StatusCode.UNSET), + (HTTPStatus.ACCEPTED, StatusCode.UNSET), + (HTTPStatus.IM_USED, StatusCode.UNSET), + (HTTPStatus.MULTIPLE_CHOICES, StatusCode.UNSET), + (HTTPStatus.BAD_REQUEST, StatusCode.ERROR), + (HTTPStatus.UNAUTHORIZED, StatusCode.ERROR), + (HTTPStatus.FORBIDDEN, StatusCode.ERROR), + (HTTPStatus.NOT_FOUND, StatusCode.ERROR), + (HTTPStatus.UNPROCESSABLE_ENTITY, StatusCode.ERROR,), + (HTTPStatus.TOO_MANY_REQUESTS, StatusCode.ERROR,), + (HTTPStatus.NOT_IMPLEMENTED, StatusCode.ERROR), + (HTTPStatus.SERVICE_UNAVAILABLE, StatusCode.ERROR), + (HTTPStatus.GATEWAY_TIMEOUT, StatusCode.ERROR,), + (HTTPStatus.HTTP_VERSION_NOT_SUPPORTED, StatusCode.ERROR,), + (600, StatusCode.ERROR), + (99, StatusCode.ERROR), ): with self.subTest(status_code=status_code): - actual = http_status_to_canonical_code(int(status_code)) + actual = http_status_to_status_code(int(status_code)) self.assertEqual(actual, expected, status_code) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 262556132e6..0bfa4147a28 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -10,6 +10,7 @@ ([#998](https://github.com/open-telemetry/opentelemetry-python/pull/998)) - Samplers to accept parent Context ([#1267](https://github.com/open-telemetry/opentelemetry-python/pull/1267)) +- Updating status codes to adhere to spec ([#1282](https://github.com/open-telemetry/opentelemetry-python/pull/1282)) ## Version 0.14b0 diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 4da93ae502d..e1c9dd17d34 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -47,7 +47,7 @@ from opentelemetry.trace.status import ( EXCEPTION_STATUS_FIELD, Status, - StatusCanonicalCode, + StatusCode, ) from opentelemetry.util import time_ns, types @@ -435,7 +435,7 @@ def __init__( self._set_status_on_exception = set_status_on_exception self.span_processor = span_processor - self.status = None + self.status = Status(StatusCode.UNSET) self._lock = threading.Lock() _filter_attribute_values(attributes) @@ -546,7 +546,7 @@ def to_json(self, indent=4): if self.status is not None: status = OrderedDict() - status["canonical_code"] = str(self.status.canonical_code.name) + status["status_code"] = str(self.status.status_code.name) if self.status.description: status["description"] = self.status.description @@ -637,9 +637,6 @@ def end(self, end_time: Optional[int] = None) -> None: logger.warning("Calling end() on an ended span.") return - if self.status is None: - self.status = Status(canonical_code=StatusCanonicalCode.OK) - self._end_time = end_time if end_time is not None else time_ns() self.span_processor.on_end(self) @@ -662,15 +659,17 @@ def __exit__( exc_tb: Optional[TracebackType], ) -> None: """Ends context manager and calls `end` on the `Span`.""" - + # Records status if span is used as context manager + # i.e. with tracer.start_span() as span: + # TODO: Record exception if ( - self.status is None + self.status.status_code is StatusCode.UNSET and self._set_status_on_exception and exc_val is not None ): self.set_status( Status( - canonical_code=StatusCanonicalCode.UNKNOWN, + status_code=StatusCode.ERROR, description="{}: {}".format(exc_type.__name__, exc_val), ) ) @@ -831,13 +830,18 @@ def use_span( if record_exception: span.record_exception(error) - if span.status is None and span._set_status_on_exception: + # Records status if use_span is used + # i.e. with tracer.start_as_current_span() as span: + if ( + span.status.status_code is StatusCode.UNSET + and span._set_status_on_exception + ): span.set_status( Status( - canonical_code=getattr( + status_code=getattr( error, EXCEPTION_STATUS_FIELD, - StatusCanonicalCode.UNKNOWN, + StatusCode.ERROR, ), description="{}: {}".format( type(error).__name__, error diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 35bdf91320b..d08e12dee26 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -26,7 +26,7 @@ from opentelemetry.sdk.trace import Resource, sampling from opentelemetry.sdk.util import ns_to_iso_str from opentelemetry.sdk.util.instrumentation import InstrumentationInfo -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode from opentelemetry.util import time_ns @@ -733,16 +733,18 @@ def test_start_span(self): span.start() self.assertEqual(start_time, span.start_time) - self.assertIs(span.status, None) + self.assertIsNotNone(span.status) + self.assertIs( + span.status.status_code, trace_api.status.StatusCode.UNSET + ) # status new_status = trace_api.status.Status( - trace_api.status.StatusCanonicalCode.CANCELLED, "Test description" + trace_api.status.StatusCode.ERROR, "Test description" ) span.set_status(new_status) self.assertIs( - span.status.canonical_code, - trace_api.status.StatusCanonicalCode.CANCELLED, + span.status.status_code, trace_api.status.StatusCode.ERROR, ) self.assertIs(span.status.description, "Test description") @@ -803,13 +805,13 @@ def test_ended_span(self): self.assertEqual(root.name, "root") new_status = trace_api.status.Status( - trace_api.status.StatusCanonicalCode.CANCELLED, "Test description" + trace_api.status.StatusCode.ERROR, "Test description" ) with self.assertLogs(level=WARNING): root.set_status(new_status) self.assertEqual( - root.status.canonical_code, trace_api.status.StatusCanonicalCode.OK + root.status.status_code, trace_api.status.StatusCode.UNSET ) def test_error_status(self): @@ -818,9 +820,7 @@ def error_status_test(context): with context as root: raise AssertionError("unknown") - self.assertIs( - root.status.canonical_code, StatusCanonicalCode.UNKNOWN - ) + self.assertIs(root.status.status_code, StatusCode.ERROR) self.assertEqual( root.status.description, "AssertionError: unknown" ) @@ -839,17 +839,12 @@ def error_status_test(context): with self.assertRaises(AssertionError): with context as root: root.set_status( - trace_api.status.Status( - StatusCanonicalCode.UNAVAILABLE, - "Error: Unavailable", - ) + trace_api.status.Status(StatusCode.OK, "OK",) ) raise AssertionError("unknown") - self.assertIs( - root.status.canonical_code, StatusCanonicalCode.UNAVAILABLE - ) - self.assertEqual(root.status.description, "Error: Unavailable") + self.assertIs(root.status.status_code, StatusCode.OK) + self.assertEqual(root.status.description, "OK") error_status_test( trace.TracerProvider().get_tracer(__name__).start_span("root") @@ -1051,6 +1046,9 @@ def test_to_json(self): "parent_id": null, "start_time": null, "end_time": null, + "status": { + "status_code": "UNSET" + }, "attributes": {}, "events": [], "links": [], @@ -1059,7 +1057,7 @@ def test_to_json(self): ) self.assertEqual( span.to_json(indent=None), - '{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "{}"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "attributes": {}, "events": [], "links": [], "resource": {}}', + '{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "{}"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "status": {"status_code": "UNSET"}, "attributes": {}, "events": [], "links": [], "resource": {}}', ) def test_attributes_to_json(self): @@ -1076,7 +1074,7 @@ def test_attributes_to_json(self): date_str = ns_to_iso_str(123) self.assertEqual( span.to_json(indent=None), - '{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "{}"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "attributes": {"key": "value"}, "events": [{"name": "event", "timestamp": "' + '{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "{}"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "status": {"status_code": "UNSET"}, "attributes": {"key": "value"}, "events": [{"name": "event", "timestamp": "' + date_str + '", "attributes": {"key2": "value2"}}], "links": [], "resource": {}}', ) diff --git a/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py b/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py index cb9080e62c2..2e37efe2246 100644 --- a/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py @@ -5,7 +5,7 @@ from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode POSTGRES_HOST = os.getenv("POSTGRESQL_HOST ", "localhost") POSTGRES_PORT = int(os.getenv("POSTGRESQL_PORT ", "5432")) @@ -45,9 +45,7 @@ def test_instrumented_execute_method_without_arguments(self, *_, **__): async_call(self._connection.execute("SELECT 42;")) spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) - self.assertEqual( - StatusCanonicalCode.OK, spans[0].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[0].status.status_code) self.assertEqual( spans[0].attributes, { @@ -90,9 +88,7 @@ async def _transaction_execute(): }, spans[0].attributes, ) - self.assertEqual( - StatusCanonicalCode.OK, spans[0].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[0].status.status_code) self.assertEqual( { "db.instance": POSTGRES_DB_NAME, @@ -102,9 +98,7 @@ async def _transaction_execute(): }, spans[1].attributes, ) - self.assertEqual( - StatusCanonicalCode.OK, spans[1].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[1].status.status_code) self.assertEqual( { "db.instance": POSTGRES_DB_NAME, @@ -114,9 +108,7 @@ async def _transaction_execute(): }, spans[2].attributes, ) - self.assertEqual( - StatusCanonicalCode.OK, spans[2].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[2].status.status_code) def test_instrumented_failed_transaction_method(self, *_, **__): async def _transaction_execute(): @@ -137,9 +129,7 @@ async def _transaction_execute(): }, spans[0].attributes, ) - self.assertEqual( - StatusCanonicalCode.OK, spans[0].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[0].status.status_code) self.assertEqual( { "db.instance": POSTGRES_DB_NAME, @@ -150,8 +140,7 @@ async def _transaction_execute(): spans[1].attributes, ) self.assertEqual( - StatusCanonicalCode.INVALID_ARGUMENT, - spans[1].status.canonical_code, + StatusCode.ERROR, spans[1].status.status_code, ) self.assertEqual( { @@ -162,17 +151,13 @@ async def _transaction_execute(): }, spans[2].attributes, ) - self.assertEqual( - StatusCanonicalCode.OK, spans[2].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[2].status.status_code) def test_instrumented_method_doesnt_capture_parameters(self, *_, **__): async_call(self._connection.execute("SELECT $1;", "1")) spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) - self.assertEqual( - StatusCanonicalCode.OK, spans[0].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[0].status.status_code) self.assertEqual( spans[0].attributes, { @@ -216,9 +201,7 @@ def test_instrumented_execute_method_with_arguments(self, *_, **__): async_call(self._connection.execute("SELECT $1;", "1")) spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) - self.assertEqual( - StatusCanonicalCode.OK, spans[0].status.canonical_code - ) + self.assertIs(StatusCode.UNSET, spans[0].status.status_code) self.assertEqual( spans[0].attributes, { diff --git a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py index c4be6762ea0..7786890a5fe 100644 --- a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py +++ b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py @@ -22,7 +22,7 @@ from opentelemetry.instrumentation.celery import CeleryInstrumentor from opentelemetry.sdk import resources from opentelemetry.sdk.trace import TracerProvider, export -from opentelemetry.trace.status import StatusCanonicalCode +from opentelemetry.trace.status import StatusCode # set a high timeout for async executions due to issues in CI ASYNC_GET_TIMEOUT = 120 @@ -257,7 +257,7 @@ def fn_exception(): span.attributes.get("celery.task_name") == "test_celery_functional.fn_exception" ) - assert span.status.canonical_code == StatusCanonicalCode.UNKNOWN + assert span.status.status_code == StatusCode.ERROR assert span.attributes.get("messaging.message_id") == result.task_id assert "Task class is failing" in span.status.description @@ -278,7 +278,7 @@ def fn_exception(): span = spans[0] assert span.status.is_ok is True - assert span.status.canonical_code == StatusCanonicalCode.OK + assert span.status.status_code == StatusCode.UNSET assert span.name == "run/test_celery_functional.fn_exception" assert span.attributes.get("celery.action") == "run" assert span.attributes.get("celery.state") == "FAILURE" @@ -305,7 +305,7 @@ def fn_exception(): span = spans[0] assert span.status.is_ok is True - assert span.status.canonical_code == StatusCanonicalCode.OK + assert span.status.status_code == StatusCode.UNSET assert span.name == "run/test_celery_functional.fn_exception" assert span.attributes.get("celery.action") == "run" assert span.attributes.get("celery.state") == "RETRY" @@ -377,7 +377,7 @@ def run(self): ) assert span.attributes.get("celery.action") == "run" assert span.attributes.get("celery.state") == "FAILURE" - assert span.status.canonical_code == StatusCanonicalCode.UNKNOWN + assert span.status.status_code == StatusCode.ERROR assert span.attributes.get("messaging.message_id") == result.task_id assert "Task class is failing" in span.status.description @@ -406,7 +406,7 @@ def run(self): span = spans[0] assert span.status.is_ok is True - assert span.status.canonical_code == StatusCanonicalCode.OK + assert span.status.status_code == StatusCode.UNSET assert span.name == "run/test_celery_functional.BaseTask" assert span.attributes.get("celery.action") == "run" assert span.attributes.get("celery.state") == "FAILURE" diff --git a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py index 64984e9c4fa..8bdc120105b 100644 --- a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py +++ b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py @@ -36,9 +36,7 @@ def tearDown(self): def _check_span(self, span): self.assertEqual(span.attributes["service"], self.test_service) self.assertEqual(span.name, "redis.command") - self.assertIs( - span.status.canonical_code, trace.status.StatusCanonicalCode.OK - ) + self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) self.assertEqual(span.attributes.get("db.instance"), 0) self.assertEqual( span.attributes.get("db.url"), "redis://localhost:6379" diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py index b2d8c0abc51..72137f83e84 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py @@ -113,9 +113,7 @@ def _check_span(self, span): self.assertEqual(span.name, "{}.query".format(self.VENDOR)) self.assertEqual(span.attributes.get("service"), self.SERVICE) self.assertEqual(span.attributes.get(_DB), self.SQL_DB) - self.assertIs( - span.status.canonical_code, trace.status.StatusCanonicalCode.OK - ) + self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) self.assertGreater((span.end_time - span.start_time), 0) def test_orm_insert(self): diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py index 20c837c03b6..c408c63d943 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py @@ -66,7 +66,5 @@ def test_engine_traced(self): # check subset of span fields self.assertEqual(span.name, "postgres.query") self.assertEqual(span.attributes.get("service"), "postgres") - self.assertIs( - span.status.canonical_code, trace.status.StatusCanonicalCode.OK - ) + self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) self.assertGreater((span.end_time - span.start_time), 0) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py index 44c3501b1d7..310cd91f732 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py @@ -77,7 +77,6 @@ def test_engine_execute_errors(self): self.assertTrue(span.end_time - span.start_time > 0) # check the error self.assertIs( - span.status.canonical_code, - trace.status.StatusCanonicalCode.UNKNOWN, + span.status.status_code, trace.status.StatusCode.ERROR, ) self.assertIn("a_wrong_table", span.status.description) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py index 615a196f5bb..91fb123c97a 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py @@ -78,8 +78,7 @@ def test_engine_execute_errors(self): self.assertTrue(span.end_time - span.start_time > 0) # check the error self.assertIs( - span.status.canonical_code, - trace.status.StatusCanonicalCode.UNKNOWN, + span.status.status_code, trace.status.StatusCode.ERROR, ) self.assertIn("a_wrong_table", span.status.description) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py index 4295fc045c7..309dd73ccc7 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py @@ -53,8 +53,7 @@ def test_engine_execute_errors(self): self.assertTrue((span.end_time - span.start_time) > 0) # check the error self.assertIs( - span.status.canonical_code, - trace.status.StatusCanonicalCode.UNKNOWN, + span.status.status_code, trace.status.StatusCode.ERROR, ) self.assertEqual( span.status.description, "no such table: a_wrong_table"