Skip to content

Commit 8ebd151

Browse files
Fix query script
1 parent 4d509d3 commit 8ebd151

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

docs/examples/sqlcommenter/instrumented_query.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
)
4040
trace.get_tracer_provider().add_span_processor(span_processor)
4141

42-
# Instrument MySQL queries with sqlcommenter enabled
43-
# and comment-in-span-attribute enabled
44-
MySQLInstrumentor().instrument(
45-
enable_commenter=True,
46-
enable_attribute_commenter=True,
47-
)
48-
4942
cnx = connect(
5043
host="localhost",
5144
port=3366,
@@ -54,13 +47,22 @@
5447
database="books",
5548
)
5649

50+
# Instruments MySQL queries with sqlcommenter enabled
51+
# and comment-in-span-attribute enabled.
52+
# Returns wrapped connection to generate traces.
53+
cnx = MySQLInstrumentor().instrument_connection(
54+
connection=cnx,
55+
enable_commenter=True,
56+
enable_attribute_commenter=True,
57+
)
58+
5759
cursor = cnx.cursor()
5860
statement = "SELECT * FROM authors WHERE id = %s"
5961

6062
# Each SELECT query generates one mysql log with sqlcomment
6163
# and one OTel span with `db.statement` attribute that also
6264
# includes sqlcomment.
63-
for cid in range(1, 3):
65+
for cid in range(1, 4):
6466
cursor.execute(statement, (cid,))
6567
rows = cursor.fetchall()
6668
print(f"Found author: {rows[0]}")

0 commit comments

Comments
 (0)