Skip to content

Commit e11ec1a

Browse files
committed
Separate instrument_connection() docstring block for mysql, mysqlclient, psycopg, psycopg2, pymysql, sqlite3
1 parent 0cbd913 commit e11ec1a

File tree

6 files changed

+66
-21
lines changed
  • instrumentation
    • opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql
    • opentelemetry-instrumentation-mysqlclient/src/opentelemetry/instrumentation/mysqlclient
    • opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg
    • opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2
    • opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql
    • opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3

6 files changed

+66
-21
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import mysql.connector
2727
from opentelemetry.instrumentation.mysql import MySQLInstrumentor
2828
29+
# Call instrument() to wrap all database connections
2930
MySQLInstrumentor().instrument()
3031
3132
cnx = mysql.connector.connect(database="MySQL_Database")
@@ -34,11 +35,18 @@
3435
cursor.close()
3536
cnx.close()
3637
37-
cnx = MySQLInstrumentor().instrument_connection(cnx)
38-
cursor = cnx.cursor()
38+
.. code:: python
39+
40+
import mysql.connector
41+
from opentelemetry.instrumentation.mysql import MySQLInstrumentor
42+
43+
# Alternatively, use instrument_connection for an individual connection
44+
cnx = mysql.connector.connect(database="MySQL_Database")
45+
instrumented_cnx = MySQLInstrumentor().instrument_connection(cnx)
46+
cursor = instrumented_cnx.cursor()
3947
cursor.execute("INSERT INTO test (testField) VALUES (123)")
4048
cursor.close()
41-
cnx.close()
49+
instrumented_cnx.close()
4250
4351
API
4452
---

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import MySQLdb
4747
from opentelemetry.instrumentation.mysqlclient import MySQLClientInstrumentor
4848
49-
49+
# Call instrument() to wrap all database connections
5050
MySQLClientInstrumentor().instrument(enable_commenter=True, commenter_options={})
5151
5252
cnx = MySQLdb.connect(database="MySQL_Database")
@@ -56,6 +56,13 @@
5656
cursor.close()
5757
cnx.close()
5858
59+
.. code:: python
60+
61+
import MySQLdb
62+
from opentelemetry.instrumentation.mysqlclient import MySQLClientInstrumentor
63+
64+
# Alternatively, use instrument_connection for an individual connection
65+
cnx = MySQLdb.connect(database="MySQL_Database")
5966
instrumented_cnx = MySQLClientInstrumentor.instrument_connection(
6067
cnx,
6168
enable_commenter=True,

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import psycopg
8989
from opentelemetry.instrumentation.psycopg import PsycopgInstrumentor
9090
91-
91+
# Call instrument() to wrap all database connections
9292
PsycopgInstrumentor().instrument()
9393
9494
cnx = psycopg.connect(database='Database')
@@ -98,6 +98,13 @@
9898
cursor.close()
9999
cnx.close()
100100
101+
.. code-block:: python
102+
103+
import psycopg
104+
from opentelemetry.instrumentation.psycopg import PsycopgInstrumentor
105+
106+
# Alternatively, use instrument_connection for an individual connection
107+
cnx = psycopg.connect(database='Database')
101108
instrumented_cnx = instrument_connection(cnx)
102109
cursor = instrumented_cnx.cursor()
103110
cursor.execute("INSERT INTO test (testField) VALUES (123)")

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import psycopg2
8989
from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor
9090
91-
91+
# Call instrument() to wrap all database connections
9292
Psycopg2Instrumentor().instrument()
9393
9494
cnx = psycopg2.connect(database='Database')
@@ -98,6 +98,13 @@
9898
cursor.close()
9999
cnx.close()
100100
101+
.. code-block:: python
102+
103+
import psycopg2
104+
from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor
105+
106+
# Alternatively, use instrument_connection for an individual connection
107+
cnx = psycopg2.connect(database='Database')
101108
instrumented_cnx = Psycopg2Instrumentor.instrument_connection(cnx)
102109
cursor = instrumented_cnx.cursor()
103110
cursor.execute("INSERT INTO test (testField) VALUES (123)")

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

+23-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import pymysql
2727
from opentelemetry.instrumentation.pymysql import PyMySQLInstrumentor
2828
29+
# Call instrument() to wrap all database connections
2930
PyMySQLInstrumentor().instrument()
3031
3132
cnx = pymysql.connect(database="MySQL_Database")
@@ -35,6 +36,28 @@
3536
cursor.close()
3637
cnx.close()
3738
39+
40+
.. code:: python
41+
42+
import pymysql
43+
from opentelemetry.instrumentation.pymysql import PyMySQLInstrumentor
44+
45+
# Alternatively, use instrument_connection for an individual connection
46+
cnx = pymysql.connect(database="MySQL_Database")
47+
instrumented_cnx = PyMySQLInstrumentor().instrument_connection(
48+
cnx,
49+
enable_commenter=True,
50+
commenter_options={
51+
"db_driver": True,
52+
"mysql_client_version": True
53+
}
54+
)
55+
cursor = instrumented_cnx.cursor()
56+
cursor.execute("INSERT INTO test (testField) VALUES (123)"
57+
instrumented_cnx.commit()
58+
cursor.close()
59+
instrumented_cnx.close()
60+
3861
SQLCOMMENTER
3962
*****************************************
4063
You can optionally configure PyMySQL instrumentation to enable sqlcommenter which enriches
@@ -57,20 +80,6 @@
5780
cursor.close()
5881
cnx.close()
5982
60-
instrumented_cnx = PyMySQLInstrumentor().instrument_connection(
61-
cnx,
62-
enable_commenter=True,
63-
commenter_options={
64-
"db_driver": True,
65-
"mysql_client_version": True
66-
}
67-
)
68-
cursor = instrumented_cnx.cursor()
69-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
70-
instrumented_cnx.commit()
71-
cursor.close()
72-
instrumented_cnx.close()
73-
7483
7584
For example,
7685
::

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import sqlite3
2828
from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor
2929
30-
30+
# Call instrument() to wrap all database connections
3131
SQLite3Instrumentor().instrument()
3232
3333
cnx = sqlite3.connect(':memory:')
@@ -36,6 +36,13 @@
3636
cursor.execute("INSERT INTO test (testField) VALUES (123)")
3737
cursor.close()
3838
cnx.close()
39+
40+
.. code:: python
41+
42+
import sqlite3
43+
from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor
44+
45+
# Alternatively, use instrument_connection for an individual connection
3946
conn = sqlite3.connect(":memory:")
4047
instrumented_connection = SQLite3Instrumentor.instrument_connection(conn)
4148
cursor = instrumented_connection.cursor()

0 commit comments

Comments
 (0)