You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cursor.execute("INSERT INTO test (testField) VALUES (123)")
70
+
cursor.close()
71
+
cnx.close()
72
+
73
+
74
+
For example,
75
+
::
76
+
77
+
Invoking cursor.execute("INSERT INTO test (testField) VALUES (123)") will lead to sql query "INSERT INTO test (testField) VALUES (123)" but when SQLCommenter is enabled
78
+
the query will get appended with some configurable tags like "INSERT INTO test (testField) VALUES (123) /*tag=value*/;"
79
+
80
+
**WARNING:** sqlcommenter for mysql-connector instrumentation should NOT be used if your application initializes cursors with ``prepared=True``, which will natively prepare and execute MySQL statements. Adding sqlcommenting will introduce a severe performance penalty by repeating ``Prepare`` of statements by mysql-connector that are made unique by traceparent in sqlcomment. The penalty does not happen if cursor ``prepared=False`` (default) and instrumentor ``enable_commenter=True``.
81
+
82
+
SQLCommenter Configurations
83
+
***************************
84
+
We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword
85
+
86
+
db_driver = True(Default) or False
87
+
88
+
For example,
89
+
::
90
+
Enabling this flag will add mysql.connector and its version, e.g. /*mysql.connector%%3A1.2.3*/
91
+
92
+
dbapi_threadsafety = True(Default) or False
93
+
94
+
For example,
95
+
::
96
+
Enabling this flag will add threadsafety /*dbapi_threadsafety=2*/
97
+
98
+
dbapi_level = True(Default) or False
99
+
100
+
For example,
101
+
::
102
+
Enabling this flag will add dbapi_level /*dbapi_level='2.0'*/
103
+
104
+
mysql_client_version = True(Default) or False
105
+
106
+
For example,
107
+
::
108
+
Enabling this flag will add mysql_client_version /*mysql_client_version='123'*/
109
+
110
+
driver_paramstyle = True(Default) or False
111
+
112
+
For example,
113
+
::
114
+
Enabling this flag will add driver_paramstyle /*driver_paramstyle='pyformat'*/
115
+
116
+
opentelemetry_values = True(Default) or False
117
+
118
+
For example,
119
+
::
120
+
Enabling this flag will add traceparent values /*traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'*/
121
+
122
+
SQLComment in span attribute
123
+
****************************
124
+
If sqlcommenter is enabled, you can optionally configure mysql-connector instrumentation to append sqlcomment to query span attribute for convenience of your platform.
125
+
126
+
.. code:: python
127
+
128
+
from opentelemetry.instrumentation.mysql import MySQLInstrumentor
129
+
130
+
MySQLInstrumentor().instrument(
131
+
enable_commenter=True,
132
+
enable_attribute_commenter=True,
133
+
)
134
+
135
+
136
+
For example,
137
+
::
138
+
139
+
Invoking cursor.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter and attribute_commenter are enabled
140
+
the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" for both server query and `db.statement` span attribute.
0 commit comments