feat: respect supress_instrumentation functionality in dbapi instrumentation (#3460)

* respect supress_instrumentation

* update CHANGELOG

* fix link

* update CHANGELOG

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
This commit is contained in:
Naofumi MURATA
2025-05-31 00:49:29 +09:00
committed by GitHub
parent 6c89a56da5
commit 6d8becf9ad
3 changed files with 21 additions and 0 deletions

View File

@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3544](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3544))
- `opentelemetry-instrumentation-botocore` Add type check when extracting tool use from Bedrock request message content
([#3548](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3548))
- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3460](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3460))
### Breaking changes

View File

@ -52,6 +52,7 @@ from opentelemetry.instrumentation.dbapi.version import __version__
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 @@ class CursorTracer(Generic[CursorT]):
*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 = (

View File

@ -21,6 +21,7 @@ from unittest import mock
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 @@ class TestDBApiIntegration(TestBase):
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"