Skip to content

Commit 49e3c92

Browse files
committed
add commenter_options in trace_integration
1 parent 2ecc2d2 commit 49e3c92

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def trace_integration(
7878
capture_parameters: bool = False,
7979
enable_commenter: bool = False,
8080
db_api_integration_factory: type[DatabaseApiIntegration] | None = None,
81+
commenter_options: dict[str, Any] | None = None,
8182
enable_attribute_commenter: bool = False,
8283
):
8384
"""Integrate with DB API library.
@@ -96,6 +97,7 @@ def trace_integration(
9697
enable_commenter: Flag to enable/disable sqlcommenter.
9798
db_api_integration_factory: The `DatabaseApiIntegration` to use. If none is passed the
9899
default one is used.
100+
commenter_options: Configurations for tags to be appended at the sql query.
99101
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` span attribute. Only available if enable_commenter=True.
100102
"""
101103
wrap_connect(
@@ -109,6 +111,7 @@ def trace_integration(
109111
capture_parameters=capture_parameters,
110112
enable_commenter=enable_commenter,
111113
db_api_integration_factory=db_api_integration_factory,
114+
commenter_options=commenter_options,
112115
enable_attribute_commenter=enable_attribute_commenter,
113116
)
114117

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@ def test_suppress_instrumentation(self):
259259
spans_list = self.memory_exporter.get_finished_spans()
260260
self.assertEqual(len(spans_list), 0)
261261

262+
def test_commenter_options_propagation(self):
263+
db_integration = dbapi.DatabaseApiIntegration(
264+
"instrumenting_module_test_name",
265+
"testcomponent",
266+
commenter_options={"opentelemetry_values": False},
267+
)
268+
mock_connection = db_integration.wrapped_connection(
269+
mock_connect, {}, {}
270+
)
271+
cursor = mock_connection.cursor()
272+
with self.assertRaises(Exception):
273+
cursor.execute("SELECT 1", throw_exception=True)
274+
spans_list = self.memory_exporter.get_finished_spans()
275+
self.assertEqual(len(spans_list), 1)
276+
span = spans_list[0]
277+
self.assertEqual(span.attributes.get("db.system"), "testcomponent")
278+
self.assertIn("opentelemetry_values", db_integration.commenter_options)
279+
self.assertFalse(db_integration.commenter_options["opentelemetry_values"])
280+
262281
def test_executemany(self):
263282
db_integration = dbapi.DatabaseApiIntegration(
264283
"instrumenting_module_test_name", "testcomponent"

0 commit comments

Comments
 (0)