1111from sqlalchemy import text
1212
1313import sentry_sdk
14- from sentry_sdk import capture_message , start_transaction
1514from sentry_sdk .consts import DEFAULT_MAX_VALUE_LENGTH , SPANDATA
1615from sentry_sdk .integrations .sqlalchemy import SqlalchemyIntegration
1716from sentry_sdk .serializer import MAX_EVENT_BYTES
@@ -54,7 +53,7 @@ class Address(Base):
5453
5554 assert session .query (Person ).first () == bob
5655
57- capture_message ("hi" )
56+ sentry_sdk . capture_message ("hi" )
5857
5958 (event ,) = events
6059
@@ -111,7 +110,7 @@ class Address(Base):
111110 Session = sessionmaker (bind = engine ) # noqa: N806
112111 session = Session ()
113112
114- with start_transaction (name = "test_transaction" , sampled = True ):
113+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
115114 with session .begin_nested ():
116115 session .query (Person ).first ()
117116
@@ -135,7 +134,7 @@ class Address(Base):
135134 assert (
136135 render_span_tree (event )
137136 == """\
138- - op=null : description=null
137+ - op="test_transaction" : description=null
139138 - op="db": description="SAVEPOINT sa_savepoint_1"
140139 - op="db": description="SELECT person.id AS person_id, person.name AS person_name \\ nFROM person\\ n LIMIT ? OFFSET ?"
141140 - op="db": description="RELEASE SAVEPOINT sa_savepoint_1"
@@ -185,7 +184,7 @@ class Address(Base):
185184 Session = sessionmaker (bind = engine ) # noqa: N806
186185 session = Session ()
187186
188- with start_transaction (name = "test_transaction" , sampled = True ):
187+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
189188 with session .begin_nested ():
190189 session .query (Person ).first ()
191190
@@ -217,7 +216,7 @@ def test_long_sql_query_preserved(sentry_init, capture_events):
217216 engine = create_engine (
218217 "sqlite:///:memory:" , connect_args = {"check_same_thread" : False }
219218 )
220- with start_transaction (name = "test" ):
219+ with sentry_sdk . start_span (name = "test" ):
221220 with engine .connect () as con :
222221 con .execute (text (" UNION " .join ("SELECT {}" .format (i ) for i in range (100 ))))
223222
@@ -246,7 +245,7 @@ def processor(event, hint):
246245 engine = create_engine (
247246 "sqlite:///:memory:" , connect_args = {"check_same_thread" : False }
248247 )
249- with start_transaction (name = "test" ):
248+ with sentry_sdk . start_span (name = "test" ):
250249 with engine .connect () as con :
251250 for _ in range (1500 ):
252251 con .execute (
@@ -306,7 +305,7 @@ def test_query_source_disabled(sentry_init, capture_events):
306305
307306 events = capture_events ()
308307
309- with start_transaction (name = "test_transaction" , sampled = True ):
308+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
310309 Base = declarative_base () # noqa: N806
311310
312311 class Person (Base ):
@@ -358,7 +357,7 @@ def test_query_source_enabled(sentry_init, capture_events, enable_db_query_sourc
358357
359358 events = capture_events ()
360359
361- with start_transaction (name = "test_transaction" , sampled = True ):
360+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
362361 Base = declarative_base () # noqa: N806
363362
364363 class Person (Base ):
@@ -405,7 +404,7 @@ def test_query_source(sentry_init, capture_events):
405404 )
406405 events = capture_events ()
407406
408- with start_transaction (name = "test_transaction" , sampled = True ):
407+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
409408 Base = declarative_base () # noqa: N806
410409
411410 class Person (Base ):
@@ -475,7 +474,7 @@ def test_query_source_with_module_in_search_path(sentry_init, capture_events):
475474 query_first_model_from_session ,
476475 )
477476
478- with start_transaction (name = "test_transaction" , sampled = True ):
477+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
479478 Base = declarative_base () # noqa: N806
480479
481480 class Person (Base ):
@@ -533,7 +532,7 @@ def test_no_query_source_if_duration_too_short(sentry_init, capture_events):
533532 )
534533 events = capture_events ()
535534
536- with start_transaction (name = "test_transaction" , sampled = True ):
535+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
537536 Base = declarative_base () # noqa: N806
538537
539538 class Person (Base ):
@@ -601,7 +600,7 @@ def test_query_source_if_duration_over_threshold(sentry_init, capture_events):
601600 )
602601 events = capture_events ()
603602
604- with start_transaction (name = "test_transaction" , sampled = True ):
603+ with sentry_sdk . start_span (name = "test_transaction" , sampled = True ):
605604 Base = declarative_base () # noqa: N806
606605
607606 class Person (Base ):
@@ -687,7 +686,7 @@ def test_span_origin(sentry_init, capture_events):
687686 engine = create_engine (
688687 "sqlite:///:memory:" , connect_args = {"check_same_thread" : False }
689688 )
690- with start_transaction (name = "foo" ):
689+ with sentry_sdk . start_span (name = "foo" ):
691690 with engine .connect () as con :
692691 con .execute (text ("SELECT 0" ))
693692
0 commit comments