Skip to content

Commit d042691

Browse files
Add DB-API docs SQLCommenter Configurations
1 parent bf1c211 commit d042691

File tree

1 file changed

+58
-6
lines changed
  • instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi

1 file changed

+58
-6
lines changed

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

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
wrap_connect,
4343
)
4444
45-
# Ex: mysql.connector
45+
# Example: mysql.connector
4646
trace_integration(mysql.connector, "connect", "mysql")
47-
# Ex: pyodbc
47+
# Example: pyodbc
4848
trace_integration(pyodbc, "Connection", "odbc")
4949
5050
# Or, directly call wrap_connect for more configurability
@@ -60,29 +60,81 @@
6060
You can optionally configure DB-API instrumentation to enable sqlcommenter which
6161
enriches the query with contextual information. Queries made after setting up
6262
trace integration with sqlcommenter enabled will have configurable key-value pairs
63-
appended to them, e.g. ``"select * from auth_users; /*metrics=value*/"``. For
64-
more information, see:
63+
appended to them, e.g. ``"select * from auth_users; /*metrics=value*/"``. This
64+
supports context propagation between database client and server when database log
65+
records are enabled. For more information, see:
6566
6667
* `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_
6768
* `sqlcommenter <https://google.github.io/sqlcommenter/>`_
6869
6970
.. code:: python
7071
7172
import mysql.connector
72-
import pyodbc
7373
7474
from opentelemetry.instrumentation.dbapi import wrap_connect
7575
7676
77-
# Ex: mysql.connector
77+
# Opts into sqlcomment for MySQL trace integration
78+
wrap_connect(
79+
__name__,
80+
mysql.connector,
81+
"connect",
82+
"mysql",
83+
enable_commenter=True,
84+
)
85+
86+
87+
SQLCommenter Configurations
88+
***************************
89+
When using ``wrap_connect`` for DB-API trace integration, the key-value pairs appended to the query can be configured using ``commenter_options``. When sqlcommenter is enabled, all available KVs/tags calculated by default. ``commenter_options`` supports opting out of specific KVs.
90+
91+
.. code:: python
92+
93+
import mysql.connector
94+
95+
from opentelemetry.instrumentation.dbapi import wrap_connect
96+
97+
98+
# Opts into sqlcomment for MySQL trace integration
99+
# Opts out of tags for libpq_version
78100
wrap_connect(
79101
__name__,
80102
mysql.connector,
81103
"connect",
82104
"mysql",
83105
enable_commenter=True,
106+
commenter_options={
107+
"libpq_version": False,
108+
"db_driver": False,
109+
}
84110
)
85111
112+
Available commenter options
113+
###########################
114+
115+
The following options can be configured through ``commenter_options``:
116+
117+
#. ``db_driver`` - Database driver name with version.
118+
Example: ``mysql.connector=2.2.9``
119+
120+
#. ``dbapi_threadsafety`` - DB-API's threadsafety value.
121+
Example: ``dbapi_threadsafety=2``
122+
123+
#. ``dbapi_level`` - DB-API's API level.
124+
Example: ``dbapi_level=2.0``
125+
126+
#. ``driver_paramstyle`` - DB-API's paramstyle for SQL statement parameters.
127+
Example: ``driver_paramstyle='pyformat'``
128+
129+
#. ``libpq_version`` - PostgreSQL's libpq version (checked for PostgreSQL only).
130+
Example: ``libpq_version=140001``
131+
132+
#. ``mysql_client_version`` - MySQL client version (checked for MySQL only).
133+
Example: ``mysql_client_version='123'``
134+
135+
#. ``opentelemetry_values`` - OpenTelemetry context values.
136+
Example: ``traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'``
137+
86138
API
87139
---
88140
"""

0 commit comments

Comments
 (0)