Skip to content

Commit e5558a6

Browse files
authored
Cleanup start_transaction usages (#3884)
1 parent 0f34b49 commit e5558a6

29 files changed

+118
-118
lines changed

sentry_sdk/integrations/aws_lambda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
160160
headers = {}
161161

162162
with sentry_sdk.continue_trace(headers):
163-
with sentry_sdk.start_transaction(
163+
with sentry_sdk.start_span(
164164
op=OP.FUNCTION_AWS,
165165
name=aws_context.function_name,
166166
source=TRANSACTION_SOURCE_COMPONENT,

sentry_sdk/integrations/celery/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _inner(*args, **kwargs):
313313
# something such as attribute access can fail.
314314
headers = args[3].get("headers") or {}
315315
with sentry_sdk.continue_trace(headers):
316-
with sentry_sdk.start_transaction(
316+
with sentry_sdk.start_span(
317317
op=OP.QUEUE_TASK_CELERY,
318318
name=task.name,
319319
source=TRANSACTION_SOURCE_TASK,

sentry_sdk/integrations/gcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
8787
headers = gcp_event.headers
8888

8989
with sentry_sdk.continue_trace(headers):
90-
with sentry_sdk.start_transaction(
90+
with sentry_sdk.start_span(
9191
op=OP.FUNCTION_GCP,
9292
name=environ.get("FUNCTION_NAME", ""),
9393
source=TRANSACTION_SOURCE_COMPONENT,

sentry_sdk/integrations/grpc/aio/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def wrapped(request, context):
4545

4646
# What if the headers are empty?
4747
with sentry_sdk.continue_trace(dict(context.invocation_metadata())):
48-
with sentry_sdk.start_transaction(
48+
with sentry_sdk.start_span(
4949
op=OP.GRPC_SERVER,
5050
name=name,
5151
source=TRANSACTION_SOURCE_CUSTOM,

sentry_sdk/integrations/grpc/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def behavior(request, context):
3939
metadata = dict(context.invocation_metadata())
4040

4141
with sentry_sdk.continue_trace(metadata):
42-
with sentry_sdk.start_transaction(
42+
with sentry_sdk.start_span(
4343
op=OP.GRPC_SERVER,
4444
name=name,
4545
source=TRANSACTION_SOURCE_CUSTOM,

sentry_sdk/integrations/tornado.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _handle_request_impl(self):
125125
scope.add_event_processor(processor)
126126

127127
with sentry_sdk.continue_trace(headers):
128-
with sentry_sdk.start_transaction(
128+
with sentry_sdk.start_span(
129129
op=OP.HTTP_SERVER,
130130
# Like with all other integrations, this is our
131131
# fallback transaction in case there is no route.

sentry_sdk/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ def ensure_integration_enabled(
18021802
```python
18031803
@ensure_integration_enabled(MyIntegration, my_function)
18041804
def patch_my_function():
1805-
with sentry_sdk.start_transaction(...):
1805+
with sentry_sdk.start_span(...):
18061806
return my_function()
18071807
```
18081808
"""

tests/integrations/aiohttp/test_aiohttp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
HTTPUnavailableForLegalReasons,
1616
)
1717

18-
from sentry_sdk import capture_message, start_transaction
18+
from sentry_sdk import capture_message, start_span
1919
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
2020
from tests.conftest import ApproxDict
2121

@@ -417,7 +417,7 @@ async def hello(request):
417417
# The aiohttp_client is instrumented so will generate the sentry-trace header and add request.
418418
# Get the sentry-trace header from the request so we can later compare with transaction events.
419419
client = await aiohttp_client(app)
420-
with start_transaction():
420+
with start_span(name="request"):
421421
# Headers are only added to the span if there is an active transaction
422422
resp = await client.get("/")
423423

@@ -496,7 +496,7 @@ async def handler(request):
496496

497497
raw_server = await aiohttp_raw_server(handler)
498498

499-
with start_transaction():
499+
with start_span(name="breadcrumb"):
500500
events = capture_events()
501501

502502
client = await aiohttp_client(raw_server)
@@ -538,7 +538,7 @@ async def handler(request):
538538

539539
raw_server = await aiohttp_raw_server(handler)
540540

541-
with start_transaction(
541+
with start_span(
542542
name="/interactions/other-dogs/new-dog",
543543
op="greeting.sniff",
544544
) as transaction:
@@ -573,7 +573,7 @@ async def handler(request):
573573

574574
raw_server = await aiohttp_raw_server(handler)
575575

576-
with start_transaction(
576+
with start_span(
577577
name="/interactions/other-dogs/new-dog",
578578
op="greeting.sniff",
579579
) as transaction:

tests/integrations/anthropic/test_anthropic.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def __call__(self, *args, **kwargs):
4242
except ImportError:
4343
from anthropic.types.content_block import ContentBlock as TextBlock
4444

45-
from sentry_sdk import start_transaction
45+
from sentry_sdk import start_span
4646
from sentry_sdk.consts import OP, SPANDATA
4747
from sentry_sdk.integrations.anthropic import AnthropicIntegration
4848

@@ -90,7 +90,7 @@ def test_nonstreaming_create_message(
9090
}
9191
]
9292

93-
with start_transaction(name="anthropic"):
93+
with start_span(name="anthropic"):
9494
response = client.messages.create(
9595
max_tokens=1024, messages=messages, model="model"
9696
)
@@ -160,7 +160,7 @@ async def test_nonstreaming_create_message_async(
160160
}
161161
]
162162

163-
with start_transaction(name="anthropic"):
163+
with start_span(name="anthropic"):
164164
response = await client.messages.create(
165165
max_tokens=1024, messages=messages, model="model"
166166
)
@@ -263,7 +263,7 @@ def test_streaming_create_message(
263263
}
264264
]
265265

266-
with start_transaction(name="anthropic"):
266+
with start_span(name="anthropic"):
267267
message = client.messages.create(
268268
max_tokens=1024, messages=messages, model="model", stream=True
269269
)
@@ -368,7 +368,7 @@ async def test_streaming_create_message_async(
368368
}
369369
]
370370

371-
with start_transaction(name="anthropic"):
371+
with start_span(name="anthropic"):
372372
message = await client.messages.create(
373373
max_tokens=1024, messages=messages, model="model", stream=True
374374
)
@@ -500,7 +500,7 @@ def test_streaming_create_message_with_input_json_delta(
500500
}
501501
]
502502

503-
with start_transaction(name="anthropic"):
503+
with start_span(name="anthropic"):
504504
message = client.messages.create(
505505
max_tokens=1024, messages=messages, model="model", stream=True
506506
)
@@ -639,7 +639,7 @@ async def test_streaming_create_message_with_input_json_delta_async(
639639
}
640640
]
641641

642-
with start_transaction(name="anthropic"):
642+
with start_span(name="anthropic"):
643643
message = await client.messages.create(
644644
max_tokens=1024, messages=messages, model="model", stream=True
645645
)
@@ -736,7 +736,7 @@ def test_span_origin(sentry_init, capture_events):
736736
}
737737
]
738738

739-
with start_transaction(name="anthropic"):
739+
with start_span(name="anthropic"):
740740
client.messages.create(max_tokens=1024, messages=messages, model="model")
741741

742742
(event,) = events
@@ -763,7 +763,7 @@ async def test_span_origin_async(sentry_init, capture_events):
763763
}
764764
]
765765

766-
with start_transaction(name="anthropic"):
766+
with start_span(name="anthropic"):
767767
await client.messages.create(max_tokens=1024, messages=messages, model="model")
768768

769769
(event,) = events

tests/integrations/arq/test_arq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import pytest
33

4-
from sentry_sdk import get_client, start_transaction
4+
from sentry_sdk import get_client, start_span
55
from sentry_sdk.integrations.arq import ArqIntegration
66

77
import arq.worker
@@ -292,7 +292,7 @@ async def dummy_job(_):
292292

293293
events = capture_events()
294294

295-
with start_transaction() as transaction:
295+
with start_span(name="test") as transaction:
296296
await pool.enqueue_job("dummy_job")
297297

298298
(event,) = events
@@ -343,7 +343,7 @@ async def dummy_job(_):
343343

344344
events = capture_events()
345345

346-
with start_transaction():
346+
with start_span(name="job"):
347347
await pool.enqueue_job("dummy_job")
348348

349349
(event,) = events

tests/integrations/celery/test_celery.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from celery.bin import worker
88

99
import sentry_sdk
10-
from sentry_sdk import start_transaction, get_current_span
10+
from sentry_sdk import start_span, get_current_span
1111
from sentry_sdk.integrations.celery import (
1212
CeleryIntegration,
1313
_wrap_task_run,
@@ -126,7 +126,7 @@ def dummy_task(x, y):
126126
foo = 42 # noqa
127127
return x / y
128128

129-
with start_transaction(op="unit test transaction") as transaction:
129+
with start_span(op="unit test transaction") as transaction:
130130
celery_invocation(dummy_task, 1, 2)
131131
_, expected_context = celery_invocation(dummy_task, 1, 0)
132132

@@ -195,7 +195,7 @@ def dummy_task(x, y):
195195

196196
events = capture_events()
197197

198-
with start_transaction(name="submission") as transaction:
198+
with start_span(name="submission") as transaction:
199199
celery_invocation(dummy_task, 1, 0 if task_fails else 1)
200200

201201
if task_fails:
@@ -275,11 +275,11 @@ def test_simple_no_propagation(capture_events, init_celery):
275275
def dummy_task():
276276
1 / 0
277277

278-
with start_transaction() as transaction:
278+
with start_span(name="task") as root_span:
279279
dummy_task.delay()
280280

281281
(event,) = events
282-
assert event["contexts"]["trace"]["trace_id"] != transaction.trace_id
282+
assert event["contexts"]["trace"]["trace_id"] != root_span.trace_id
283283
assert event["transaction"] == "dummy_task"
284284
(exception,) = event["exception"]["values"]
285285
assert exception["type"] == "ZeroDivisionError"
@@ -350,7 +350,7 @@ def dummy_task(self):
350350
runs.append(1)
351351
1 / 0
352352

353-
with start_transaction(name="submit_celery"):
353+
with start_span(name="submit_celery"):
354354
# Curious: Cannot use delay() here or py2.7-celery-4.2 crashes
355355
res = dummy_task.apply_async()
356356

@@ -469,7 +469,7 @@ def __call__(self, *args, **kwargs):
469469
def dummy_task(x, y):
470470
return x / y
471471

472-
with start_transaction():
472+
with start_span(name="celery"):
473473
celery_invocation(dummy_task, 1, 0)
474474

475475
assert not events
@@ -510,7 +510,7 @@ def test_baggage_propagation(init_celery):
510510
def dummy_task(self, x, y):
511511
return _get_headers(self)
512512

513-
with start_transaction() as transaction:
513+
with start_span(name="task") as root_span:
514514
result = dummy_task.apply_async(
515515
args=(1, 0),
516516
headers={"baggage": "custom=value"},
@@ -519,7 +519,7 @@ def dummy_task(self, x, y):
519519
assert sorted(result["baggage"].split(",")) == sorted(
520520
[
521521
"sentry-release=abcdef",
522-
"sentry-trace_id={}".format(transaction.trace_id),
522+
"sentry-trace_id={}".format(root_span.trace_id),
523523
"sentry-environment=production",
524524
"sentry-sample_rate=1.0",
525525
"sentry-sampled=true",
@@ -542,8 +542,8 @@ def dummy_task(self, message):
542542
trace_id = get_current_span().trace_id
543543
return trace_id
544544

545-
with start_transaction() as transaction:
546-
transaction_trace_id = transaction.trace_id
545+
with start_span(name="task") as root_span:
546+
transaction_trace_id = root_span.trace_id
547547

548548
# should propagate trace
549549
task_transaction_id = dummy_task.apply_async(
@@ -710,7 +710,7 @@ def publish(*args, **kwargs):
710710
@celery.task()
711711
def task(): ...
712712

713-
with start_transaction():
713+
with start_span(name="task"):
714714
task.apply_async()
715715

716716
(event,) = events
@@ -773,7 +773,7 @@ def publish(*args, **kwargs):
773773
@celery.task()
774774
def task(): ...
775775

776-
with start_transaction(name="custom_transaction"):
776+
with start_span(name="custom_transaction"):
777777
task.apply_async()
778778

779779
(event,) = events
@@ -799,7 +799,7 @@ def test_send_task_wrapped(
799799

800800
events = capture_events()
801801

802-
with sentry_sdk.start_transaction(name="custom_transaction"):
802+
with sentry_sdk.start_span(name="custom_transaction"):
803803
celery.send_task("very_creative_task_name", args=(1, 2), kwargs={"foo": "bar"})
804804

805805
(call,) = patched_send_task.call_args_list # We should have exactly one call

tests/integrations/celery/test_update_celery_task_headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_span_with_transaction(sentry_init):
7575
headers = {}
7676
monitor_beat_tasks = False
7777

78-
with sentry_sdk.start_transaction(name="test_transaction") as transaction:
78+
with sentry_sdk.start_span(name="test_transaction") as transaction:
7979
with sentry_sdk.start_span(op="test_span") as span:
8080
outgoing_headers = _update_celery_task_headers(
8181
headers, span, monitor_beat_tasks
@@ -97,7 +97,7 @@ def test_span_with_transaction_custom_headers(sentry_init):
9797
"sentry-trace": SENTRY_TRACE_VALUE,
9898
}
9999

100-
with sentry_sdk.start_transaction(name="test_transaction") as transaction:
100+
with sentry_sdk.start_span(name="test_transaction") as transaction:
101101
with sentry_sdk.start_span(op="test_span") as span:
102102
outgoing_headers = _update_celery_task_headers(headers, span, False)
103103

0 commit comments

Comments
 (0)