Skip to content

Commit 288428e

Browse files
committed
respect supress_instrumentation
1 parent e6869cd commit 288428e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment
5353
from opentelemetry.instrumentation.utils import (
5454
_get_opentelemetry_values,
55+
is_instrumentation_enabled,
5556
unwrap,
5657
)
5758
from opentelemetry.semconv.trace import SpanAttributes
@@ -561,6 +562,9 @@ def traced_execution(
561562
*args: tuple[Any, ...],
562563
**kwargs: dict[Any, Any],
563564
):
565+
if not is_instrumentation_enabled():
566+
return query_method(*args, **kwargs)
567+
564568
name = self.get_operation_name(cursor, args)
565569
if not name:
566570
name = (

instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from opentelemetry import context
2222
from opentelemetry import trace as trace_api
2323
from opentelemetry.instrumentation import dbapi
24+
from opentelemetry.instrumentation.utils import suppress_instrumentation
2425
from opentelemetry.sdk import resources
2526
from opentelemetry.semconv.trace import SpanAttributes
2627
from opentelemetry.test.test_base import TestBase
@@ -243,6 +244,21 @@ def test_no_op_tracer_provider(self):
243244
spans_list = self.memory_exporter.get_finished_spans()
244245
self.assertEqual(len(spans_list), 0)
245246

247+
def test_suppress_instrumentation(self):
248+
db_integration = dbapi.DatabaseApiIntegration(
249+
"instrumenting_module_test_name",
250+
"testcomponent",
251+
)
252+
mock_connection = db_integration.wrapped_connection(
253+
mock_connect, {}, {}
254+
)
255+
with suppress_instrumentation():
256+
cursor = mock_connection.cursor()
257+
cursor.execute("Test query", ("param1Value", False))
258+
259+
spans_list = self.memory_exporter.get_finished_spans()
260+
self.assertEqual(len(spans_list), 0)
261+
246262
def test_executemany(self):
247263
db_integration = dbapi.DatabaseApiIntegration(
248264
"instrumenting_module_test_name", "testcomponent"

0 commit comments

Comments
 (0)