Skip to content

Commit eaa05bc

Browse files
Update DB-API integration docs
1 parent 51da0a7 commit eaa05bc

File tree

1 file changed

+43
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
Usage
2121
-----
2222
23+
The DB-API instrumentor and its utilities provide common, core functionality for
24+
database framework or object relation mapper (ORM) instrumentations. Users will
25+
typically instrument database client code with those framework/ORM-specific
26+
instrumentations, instead of directly using this DB-API integration. See full list
27+
at `instrumentation`_.
28+
29+
.. _instrumentation: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation
30+
31+
If an instrumentation for your needs does not exist, then DB-API integration can
32+
be used directly as follows.
33+
34+
2335
.. code-block:: python
2436
2537
import mysql.connector
@@ -33,6 +45,37 @@
3345
# Ex: pyodbc
3446
trace_integration(pyodbc, "Connection", "odbc")
3547
48+
49+
Configuration
50+
-------------
51+
52+
SQLCOMMENTER
53+
************
54+
You can optionally configure DB-API instrumentation to enable sqlcommenter which
55+
enriches the query with contextual information. Queries made after setting up
56+
trace integration with sqlcommenter enabled will have configurable key-value pairs
57+
appended to them, e.g. ``"select * from auth_users; /*metrics=value*/"``. For
58+
more information, see:
59+
60+
* `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_
61+
* `sqlcommenter <https://google.github.io/sqlcommenter/>`_
62+
63+
.. code:: python
64+
65+
import mysql.connector
66+
import pyodbc
67+
68+
from opentelemetry.instrumentation.dbapi import trace_integration
69+
70+
71+
# Ex: mysql.connector
72+
trace_integration(
73+
mysql.connector,
74+
"connect",
75+
"mysql",
76+
enable_commenter=True,
77+
)
78+
3679
API
3780
---
3881
"""

0 commit comments

Comments
 (0)