File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 3939)
4040trace .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-
4942cnx = connect (
5043 host = "localhost" ,
5144 port = 3366 ,
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+
5759cursor = cnx .cursor ()
5860statement = "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 ]} " )
You can’t perform that action at this time.
0 commit comments