From 288428e5af048f0aaea4d39f0b389776ebd92fa3 Mon Sep 17 00:00:00 2001 From: Naofumi MURATA <10278628+nao23@users.noreply.github.com> Date: Fri, 2 May 2025 23:23:32 +0900 Subject: [PATCH 1/4] respect supress_instrumentation --- .../instrumentation/dbapi/__init__.py | 4 ++++ .../tests/test_dbapi_integration.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) 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 f87401ff32..0d1a228be1 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -52,6 +52,7 @@ from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment from opentelemetry.instrumentation.utils import ( _get_opentelemetry_values, + is_instrumentation_enabled, unwrap, ) from opentelemetry.semconv.trace import SpanAttributes @@ -561,6 +562,9 @@ def traced_execution( *args: tuple[Any, ...], **kwargs: dict[Any, Any], ): + if not is_instrumentation_enabled(): + return query_method(*args, **kwargs) + name = self.get_operation_name(cursor, args) if not name: name = ( diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py index 3f30f3a897..9a7a4a7d12 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py @@ -21,6 +21,7 @@ from opentelemetry import context from opentelemetry import trace as trace_api from opentelemetry.instrumentation import dbapi +from opentelemetry.instrumentation.utils import suppress_instrumentation from opentelemetry.sdk import resources from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.test.test_base import TestBase @@ -243,6 +244,21 @@ def test_no_op_tracer_provider(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 0) + def test_suppress_instrumentation(self): + db_integration = dbapi.DatabaseApiIntegration( + "instrumenting_module_test_name", + "testcomponent", + ) + mock_connection = db_integration.wrapped_connection( + mock_connect, {}, {} + ) + with suppress_instrumentation(): + cursor = mock_connection.cursor() + cursor.execute("Test query", ("param1Value", False)) + + spans_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans_list), 0) + def test_executemany(self): db_integration = dbapi.DatabaseApiIntegration( "instrumenting_module_test_name", "testcomponent" From 2aa20ea2b02f2e330348b439ab093ee785e19ce5 Mon Sep 17 00:00:00 2001 From: Naofumi MURATA <10278628+nao23@users.noreply.github.com> Date: Tue, 6 May 2025 01:29:28 +0900 Subject: [PATCH 2/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc9c6e01c8..db2c786ae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3447](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3447)) - `opentelemetry-instrumentation-botocore` Capture server attributes for botocore API calls ([#3448](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3448)) +- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3459](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3459)) ## Version 1.32.0/0.53b0 (2025-04-10) From 152eda09d1679941ace01ef507cf4ba21acb7ab2 Mon Sep 17 00:00:00 2001 From: Naofumi MURATA <10278628+nao23@users.noreply.github.com> Date: Tue, 6 May 2025 01:52:22 +0900 Subject: [PATCH 3/4] fix link --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db2c786ae8..574ba62c28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3447](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3447)) - `opentelemetry-instrumentation-botocore` Capture server attributes for botocore API calls ([#3448](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3448)) -- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3459](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3459)) +- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3460](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3460)) ## Version 1.32.0/0.53b0 (2025-04-10) From 2b00ca975b99bfb9afad65c0572aa016711a2b3a Mon Sep 17 00:00:00 2001 From: Naofumi MURATA <10278628+nao23@users.noreply.github.com> Date: Mon, 12 May 2025 23:43:57 +0900 Subject: [PATCH 4/4] update CHANGELOG --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d5cd8079..6d6e134ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed +- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3460](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3460)) + + ## Version 1.33.0/0.54b0 (2025-05-09) ### Added @@ -37,8 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3447](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3447)) - `opentelemetry-instrumentation-botocore` Capture server attributes for botocore API calls ([#3448](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3448)) -- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3460](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3460)) - ## Version 1.32.0/0.53b0 (2025-04-10)