From ffc2a2ff4cc14686414ebe093478e4d8ca1bcc52 Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Tue, 31 Aug 2021 02:16:18 +0530 Subject: [PATCH 01/10] More consistent assertion methods (#641) * More consistent assertion methods * Updated core SHA --- .github/workflows/test.yml | 2 +- .../tests/test_aiopg_integration.py | 8 ++--- .../tests/test_botocore_instrumentation.py | 26 +++++++------- .../tests/test_tasks.py | 4 +-- .../tests/test_elasticsearch.py | 8 ++--- .../tests/test_falcon.py | 6 ++-- .../tests/test_fastapi_instrumentation.py | 2 +- .../tests/test_client_interceptor.py | 18 +++++----- .../tests/test_server_interceptor.py | 28 +++++++-------- .../tests/test_httpx_integration.py | 2 +- .../tests/test_mysql_integration.py | 2 +- .../tests/test_psycopg2_integration.py | 2 +- .../tests/test_pymysql_integration.py | 2 +- .../tests/test_requests_integration.py | 2 +- .../tests/test_starlette_instrumentation.py | 2 +- .../tests/test_instrumentation.py | 36 +++++++++---------- .../tests/test_urllib_integration.py | 2 +- 17 files changed, 75 insertions(+), 77 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f311db2bc3..7851e2fe5a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 3e1c89bcae77c34b9750a1f00608a04a97921c51 + CORE_REPO_SHA: 9dc17e33bc083e38c1fd55b8ed6787caba8f54fe jobs: build: diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py index 24d2299166..155c9948a8 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py @@ -68,7 +68,7 @@ def test_instrumentor_connect(self): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.aiopg ) @@ -97,7 +97,7 @@ async def _ctx_manager_connect(): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.aiopg ) @@ -118,7 +118,7 @@ def test_instrumentor_create_pool(self): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.aiopg ) @@ -149,7 +149,7 @@ async def _ctx_manager_pool(): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.aiopg ) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index e77a255d13..a9d4eb2619 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -132,8 +132,8 @@ def test_s3_client(self): assert spans span = spans[0] self.assertEqual(len(spans), 2) - self.assertEqual( - span.attributes, + self.assertSpanHasAttributes( + span, { "aws.operation": "ListBuckets", "aws.region": "us-west-2", @@ -150,8 +150,8 @@ def test_s3_client(self): spans = self.memory_exporter.get_finished_spans() assert spans span = spans[2] - self.assertEqual( - span.attributes, + self.assertSpanHasAttributes( + span, { "aws.operation": "ListObjects", "aws.region": "us-west-2", @@ -175,9 +175,9 @@ def test_s3_put(self): spans = self.memory_exporter.get_finished_spans() assert spans self.assertEqual(len(spans), 3) - create_bucket_attributes = spans[0].attributes - self.assertEqual( - create_bucket_attributes, + create_span = spans[0] + self.assertSpanHasAttributes( + create_span, { "aws.operation": "CreateBucket", "aws.region": "us-west-2", @@ -186,9 +186,9 @@ def test_s3_put(self): SpanAttributes.HTTP_STATUS_CODE: 200, }, ) - put_object_attributes = spans[1].attributes - self.assertEqual( - put_object_attributes, + put_span = spans[1] + self.assertSpanHasAttributes( + put_span, { "aws.operation": "PutObject", "aws.region": "us-west-2", @@ -198,9 +198,9 @@ def test_s3_put(self): }, ) self.assertTrue("params.Body" not in spans[1].attributes.keys()) - get_object_attributes = spans[2].attributes - self.assertEqual( - get_object_attributes, + get_span = spans[2] + self.assertSpanHasAttributes( + get_span, { "aws.operation": "GetObject", "aws.region": "us-west-2", diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py index 17538aaf5d..6b2ee9a94c 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py @@ -50,7 +50,7 @@ def test_task(self): self.assertEqual(consumer.name, "run/tests.celery_test_tasks.task_add") self.assertEqual(consumer.kind, SpanKind.CONSUMER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( consumer, { "celery.action": "run", @@ -64,7 +64,7 @@ def test_task(self): producer.name, "apply_async/tests.celery_test_tasks.task_add" ) self.assertEqual(producer.kind, SpanKind.PRODUCER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( producer, { "celery.action": "apply_async", diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 49301a061e..3b99238c60 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -77,8 +77,8 @@ def test_instrumentor(self, request_mock): span = spans_list[0] # Check version and name in span's instrumentation info - # self.check_span_instrumentation_info(span, opentelemetry.instrumentation.elasticsearch) - self.check_span_instrumentation_info( + # self.assertEqualSpanInstrumentationInfo(span, opentelemetry.instrumentation.elasticsearch) + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.elasticsearch ) @@ -289,7 +289,7 @@ def test_dsl_create(self, request_mock): "elasticsearch.url": "/test-index", "elasticsearch.method": "PUT", } - self.assert_span_has_attributes(span2, attributes) + self.assertSpanHasAttributes(span2, attributes) self.assertEqual( literal_eval(span2.attributes[SpanAttributes.DB_STATEMENT]), helpers.dsl_create_statement, @@ -315,7 +315,7 @@ def test_dsl_index(self, request_mock): "elasticsearch.url": helpers.dsl_index_url, "elasticsearch.method": "PUT", } - self.assert_span_has_attributes(span, attributes) + self.assertSpanHasAttributes(span, attributes) self.assertEqual( literal_eval(span.attributes[SpanAttributes.DB_STATEMENT]), { diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index 079923d11a..db32d157a7 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -103,7 +103,7 @@ def _test_method(self, method): span.name, "HelloWorldResource.on_{0}".format(method.lower()) ) self.assertEqual(span.status.status_code, StatusCode.UNSET) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.HTTP_METHOD: method, @@ -128,7 +128,7 @@ def test_404(self): span = spans[0] self.assertEqual(span.name, "HTTP GET") self.assertEqual(span.status.status_code, StatusCode.ERROR) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.HTTP_METHOD: "GET", @@ -159,7 +159,7 @@ def test_500(self): span.status.description, "NameError: name 'non_existent_var' is not defined", ) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.HTTP_METHOD: "GET", diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py index 20de363bde..a11ffea33a 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py @@ -222,7 +222,7 @@ def client_response_hook(send_span, response): response_spans = spans[:2] for span in response_spans: self.assertEqual(span.name, "name from response hook") - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, {"attr-from-response-hook": "value"} ) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py index 0f30464744..e0970994e6 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py @@ -112,7 +112,7 @@ def test_unary_unary_future(self): self.assertIs(span.kind, trace.SpanKind.CLIENT) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) @@ -126,11 +126,11 @@ def test_unary_unary(self): self.assertIs(span.kind, trace.SpanKind.CLIENT) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.RPC_METHOD: "SimpleMethod", @@ -152,11 +152,11 @@ def test_unary_stream(self): self.assertIs(span.kind, trace.SpanKind.CLIENT) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.RPC_METHOD: "ServerStreamingMethod", @@ -178,11 +178,11 @@ def test_stream_unary(self): self.assertIs(span.kind, trace.SpanKind.CLIENT) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.RPC_METHOD: "ClientStreamingMethod", @@ -206,11 +206,11 @@ def test_stream_stream(self): self.assertIs(span.kind, trace.SpanKind.CLIENT) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.RPC_METHOD: "BidirectionalStreamingMethod", diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py index c6151a04c3..23a6f148e1 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py @@ -106,12 +106,12 @@ def handler(request, context): self.assertIs(span.kind, trace.SpanKind.SERVER) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) # Check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -187,12 +187,12 @@ def test_create_span(self): self.assertIs(span.kind, trace.SpanKind.SERVER) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) # Check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -257,12 +257,12 @@ def SimpleMethod(self, request, context): self.assertIs(parent_span.kind, trace.SpanKind.SERVER) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( parent_span, opentelemetry.instrumentation.grpc ) # Check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( parent_span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -317,12 +317,12 @@ def test_create_span_streaming(self): self.assertIs(span.kind, trace.SpanKind.SERVER) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) # Check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -386,12 +386,12 @@ def ServerStreamingMethod(self, request, context): self.assertIs(parent_span.kind, trace.SpanKind.SERVER) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( parent_span, opentelemetry.instrumentation.grpc ) # Check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( parent_span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -490,7 +490,7 @@ def handler(request, context): self.assertIsNone(span2.parent) # check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -562,7 +562,7 @@ def handler(request, context): self.assertIsNone(span2.parent) # check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.NET_PEER_IP: "[::1]", @@ -617,7 +617,7 @@ def handler(request, context): self.assertIs(span.kind, trace.SpanKind.SERVER) # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.grpc ) @@ -631,7 +631,7 @@ def handler(request, context): ) # Check attributes - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, { SpanAttributes.NET_PEER_IP: "[::1]", diff --git a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py index c092c46626..1eacad500d 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py @@ -153,7 +153,7 @@ def test_basic(self): self.assertIs(span.status.status_code, trace.StatusCode.UNSET) - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.httpx ) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 6c114d969f..fc45b72b46 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -43,7 +43,7 @@ def test_instrumentor(self, mock_connect): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.mysql ) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index 8219e2a6b5..d20cc41348 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -100,7 +100,7 @@ def test_instrumentor(self): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.psycopg2 ) diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/tests/test_pymysql_integration.py b/instrumentation/opentelemetry-instrumentation-pymysql/tests/test_pymysql_integration.py index 35c9f4d32b..587ebc1b53 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/tests/test_pymysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-pymysql/tests/test_pymysql_integration.py @@ -43,7 +43,7 @@ def test_instrumentor(self, mock_connect): span = spans_list[0] # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.pymysql ) diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index db9a5e7625..f9a539773e 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -109,7 +109,7 @@ def test_basic(self): self.assertIs(span.status.status_code, trace.StatusCode.UNSET) - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.requests ) diff --git a/instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py b/instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py index 8f9f20498c..14175f9075 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py @@ -153,7 +153,7 @@ def client_response_hook(send_span, response): response_spans = spans[:2] for span in response_spans: self.assertEqual(span.name, "name from response hook") - self.assert_span_has_attributes( + self.assertSpanHasAttributes( span, {"attr-from-response-hook": "value"} ) diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 25b72f1630..5ddece4395 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -135,7 +135,7 @@ def _test_http_method_call(self, method): self.assertEqual(server.parent.span_id, client.context.span_id) self.assertEqual(server.context.trace_id, client.context.trace_id) self.assertEqual(server.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server, { SpanAttributes.HTTP_METHOD: method, @@ -152,7 +152,7 @@ def _test_http_method_call(self, method): self.assertFalse(client.context.is_remote) self.assertIsNone(client.parent) self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url("/"), @@ -208,7 +208,7 @@ def _test_async_handler(self, url, handler_name): self.assertEqual(server.parent.span_id, client.context.span_id) self.assertEqual(server.context.trace_id, client.context.trace_id) self.assertEqual(server.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server, { SpanAttributes.HTTP_METHOD: "GET", @@ -225,7 +225,7 @@ def _test_async_handler(self, url, handler_name): self.assertFalse(client.context.is_remote) self.assertIsNone(client.parent) self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url(url), @@ -244,7 +244,7 @@ def test_500(self): self.assertEqual(server.name, "BadHandler.get") self.assertEqual(server.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server, { SpanAttributes.HTTP_METHOD: "GET", @@ -259,7 +259,7 @@ def test_500(self): self.assertEqual(client.name, "GET") self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url("/error"), @@ -278,7 +278,7 @@ def test_404(self): self.assertEqual(server.name, "ErrorHandler.get") self.assertEqual(server.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server, { SpanAttributes.HTTP_METHOD: "GET", @@ -293,7 +293,7 @@ def test_404(self): self.assertEqual(client.name, "GET") self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url("/missing-url"), @@ -322,7 +322,7 @@ def test_dynamic_handler(self): self.assertEqual(server.parent.span_id, client.context.span_id) self.assertEqual(server.context.trace_id, client.context.trace_id) self.assertEqual(server.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server, { SpanAttributes.HTTP_METHOD: "GET", @@ -339,7 +339,7 @@ def test_dynamic_handler(self): self.assertFalse(client.context.is_remote) self.assertIsNone(client.parent) self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url("/dyna"), @@ -363,7 +363,7 @@ def test_handler_on_finish(self): self.assertEqual(server.parent.span_id, client.context.span_id) self.assertEqual(server.context.trace_id, client.context.trace_id) self.assertEqual(server.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server, { SpanAttributes.HTTP_METHOD: "GET", @@ -380,7 +380,7 @@ def test_handler_on_finish(self): self.assertFalse(client.context.is_remote) self.assertIsNone(client.parent) self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url("/on_finish"), @@ -406,7 +406,7 @@ def test_excluded(path): client = spans[0] self.assertEqual(client.name, "GET") self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: self.get_url(path), @@ -425,7 +425,7 @@ def test_traced_attrs(self): self.assertEqual(len(spans), 2) server_span = spans[0] self.assertEqual(server_span.kind, SpanKind.SERVER) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( server_span, {"uri": "/pong?q=abc&b=123", "query": "q=abc&b=123"} ) self.memory_exporter.clear() @@ -468,7 +468,7 @@ def test_credential_removal(self): self.assertEqual(client.name, "GET") self.assertEqual(client.kind, SpanKind.CLIENT) - self.assert_span_has_attributes( + self.assertSpanHasAttributes( client, { SpanAttributes.HTTP_URL: "http://httpbin.org/status/200", @@ -520,15 +520,13 @@ def client_response_hook(span, response): server_span = spans[1] self.assertEqual(server_span.kind, SpanKind.SERVER) self.assertEqual(server_span.name, "name from server hook") - self.assert_span_has_attributes(server_span, {"uri": "/"}) + self.assertSpanHasAttributes(server_span, {"uri": "/"}) self.memory_exporter.clear() client_span = spans[2] self.assertEqual(client_span.kind, SpanKind.CLIENT) self.assertEqual(client_span.name, "name from client hook") - self.assert_span_has_attributes( - client_span, {"attr-from-hook": "value"} - ) + self.assertSpanHasAttributes(client_span, {"attr-from-hook": "value"}) self.memory_exporter.clear() diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py index 52795270bd..f037cc61bd 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py @@ -115,7 +115,7 @@ def test_basic(self): self.assertIs(span.status.status_code, trace.StatusCode.UNSET) - self.check_span_instrumentation_info( + self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.urllib ) From c279ee59a899465043dff4a4310082c726702f62 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 31 Aug 2021 00:17:58 +0200 Subject: [PATCH 02/10] Rerun a flaky test (#639) * Rerun a flaky test --- .../tests/celery/test_celery_functional.py | 15 +++++++++------ tox.ini | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) 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 45ffbbe389..c85952aa7d 100644 --- a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py +++ b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py @@ -14,8 +14,9 @@ import celery -import pytest from celery.exceptions import Retry +from flaky import flaky +from pytest import mark import opentelemetry.instrumentation.celery from opentelemetry import trace as trace_api @@ -33,7 +34,7 @@ class MyException(Exception): pass -@pytest.mark.skip(reason="inconsistent test results") +@mark.skip(reason="inconsistent test results") def test_instrumentation_info(celery_app, memory_exporter): @celery_app.task def fn_task(): @@ -143,7 +144,7 @@ def fn_task(self): assert span.attributes.get("celery.state") == "SUCCESS" -@pytest.mark.skip(reason="inconsistent test results") +@mark.skip(reason="inconsistent test results") def test_fn_task_apply_async(celery_app, memory_exporter): @celery_app.task def fn_task_parameters(user, force_logout=False): @@ -190,7 +191,7 @@ def fn_task_parameters(user, force_logout=False): ) -@pytest.mark.skip(reason="inconsistent test results") +@mark.skip(reason="inconsistent test results") def test_concurrent_delays(celery_app, memory_exporter): @celery_app.task def fn_task(): @@ -206,7 +207,7 @@ def fn_task(): assert len(spans) == 200 -@pytest.mark.skip(reason="inconsistent test results") +@mark.skip(reason="inconsistent test results") def test_fn_task_delay(celery_app, memory_exporter): @celery_app.task def fn_task_parameters(user, force_logout=False): @@ -476,7 +477,7 @@ def add(x, y): ) -@pytest.mark.skip(reason="inconsistent test results") +@mark.skip(reason="inconsistent test results") def test_apply_async_previous_style_tasks( celery_app, celery_worker, memory_exporter ): @@ -558,6 +559,8 @@ class CelerySubClass(CelerySuperClass): ) == async_run_span.attributes.get(SpanAttributes.MESSAGING_MESSAGE_ID) +# FIXME find a permanent solution for the flakiness of this test +@flaky def test_custom_tracer_provider(celery_app, memory_exporter): @celery_app.task def fn_task(): diff --git a/tox.ini b/tox.ini index 50fca6d6b8..70a8968607 100644 --- a/tox.ini +++ b/tox.ini @@ -408,6 +408,7 @@ deps = protobuf>=3.13.0 requests==2.25.0 pyodbc~=4.0.30 + flaky==3.7.0 changedir = tests/opentelemetry-docker-tests/tests From cc57aacd71c3eff8fac4030ca3013546dd4e545a Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Wed, 1 Sep 2021 15:36:13 +0530 Subject: [PATCH 03/10] Improve reliability of tests (#643) * Run tests on Windows in Github Actions * core sha update * format code * fix ci yaml * rebase * lint * Try without win+py3.6 fix * Try without win+py3.6 fix * Improve test reliability Update some tests to use more deterministic methods of testing in memory spans. This helps the core repo pass tests after adding Windows to CI matrix. --- .github/workflows/test.yml | 2 +- .../tests/test_datadog_exporter.py | 5 ++ .../tests/test_botocore_instrumentation.py | 36 +++++++++----- .../tests/test_elasticsearch.py | 47 ++++++++----------- .../tests/test_instrumentation.py | 14 ++++-- tox.ini | 3 +- 6 files changed, 61 insertions(+), 46 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7851e2fe5a..2926a019aa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 9dc17e33bc083e38c1fd55b8ed6787caba8f54fe + CORE_REPO_SHA: c49ad57bfe35cfc69bfa863d74058ca9bec55fc3 jobs: build: diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py index c6fe2fc27a..7d44f734e7 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py @@ -14,12 +14,14 @@ import itertools import logging +import sys import time import unittest from unittest import mock from ddtrace.internal.writer import AgentWriter from flaky import flaky +from pytest import mark from opentelemetry import trace as trace_api from opentelemetry.context import Context @@ -469,6 +471,9 @@ def test_span_processor_dropped_spans(self): self.assertEqual(len(datadog_spans), 128) tracer_provider.shutdown() + @mark.skipif( + sys.platform == "win32", reason="unreliable test on windows", + ) def test_span_processor_scheduled_delay(self): """Test that spans are exported each schedule_delay_millis""" delay = 300 diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index a9d4eb2619..fda6220ca0 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -13,6 +13,7 @@ # limitations under the License. import io import json +import sys import zipfile from unittest.mock import Mock, patch @@ -30,6 +31,7 @@ mock_sts, mock_xray, ) +from pytest import mark from opentelemetry import trace as trace_api from opentelemetry.context import attach, detach, set_value @@ -128,12 +130,13 @@ def test_s3_client(self): s3.list_buckets() s3.list_buckets() - spans = self.memory_exporter.get_finished_spans() + spans = self.get_finished_spans() assert spans - span = spans[0] self.assertEqual(len(spans), 2) + + buckets_span = spans.by_attr("aws.operation", "ListBuckets") self.assertSpanHasAttributes( - span, + buckets_span, { "aws.operation": "ListBuckets", "aws.region": "us-west-2", @@ -144,14 +147,13 @@ def test_s3_client(self): ) # testing for span error - self.memory_exporter.get_finished_spans() with self.assertRaises(ParamValidationError): s3.list_objects(bucket="mybucket") - spans = self.memory_exporter.get_finished_spans() + spans = self.get_finished_spans() assert spans - span = spans[2] + objects_span = spans.by_attr("aws.operation", "ListObjects") self.assertSpanHasAttributes( - span, + objects_span, { "aws.operation": "ListObjects", "aws.region": "us-west-2", @@ -159,7 +161,7 @@ def test_s3_client(self): }, ) self.assertIs( - span.status.status_code, trace_api.StatusCode.ERROR, + objects_span.status.status_code, trace_api.StatusCode.ERROR, ) # Comment test for issue 1088 @@ -172,10 +174,11 @@ def test_s3_put(self): s3.put_object(**params) s3.get_object(Bucket="mybucket", Key="foo") - spans = self.memory_exporter.get_finished_spans() + spans = self.get_finished_spans() assert spans self.assertEqual(len(spans), 3) - create_span = spans[0] + + create_span = spans.by_attr("aws.operation", "CreateBucket") self.assertSpanHasAttributes( create_span, { @@ -186,7 +189,8 @@ def test_s3_put(self): SpanAttributes.HTTP_STATUS_CODE: 200, }, ) - put_span = spans[1] + + put_span = spans.by_attr("aws.operation", "PutObject") self.assertSpanHasAttributes( put_span, { @@ -197,8 +201,10 @@ def test_s3_put(self): SpanAttributes.HTTP_STATUS_CODE: 200, }, ) - self.assertTrue("params.Body" not in spans[1].attributes.keys()) - get_span = spans[2] + self.assertTrue("params.Body" not in put_span.attributes.keys()) + + get_span = spans.by_attr("aws.operation", "GetObject") + self.assertSpanHasAttributes( get_span, { @@ -359,6 +365,10 @@ def get_role_name(self): Path="/my-path/", )["Role"]["Arn"] + @mark.skipif( + sys.platform == "win32", + reason="requires docker and Github CI Windows does not have docker installed by default", + ) @mock_lambda def test_lambda_invoke_propagation(self): diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 3b99238c60..f2eaf509a5 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -60,19 +60,13 @@ def tearDown(self): with self.disable_logging(): ElasticsearchInstrumentor().uninstrument() - def get_ordered_finished_spans(self): - return sorted( - self.memory_exporter.get_finished_spans(), - key=lambda s: s.start_time, - ) - def test_instrumentor(self, request_mock): request_mock.return_value = (1, {}, {}) es = Elasticsearch() es.index(index="sw", doc_type="people", id=1, body={"name": "adam"}) - spans_list = self.get_ordered_finished_spans() + spans_list = self.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] @@ -87,7 +81,7 @@ def test_instrumentor(self, request_mock): es.index(index="sw", doc_type="people", id=1, body={"name": "adam"}) - spans_list = self.get_ordered_finished_spans() + spans_list = self.get_finished_spans() self.assertEqual(len(spans_list), 1) def test_span_not_recording(self, request_mock): @@ -127,7 +121,7 @@ def _test_prefix(self, prefix): es = Elasticsearch() es.index(index="sw", doc_type="people", id=1, body={"name": "adam"}) - spans_list = self.get_ordered_finished_spans() + spans_list = self.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] self.assertTrue(span.name.startswith(prefix)) @@ -141,7 +135,7 @@ def test_result_values(self, request_mock): es = Elasticsearch() es.get(index="test-index", doc_type="tweet", id=1) - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() self.assertEqual(1, len(spans)) self.assertEqual("False", spans[0].attributes["elasticsearch.found"]) @@ -169,7 +163,7 @@ def _test_trace_error(self, code, exc): except Exception: # pylint: disable=broad-except pass - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() self.assertEqual(1, len(spans)) span = spans[0] self.assertFalse(span.status.is_ok) @@ -186,13 +180,13 @@ def test_parent(self, request_mock): index="sw", doc_type="people", id=1, body={"name": "adam"} ) - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() self.assertEqual(len(spans), 2) - self.assertEqual(spans[0].name, "parent") - self.assertEqual(spans[1].name, "Elasticsearch/sw/people/1") - self.assertIsNotNone(spans[1].parent) - self.assertEqual(spans[1].parent.span_id, spans[0].context.span_id) + parent = spans.by_name("parent") + child = spans.by_name("Elasticsearch/sw/people/1") + self.assertIsNotNone(child.parent) + self.assertEqual(child.parent.span_id, parent.context.span_id) def test_multithread(self, request_mock): request_mock.return_value = (1, {}, {}) @@ -222,16 +216,15 @@ def target2(): t1.join() t2.join() - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() self.assertEqual(3, len(spans)) - s1, s2, s3 = spans - self.assertEqual(s1.name, "parent") + s1 = spans.by_name("parent") + s2 = spans.by_name("Elasticsearch/test-index/tweet/1") + s3 = spans.by_name("Elasticsearch/test-index/tweet/2") - self.assertEqual(s2.name, "Elasticsearch/test-index/tweet/1") self.assertIsNotNone(s2.parent) self.assertEqual(s2.parent.span_id, s1.context.span_id) - self.assertEqual(s3.name, "Elasticsearch/test-index/tweet/2") self.assertIsNone(s3.parent) def test_dsl_search(self, request_mock): @@ -242,7 +235,7 @@ def test_dsl_search(self, request_mock): "term", author="testing" ) search.execute() - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() span = spans[0] self.assertEqual(1, len(spans)) self.assertEqual(span.name, "Elasticsearch/test-index/_search") @@ -270,10 +263,11 @@ def test_dsl_create(self, request_mock): client = Elasticsearch() Article.init(using=client) - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() self.assertEqual(2, len(spans)) - span1, span2 = spans - self.assertEqual(span1.name, "Elasticsearch/test-index") + span1 = spans.by_attr(key="elasticsearch.method", value="HEAD") + span2 = spans.by_attr(key="elasticsearch.method", value="PUT") + self.assertEqual( span1.attributes, { @@ -283,7 +277,6 @@ def test_dsl_create(self, request_mock): }, ) - self.assertEqual(span2.name, "Elasticsearch/test-index") attributes = { SpanAttributes.DB_SYSTEM: "elasticsearch", "elasticsearch.url": "/test-index", @@ -306,7 +299,7 @@ def test_dsl_index(self, request_mock): ) res = article.save(using=client) self.assertTrue(res) - spans = self.get_ordered_finished_spans() + spans = self.get_finished_spans() self.assertEqual(1, len(spans)) span = spans[0] self.assertEqual(span.name, helpers.dsl_index_span_name) diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 5ddece4395..249b730d24 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -185,15 +185,19 @@ def test_coroutine_handler(self): def _test_async_handler(self, url, handler_name): response = self.fetch(url) self.assertEqual(response.code, 201) - spans = self.memory_exporter.get_finished_spans() + spans = self.get_finished_spans() self.assertEqual(len(spans), 5) - sub2, sub1, sub_wrapper, server, client = self.sorted_spans(spans) + client = spans.by_name("GET") + server = spans.by_name(handler_name + ".get") + sub_wrapper = spans.by_name("sub-task-wrapper") + sub2 = spans.by_name("sub-task-2") self.assertEqual(sub2.name, "sub-task-2") self.assertEqual(sub2.parent, sub_wrapper.context) self.assertEqual(sub2.context.trace_id, client.context.trace_id) + sub1 = spans.by_name("sub-task-1") self.assertEqual(sub1.name, "sub-task-1") self.assertEqual(sub1.parent, sub_wrapper.context) self.assertEqual(sub1.context.trace_id, client.context.trace_id) @@ -238,9 +242,11 @@ def test_500(self): response = self.fetch("/error") self.assertEqual(response.code, 500) - spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + spans = self.get_finished_spans() self.assertEqual(len(spans), 2) - server, client = spans + + client = spans.by_name("GET") + server = spans.by_name("BadHandler.get") self.assertEqual(server.name, "BadHandler.get") self.assertEqual(server.kind, SpanKind.SERVER) diff --git a/tox.ini b/tox.ini index 70a8968607..5c20828a33 100644 --- a/tox.ini +++ b/tox.ini @@ -122,7 +122,8 @@ envlist = py3{6,7,8,9}-test-instrumentation-grpc ; opentelemetry-instrumentation-sqlalchemy - py3{6,7,8,9}-test-instrumentation-sqlalchemy{11,14} + py3{6,7}-test-instrumentation-sqlalchemy{11} + py3{6,7,8,9}-test-instrumentation-sqlalchemy{14} pypy3-test-instrumentation-sqlalchemy{11,14} ; opentelemetry-instrumentation-redis From b6e49ba66d70998813766d763bdb08f453829518 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 1 Sep 2021 19:38:02 +0200 Subject: [PATCH 04/10] Remove unused imports (#646) * Remove unused imports Fixes #645 * Fix lint * Import trace_tween_factory * Fix lint * Fix lint * Fix pylint * Try without using the symbol * Fix isort * Revert "Fix isort" This reverts commit 4dbd91450b4ee099fd09ab1ca0fb8ae9c10bdcfa. * Revert "Try without using the symbol" This reverts commit d94f95564671a3155edf44bf71bf58f22ca309f0. --- .flake8 | 1 - .../opentelemetry/instrumentation/asyncpg/__init__.py | 1 - .../src/opentelemetry/instrumentation/boto/__init__.py | 1 - .../src/opentelemetry/instrumentation/dbapi/__init__.py | 1 - .../opentelemetry/instrumentation/django/middleware.py | 1 - .../instrumentation/elasticsearch/__init__.py | 1 - .../opentelemetry/instrumentation/fastapi/__init__.py | 1 - .../src/opentelemetry/instrumentation/httpx/__init__.py | 8 ++------ .../src/opentelemetry/instrumentation/jinja2/__init__.py | 1 - .../src/opentelemetry/instrumentation/mysql/__init__.py | 1 - .../opentelemetry/instrumentation/pymemcache/__init__.py | 7 +------ .../opentelemetry/instrumentation/pymongo/__init__.py | 1 - .../opentelemetry/instrumentation/pyramid/__init__.py | 9 +++++---- .../src/opentelemetry/instrumentation/redis/__init__.py | 2 +- .../opentelemetry/instrumentation/sqlite3/__init__.py | 1 - .../tests/sqlalchemy_tests/mixins.py | 3 +-- .../tests/sqlalchemy_tests/test_instrument.py | 1 - .../tests/sqlalchemy_tests/test_mssql.py | 1 - .../tests/sqlalchemy_tests/test_mysql.py | 1 - .../tests/sqlalchemy_tests/test_postgres.py | 1 - .../tests/sqlalchemy_tests/test_sqlite.py | 2 -- 21 files changed, 10 insertions(+), 36 deletions(-) diff --git a/.flake8 b/.flake8 index c036b3fbad..e1a2de4f93 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,6 @@ [flake8] ignore = E501 # line too long, defer to black - F401 # unused import, defer to pylint W503 # allow line breaks before binary ops W504 # allow line breaks after binary ops E203 # allow whitespace before ':' (https://github.com/psf/black#slices) 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 21646d398a..b66168f4d0 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py @@ -38,7 +38,6 @@ import asyncpg import wrapt -from asyncpg import exceptions from opentelemetry import trace from opentelemetry.instrumentation.asyncpg.package import _instruments diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py index c5b0935413..02e04ffa80 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py @@ -52,7 +52,6 @@ from opentelemetry.instrumentation.boto.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap -from opentelemetry.sdk.trace import Resource from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, get_tracer 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 b7ce6d13b6..762d2904d2 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -48,7 +48,6 @@ from opentelemetry.instrumentation.utils import unwrap from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, TracerProvider, get_tracer -from opentelemetry.trace.status import Status, StatusCode logger = logging.getLogger(__name__) diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py index 7fcd3dd158..3138c3f95c 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -20,7 +20,6 @@ from django.http import HttpRequest, HttpResponse from opentelemetry.context import attach, detach -from opentelemetry.instrumentation.django.version import __version__ from opentelemetry.instrumentation.propagators import ( get_global_response_propagator, ) 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 bb620c644e..f72a4bffa2 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py @@ -60,7 +60,6 @@ from opentelemetry.instrumentation.utils import unwrap from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, get_tracer -from opentelemetry.trace.status import Status, StatusCode logger = getLogger(__name__) diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py index 2bac52d072..3851e3c10b 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py @@ -17,7 +17,6 @@ from typing import Collection import fastapi -from starlette import middleware from starlette.routing import Match from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware diff --git a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py index 90d077027c..5dd39473ec 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py @@ -16,19 +16,15 @@ import typing import httpx -import wrapt from opentelemetry import context from opentelemetry.instrumentation.httpx.package import _instruments from opentelemetry.instrumentation.httpx.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor -from opentelemetry.instrumentation.utils import ( - http_status_to_status_code, - unwrap, -) +from opentelemetry.instrumentation.utils import http_status_to_status_code from opentelemetry.propagate import inject from opentelemetry.semconv.trace import SpanAttributes -from opentelemetry.trace import SpanKind, Tracer, TracerProvider, get_tracer +from opentelemetry.trace import SpanKind, TracerProvider, get_tracer from opentelemetry.trace.span import Span from opentelemetry.trace.status import Status 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 bcbd42fb86..6076d512a3 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/__init__.py @@ -43,7 +43,6 @@ from typing import Collection import jinja2 -from wrapt import ObjectProxy from wrapt import wrap_function_wrapper as _wrap from opentelemetry.instrumentation.instrumentor import BaseInstrumentor diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index 12798a61f5..4549d10150 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -46,7 +46,6 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.mysql.package import _instruments from opentelemetry.instrumentation.mysql.version import __version__ -from opentelemetry.trace import get_tracer class MySQLInstrumentor(BaseInstrumentor): diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py index 21dab059d4..47f70b9e58 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py @@ -41,18 +41,13 @@ from typing import Collection import pymemcache -from wrapt import ObjectProxy from wrapt import wrap_function_wrapper as _wrap from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.pymemcache.package import _instruments from opentelemetry.instrumentation.pymemcache.version import __version__ from opentelemetry.instrumentation.utils import unwrap -from opentelemetry.semconv.trace import ( - DbSystemValues, - NetTransportValues, - SpanAttributes, -) +from opentelemetry.semconv.trace import NetTransportValues, SpanAttributes from opentelemetry.trace import SpanKind, get_tracer logger = logging.getLogger(__name__) 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 f368320abc..69b26414d8 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -41,7 +41,6 @@ from pymongo import monitoring -from opentelemetry import trace from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.pymongo.package import _instruments from opentelemetry.instrumentation.pymongo.version import __version__ diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py index 401b6bb3cf..7f7f88d03c 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py @@ -78,13 +78,11 @@ --- """ -import typing from typing import Collection from pyramid.config import Configurator from pyramid.path import caller_package from pyramid.settings import aslist -from wrapt import ObjectProxy from wrapt import wrap_function_wrapper as _wrap from opentelemetry.instrumentation.instrumentor import BaseInstrumentor @@ -94,9 +92,12 @@ trace_tween_factory, ) from opentelemetry.instrumentation.pyramid.package import _instruments -from opentelemetry.instrumentation.pyramid.version import __version__ from opentelemetry.instrumentation.utils import unwrap -from opentelemetry.trace import TracerProvider, get_tracer + +# test_automatic.TestAutomatic.test_tween_list needs trace_tween_factory to be +# imported in this module. The next line is necessary to avoid a lint error +# from importing an unused symbol. +trace_tween_factory # pylint: disable=pointless-statement def _traced_init(wrapped, instance, args, kwargs): diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py index 18599e714c..ea40307e21 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py @@ -45,7 +45,7 @@ from typing import Collection import redis -from wrapt import ObjectProxy, wrap_function_wrapper +from wrapt import wrap_function_wrapper from opentelemetry import trace from opentelemetry.instrumentation.instrumentor import BaseInstrumentor diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py index a0842214e5..3464f3cc48 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py @@ -46,7 +46,6 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.sqlite3.package import _instruments from opentelemetry.instrumentation.sqlite3.version import __version__ -from opentelemetry.trace import get_tracer # No useful attributes of sqlite3 connection object _CONNECTION_ATTRIBUTES = {} diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py index b9c766ad1c..df976e97a8 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py @@ -15,9 +15,8 @@ import contextlib import logging import threading -import unittest -from sqlalchemy import Column, Integer, String, create_engine, insert +from sqlalchemy import Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import close_all_sessions, scoped_session, sessionmaker 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 92fe2010de..8c97d100e0 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py @@ -13,7 +13,6 @@ # limitations under the License. import os -import unittest import sqlalchemy diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mssql.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mssql.py index ef9cac051a..bb49f55518 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mssql.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mssql.py @@ -13,7 +13,6 @@ # limitations under the License. import os -import unittest import pytest from sqlalchemy.exc import ProgrammingError 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 c9e0a8dd1e..e31f992ff8 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py @@ -13,7 +13,6 @@ # limitations under the License. import os -import unittest import pytest from sqlalchemy.exc import ProgrammingError 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 d72791d970..610f604e13 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py @@ -13,7 +13,6 @@ # limitations under the License. import os -import unittest import psycopg2 import pytest 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 0acba0fec2..821f25669d 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest - import pytest from sqlalchemy.exc import OperationalError From 2e77bfc55560690809841e52ebd538dd7dc79253 Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Thu, 2 Sep 2021 01:33:02 +0530 Subject: [PATCH 05/10] Added a script to generate readme file for root instrumentations (#647) directory This file lists down all instrumentations and the packages+versions they support. This is helpful to find out at a glance what is exactly supported. Co-authored-by: alrex --- instrumentation/README.md | 36 ++++++++++ scripts/generate_instrumentation_readme.py | 79 ++++++++++++++++++++++ tox.ini | 1 + 3 files changed, 116 insertions(+) create mode 100644 instrumentation/README.md create mode 100755 scripts/generate_instrumentation_readme.py diff --git a/instrumentation/README.md b/instrumentation/README.md new file mode 100644 index 0000000000..8c59661d55 --- /dev/null +++ b/instrumentation/README.md @@ -0,0 +1,36 @@ + +| Instrumentation | Supported Packages | +| --------------- | ------------------ | +| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | +| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | +| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | +| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | +| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 | +| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 | +| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | +| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | +| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | +| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | +| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon ~= 2.0 | +| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | +| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | +| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | +| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0, < 0.19.0 | +| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2~=2.7 | +| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | +| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | +| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | +| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache ~= 1.3 | +| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo ~= 3.1 | +| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL ~= 0.10.1 | +| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | +| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | +| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | +| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | +| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | +| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | +| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 | +| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 6.0 | +| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib | +| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 | +| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi | \ No newline at end of file diff --git a/scripts/generate_instrumentation_readme.py b/scripts/generate_instrumentation_readme.py new file mode 100755 index 0000000000..4eaa8c907d --- /dev/null +++ b/scripts/generate_instrumentation_readme.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +import os + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger("instrumentation_readme_generator") + +_prefix = "opentelemetry-instrumentation-" + +header = """ +| Instrumentation | Supported Packages | +| --------------- | ------------------ |""" + + +def main(): + root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + base_instrumentation_path = os.path.join(root_path, "instrumentation") + + table = [header] + for instrumentation in sorted(os.listdir(base_instrumentation_path)): + instrumentation_path = os.path.join( + base_instrumentation_path, instrumentation + ) + if not os.path.isdir( + instrumentation_path + ) or not instrumentation.startswith(_prefix): + continue + + src_dir = os.path.join( + instrumentation_path, "src", "opentelemetry", "instrumentation" + ) + src_pkgs = [ + f + for f in os.listdir(src_dir) + if os.path.isdir(os.path.join(src_dir, f)) + ] + assert len(src_pkgs) == 1 + name = src_pkgs[0] + + pkg_info = {} + version_filename = os.path.join(src_dir, name, "package.py",) + with open(version_filename, encoding="utf-8") as fh: + exec(fh.read(), pkg_info) + + instruments = pkg_info["_instruments"] + if not instruments: + instruments = (name,) + + table.append( + "| [{0}](./{0}) | {1} |".format( + instrumentation, ",".join(instruments) + ) + ) + + with open( + os.path.join(base_instrumentation_path, "README.md"), + "w", + encoding="utf-8", + ) as fh: + fh.write("\n".join(table)) + + +if __name__ == "__main__": + main() diff --git a/tox.ini b/tox.ini index 5c20828a33..0fab90b217 100644 --- a/tox.ini +++ b/tox.ini @@ -447,3 +447,4 @@ deps = commands = {toxinidir}/scripts/generate_setup.py {toxinidir}/scripts/generate_instrumentation_bootstrap.py + {toxinidir}/scripts/generate_instrumentation_readme.py From c4639ee3f5e60f2ae62ff9bb95a2bf775ea6d784 Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Thu, 2 Sep 2021 13:44:38 +0530 Subject: [PATCH 06/10] Fix flaky celery docker test (#652) The test was actually generating 2 spans but on very fast systems we only saw one as the test ran faster than the message would travel through the broker, trigger a task and generate 2nd span. Switched from .delay() to .apply() so only one span is generated which is enough for the test in question. --- .../tests/celery/test_celery_functional.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 c85952aa7d..0f707a4571 100644 --- a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py +++ b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py @@ -15,7 +15,6 @@ import celery from celery.exceptions import Retry -from flaky import flaky from pytest import mark import opentelemetry.instrumentation.celery @@ -559,8 +558,6 @@ class CelerySubClass(CelerySuperClass): ) == async_run_span.attributes.get(SpanAttributes.MESSAGING_MESSAGE_ID) -# FIXME find a permanent solution for the flakiness of this test -@flaky def test_custom_tracer_provider(celery_app, memory_exporter): @celery_app.task def fn_task(): @@ -576,7 +573,7 @@ def fn_task(): CeleryInstrumentor().uninstrument() CeleryInstrumentor().instrument(tracer_provider=tracer_provider) - fn_task.delay() + fn_task.apply() spans_list = memory_exporter.get_finished_spans() assert len(spans_list) == 1 From 65fb21ce3e015436b8f59a6e9a3a191a5a3354b3 Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Thu, 2 Sep 2021 17:16:09 +0530 Subject: [PATCH 07/10] Falcon: handle env vars locally vs globally (#650) All instrumentations read most env vars today at module level. This has a few disadvantages. - harder to test. - code executed on import even if instrumentation is not used. - forces to use global vars. This commit fixes the Falcon instrumentation to handle env vars locally during instrumentor initialization and considerably simplifies testing. Other instrumentations should receive similar treatment. --- .../instrumentation/falcon/__init__.py | 10 ++++--- .../tests/test_falcon.py | 27 ++++--------------- 2 files changed, 11 insertions(+), 26 deletions(-) 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 8d05ea73b3..c8a802fdfb 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -124,8 +124,6 @@ def response_hook(span, req, resp): _ENVIRON_EXC = "opentelemetry-falcon.exc" -_excluded_urls = get_excluded_urls("FALCON") -_traced_request_attrs = get_traced_request_attrs("FALCON") _response_propagation_setter = FuncSetter(falcon.Response.append_header) @@ -159,17 +157,21 @@ def __init__(self, *args, **kwargs): trace_middleware = _TraceMiddleware( self._tracer, - kwargs.pop("traced_request_attributes", _traced_request_attrs), + kwargs.pop( + "traced_request_attributes", get_traced_request_attrs("FALCON") + ), kwargs.pop("request_hook", None), kwargs.pop("response_hook", None), ) middlewares.insert(0, trace_middleware) kwargs["middleware"] = middlewares + + self._excluded_urls = get_excluded_urls("FALCON") super().__init__(*args, **kwargs) def __call__(self, env, start_response): # pylint: disable=E1101 - if _excluded_urls.url_disabled(env.get("PATH_INFO", "/")): + if self._excluded_urls.url_disabled(env.get("PATH_INFO", "/")): return super().__call__(env, start_response) start_time = _time_ns() diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index db32d157a7..4ffa4ee0bd 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -26,7 +26,6 @@ from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode, format_span_id, format_trace_id -from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs from .app import make_app @@ -34,12 +33,6 @@ class TestFalconBase(TestBase): def setUp(self): super().setUp() - FalconInstrumentor().instrument( - request_hook=getattr(self, "request_hook", None), - response_hook=getattr(self, "response_hook", None), - ) - self.app = make_app() - # pylint: disable=protected-access self.env_patch = patch.dict( "os.environ", { @@ -48,20 +41,12 @@ def setUp(self): }, ) self.env_patch.start() - self.exclude_patch = patch( - "opentelemetry.instrumentation.falcon._excluded_urls", - get_excluded_urls("FALCON"), - ) - middleware = self.app._middleware[0][ # pylint:disable=W0212 - 0 - ].__self__ - self.traced_patch = patch.object( - middleware, - "_traced_request_attrs", - get_traced_request_attrs("FALCON"), + + FalconInstrumentor().instrument( + request_hook=getattr(self, "request_hook", None), + response_hook=getattr(self, "response_hook", None), ) - self.exclude_patch.start() - self.traced_patch.start() + self.app = make_app() def client(self): return testing.TestClient(self.app) @@ -71,8 +56,6 @@ def tearDown(self): with self.disable_logging(): FalconInstrumentor().uninstrument() self.env_patch.stop() - self.exclude_patch.stop() - self.traced_patch.stop() class TestFalconInstrumentation(TestFalconBase): From 0d34ef26b75f9a3bc275bf828b5a806d39ba1a40 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Thu, 2 Sep 2021 12:50:16 -0700 Subject: [PATCH 08/10] Add component owner action (#655) --- .github/component_owners.yml | 4 ++++ .github/workflows/component-owners.yml | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .github/component_owners.yml create mode 100644 .github/workflows/component-owners.yml diff --git a/.github/component_owners.yml b/.github/component_owners.yml new file mode 100644 index 0000000000..6e2b6279ed --- /dev/null +++ b/.github/component_owners.yml @@ -0,0 +1,4 @@ +components: + + sdk-extension/opentelemetry-sdk-extension-aws: + - NathanielRN diff --git a/.github/workflows/component-owners.yml b/.github/workflows/component-owners.yml new file mode 100644 index 0000000000..22869fb533 --- /dev/null +++ b/.github/workflows/component-owners.yml @@ -0,0 +1,16 @@ +# This action assigns and requires approval from owners of components for +# PRs that are open against those components. Components are defined as +# individual paths within this repository. +name: 'Component Owners' + +on: + pull_request: + branches: + - main + +jobs: + run_self: + runs-on: ubuntu-latest + name: Auto Assign Owners + steps: + - uses: dyladan/component-owners@main From 0e5853b0c6bace4e3fe315a200397513e0882d4b Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 3 Sep 2021 10:16:55 -0700 Subject: [PATCH 09/10] Change action to address forks (#659) --- .github/workflows/component-owners.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/component-owners.yml b/.github/workflows/component-owners.yml index 22869fb533..035b650aaa 100644 --- a/.github/workflows/component-owners.yml +++ b/.github/workflows/component-owners.yml @@ -4,9 +4,7 @@ name: 'Component Owners' on: - pull_request: - branches: - - main + pull_request_target: jobs: run_self: From 984f5cd2d36634de7bd9876c69f6b3e19ae0c1bd Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 7 Sep 2021 14:47:38 -0700 Subject: [PATCH 10/10] Fix documentation for MySQL instrumentation (#665) --- .../src/opentelemetry/instrumentation/mysql/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index 4549d10150..a3fafb3d80 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -30,7 +30,7 @@ cnx = mysql.connector.connect(database="MySQL_Database") cursor = cnx.cursor() - cursor.execute("INSERT INTO test (testField) VALUES (123)" + cursor.execute("INSERT INTO test (testField) VALUES (123)") cursor.close() cnx.close()