diff --git a/CHANGELOG.md b/CHANGELOG.md index efb766bda4..1777dfa262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,14 @@ 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)) + ### Breaking changes - `opentelemetry-instrumentation-botocore` Use `cloud.region` instead of `aws.region` span attribute as per semantic conventions. ([#3474](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3474)) - ## Version 1.33.0/0.54b0 (2025-05-09) ### Added @@ -44,7 +46,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-botocore` Capture server attributes for botocore API calls ([#3448](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3448)) - ## Version 1.32.0/0.53b0 (2025-04-10) ### Added 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"