From 9315eb0fb2d28ae10310d4d1e230ac903ed7f41e Mon Sep 17 00:00:00 2001 From: alrex Date: Tue, 9 Mar 2021 14:33:13 -0800 Subject: [PATCH] use StatusCode from trace instead of trace.status (#366) --- .github/workflows/test.yml | 2 +- .../tests/test_aiohttp_client_integration.py | 2 +- .../tests/test_aiopg_integration.py | 8 ++------ .../tests/test_botocore_instrumentation.py | 2 +- .../tests/test_dbapi_integration.py | 12 +++--------- .../tests/test_middleware.py | 3 +-- .../tests/test_elasticsearch.py | 2 +- .../tests/test_falcon.py | 2 +- .../tests/test_client_interceptor.py | 8 ++++---- .../tests/test_server_interceptor.py | 2 +- .../tests/test_pymongo.py | 10 ++++------ .../tests/test_requests_integration.py | 6 +++--- .../tests/test_urllib_integration.py | 6 +++--- .../tests/test_wsgi_middleware.py | 2 +- .../tests/asyncpg/test_asyncpg_functional.py | 2 +- .../tests/celery/test_celery_functional.py | 2 +- .../tests/redis/test_redis_functional.py | 4 ++-- .../tests/sqlalchemy_tests/mixins.py | 2 +- .../tests/sqlalchemy_tests/test_instrument.py | 2 +- .../tests/sqlalchemy_tests/test_mysql.py | 2 +- .../tests/sqlalchemy_tests/test_postgres.py | 2 +- .../tests/sqlalchemy_tests/test_sqlite.py | 2 +- 22 files changed, 36 insertions(+), 49 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87e84993c3..b3eed9f43b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: ddff32ac77e2e22b3193b71f1e71a590a99d1eda + CORE_REPO_SHA: 10dc3a8bc031d5b355f62a698094a03eedb2a8ee jobs: build: 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 363b0356d4..33708dfe4e 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 StatusCode +from opentelemetry.trace import StatusCode def run_with_test_server( diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py index 35139bba94..50766aee6e 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py @@ -268,9 +268,7 @@ def test_span_succeeded(self): self.assertEqual(span.attributes["db.user"], "testuser") self.assertEqual(span.attributes["net.peer.name"], "testhost") self.assertEqual(span.attributes["net.peer.port"], 123) - self.assertIs( - span.status.status_code, trace_api.status.StatusCode.UNSET - ) + self.assertIs(span.status.status_code, trace_api.StatusCode.UNSET) def test_span_not_recording(self): connection_props = { @@ -317,9 +315,7 @@ def test_span_failed(self): self.assertEqual(len(spans_list), 1) span = spans_list[0] self.assertEqual(span.attributes["db.statement"], "Test query") - self.assertIs( - span.status.status_code, trace_api.status.StatusCode.ERROR - ) + self.assertIs(span.status.status_code, trace_api.StatusCode.ERROR) self.assertEqual(span.status.description, "Exception: Test Exception") def test_executemany(self): diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 2a7c05d088..f6f86d5aa3 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -136,7 +136,7 @@ def test_s3_client(self): }, ) self.assertIs( - span.status.status_code, trace_api.status.StatusCode.ERROR, + span.status.status_code, trace_api.StatusCode.ERROR, ) # Comment test for issue 1088 diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py index 57ed582cc5..6ff25881dc 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py @@ -60,9 +60,7 @@ def test_span_succeeded(self): self.assertEqual(span.attributes["db.user"], "testuser") self.assertEqual(span.attributes["net.peer.name"], "testhost") self.assertEqual(span.attributes["net.peer.port"], 123) - self.assertIs( - span.status.status_code, trace_api.status.StatusCode.UNSET - ) + self.assertIs(span.status.status_code, trace_api.StatusCode.UNSET) def test_span_name(self): db_integration = dbapi.DatabaseApiIntegration( @@ -125,9 +123,7 @@ def test_span_succeeded_with_capture_of_statement_parameters(self): self.assertEqual(span.attributes["db.user"], "testuser") self.assertEqual(span.attributes["net.peer.name"], "testhost") self.assertEqual(span.attributes["net.peer.port"], 123) - self.assertIs( - span.status.status_code, trace_api.status.StatusCode.UNSET - ) + self.assertIs(span.status.status_code, trace_api.StatusCode.UNSET) def test_span_not_recording(self): connection_props = { @@ -174,9 +170,7 @@ def test_span_failed(self): self.assertEqual(len(spans_list), 1) span = spans_list[0] self.assertEqual(span.attributes["db.statement"], "Test query") - self.assertIs( - span.status.status_code, trace_api.status.StatusCode.ERROR - ) + self.assertIs(span.status.status_code, trace_api.StatusCode.ERROR) self.assertEqual(span.status.description, "Exception: Test Exception") def test_executemany(self): diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index a2cdfd728e..154e68bc15 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -24,8 +24,7 @@ from opentelemetry.instrumentation.django import DjangoInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.trace import SpanKind -from opentelemetry.trace.status import StatusCode +from opentelemetry.trace import SpanKind, StatusCode from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs # pylint: disable=import-error diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 018b5b2322..885ce70039 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -28,7 +28,7 @@ ElasticsearchInstrumentor, ) from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCode +from opentelemetry.trace import StatusCode major_version = elasticsearch.VERSION[0] diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index a6e6651d22..1b68c3d075 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 StatusCode +from opentelemetry.trace import StatusCode from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs from .app import make_app diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py index 41a27e1c27..8ee938c587 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py @@ -152,7 +152,7 @@ def test_error_simple(self): self.assertEqual(len(spans), 1) span = spans[0] self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) def test_error_stream_unary(self): @@ -163,7 +163,7 @@ def test_error_stream_unary(self): self.assertEqual(len(spans), 1) span = spans[0] self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) def test_error_unary_stream(self): @@ -174,7 +174,7 @@ def test_error_unary_stream(self): self.assertEqual(len(spans), 1) span = spans[0] self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) def test_error_stream_stream(self): @@ -185,5 +185,5 @@ def test_error_stream_stream(self): self.assertEqual(len(spans), 1) span = spans[0] self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py index 86c7136c89..83305cab27 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py @@ -28,7 +28,7 @@ ) from opentelemetry.sdk import trace as trace_sdk from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCode +from opentelemetry.trace import StatusCode from .protobuf.test_server_pb2 import Request, Response from .protobuf.test_server_pb2_grpc import ( diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py index 6db6978a71..d18cbad2e4 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py @@ -66,9 +66,7 @@ def test_succeeded(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertIs( - span.status.status_code, trace_api.status.StatusCode.UNSET - ) + self.assertIs(span.status.status_code, trace_api.StatusCode.UNSET) self.assertIsNotNone(span.end_time) def test_not_recording(self): @@ -96,7 +94,7 @@ def test_failed(self): span = spans_list[0] self.assertIs( - span.status.status_code, trace_api.status.StatusCode.ERROR, + span.status.status_code, trace_api.StatusCode.ERROR, ) self.assertEqual(span.status.description, "failure") self.assertIsNotNone(span.end_time) @@ -116,10 +114,10 @@ def test_multiple_commands(self): second_span = spans_list[1] self.assertIs( - first_span.status.status_code, trace_api.status.StatusCode.UNSET, + first_span.status.status_code, trace_api.StatusCode.UNSET, ) self.assertIs( - second_span.status.status_code, trace_api.status.StatusCode.ERROR, + second_span.status.status_code, trace_api.StatusCode.ERROR, ) def test_int_command(self): diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index aed47238fb..ecc56b7c54 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 import resources from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCode +from opentelemetry.trace import StatusCode class InvalidResponseObjectException(Exception): @@ -86,7 +86,7 @@ def test_basic(self): }, ) - self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) + self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.check_span_instrumentation_info( span, opentelemetry.instrumentation.requests @@ -130,7 +130,7 @@ def test_not_foundbasic(self): self.assertEqual(span.attributes.get("http.status_text"), "Not Found") self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) def test_uninstrument(self): diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py index 5e4e97885f..e5a1092689 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py @@ -32,7 +32,7 @@ from opentelemetry.sdk import resources from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase -from opentelemetry.trace.status import StatusCode +from opentelemetry.trace import StatusCode class RequestsIntegrationTestBase(abc.ABC): @@ -111,7 +111,7 @@ def test_basic(self): }, ) - self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) + self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.check_span_instrumentation_info( span, opentelemetry.instrumentation.urllib @@ -161,7 +161,7 @@ def test_not_foundbasic(self): self.assertEqual(span.attributes.get("http.status_text"), "Not Found") self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) def test_uninstrument(self): diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index d86dadf2ba..3bfbe8c36c 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 StatusCode +from opentelemetry.trace import StatusCode class Response: 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 19364d7dfc..25e3b6a410 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 StatusCode +from opentelemetry.trace import StatusCode POSTGRES_HOST = os.getenv("POSTGRESQL_HOST", "localhost") POSTGRES_PORT = int(os.getenv("POSTGRESQL_PORT", "5432")) 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 d3b5353520..5195d88f5e 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 StatusCode +from opentelemetry.trace import StatusCode # set a high timeout for async executions due to issues in CI ASYNC_GET_TIMEOUT = 120 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 ef9ea90f8c..eca14d6317 100644 --- a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py +++ b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py @@ -36,7 +36,7 @@ def tearDown(self): def _check_span(self, span, name): self.assertEqual(span.attributes["service"], self.test_service) self.assertEqual(span.name, name) - self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) + self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.assertEqual(span.attributes.get("db.name"), 0) self.assertEqual(span.attributes["net.peer.name"], "localhost") self.assertEqual(span.attributes["net.peer.ip"], 6379) @@ -130,7 +130,7 @@ def tearDown(self): def _check_span(self, span, name): self.assertEqual(span.name, name) - self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) + self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.assertEqual(span.attributes["net.peer.name"], "localhost") self.assertEqual(span.attributes["net.peer.ip"], 6379) self.assertEqual(span.attributes["db.redis.database_index"], 10) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py index 62e9b3622a..76707bb6da 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py @@ -114,7 +114,7 @@ def _check_span(self, span, name): name = "{0} {1}".format(name, self.SQL_DB) self.assertEqual(span.name, name) self.assertEqual(span.attributes.get(_DB), self.SQL_DB) - self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) + self.assertIs(span.status.status_code, trace.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 ac5b8f9389..92fe2010de 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py @@ -65,5 +65,5 @@ def test_engine_traced(self): span = traces[0] # check subset of span fields self.assertEqual(span.name, "SELECT opentelemetry-tests") - self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) + self.assertIs(span.status.status_code, trace.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 31942dd582..eb3a99f16c 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py @@ -76,6 +76,6 @@ def test_engine_execute_errors(self): self.assertTrue(span.end_time - span.start_time > 0) # check the error self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.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 f9c38b1511..ab14612db9 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py @@ -74,7 +74,7 @@ def test_engine_execute_errors(self): self.assertTrue(span.end_time - span.start_time > 0) # check the error self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.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 2f64642486..2b00b4a078 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py @@ -51,7 +51,7 @@ def test_engine_execute_errors(self): self.assertTrue((span.end_time - span.start_time) > 0) # check the error self.assertIs( - span.status.status_code, trace.status.StatusCode.ERROR, + span.status.status_code, trace.StatusCode.ERROR, ) self.assertEqual( span.status.description, "no such table: a_wrong_table"