Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup start_transaction usages #3884

Open
wants to merge 1 commit into
base: potel-base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
headers = {}

with sentry_sdk.continue_trace(headers):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
op=OP.FUNCTION_AWS,
name=aws_context.function_name,
source=TRANSACTION_SOURCE_COMPONENT,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _inner(*args, **kwargs):
# something such as attribute access can fail.
headers = args[3].get("headers") or {}
with sentry_sdk.continue_trace(headers):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
op=OP.QUEUE_TASK_CELERY,
name=task.name,
source=TRANSACTION_SOURCE_TASK,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
headers = gcp_event.headers

with sentry_sdk.continue_trace(headers):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
op=OP.FUNCTION_GCP,
name=environ.get("FUNCTION_NAME", ""),
source=TRANSACTION_SOURCE_COMPONENT,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def wrapped(request, context):

# What if the headers are empty?
with sentry_sdk.continue_trace(dict(context.invocation_metadata())):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
op=OP.GRPC_SERVER,
name=name,
source=TRANSACTION_SOURCE_CUSTOM,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def behavior(request, context):
metadata = dict(context.invocation_metadata())

with sentry_sdk.continue_trace(metadata):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
op=OP.GRPC_SERVER,
name=name,
source=TRANSACTION_SOURCE_CUSTOM,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _handle_request_impl(self):
scope.add_event_processor(processor)

with sentry_sdk.continue_trace(headers):
with sentry_sdk.start_transaction(
with sentry_sdk.start_span(
op=OP.HTTP_SERVER,
# Like with all other integrations, this is our
# fallback transaction in case there is no route.
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def ensure_integration_enabled(
```python
@ensure_integration_enabled(MyIntegration, my_function)
def patch_my_function():
with sentry_sdk.start_transaction(...):
with sentry_sdk.start_span(...):
return my_function()
```
"""
Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
HTTPUnavailableForLegalReasons,
)

from sentry_sdk import capture_message, start_transaction
from sentry_sdk import capture_message, start_span
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from tests.conftest import ApproxDict

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

Expand Down Expand Up @@ -496,7 +496,7 @@ async def handler(request):

raw_server = await aiohttp_raw_server(handler)

with start_transaction():
with start_span(name="breadcrumb"):
events = capture_events()

client = await aiohttp_client(raw_server)
Expand Down Expand Up @@ -538,7 +538,7 @@ async def handler(request):

raw_server = await aiohttp_raw_server(handler)

with start_transaction(
with start_span(
name="/interactions/other-dogs/new-dog",
op="greeting.sniff",
) as transaction:
Expand Down Expand Up @@ -573,7 +573,7 @@ async def handler(request):

raw_server = await aiohttp_raw_server(handler)

with start_transaction(
with start_span(
name="/interactions/other-dogs/new-dog",
op="greeting.sniff",
) as transaction:
Expand Down
18 changes: 9 additions & 9 deletions tests/integrations/anthropic/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def __call__(self, *args, **kwargs):
except ImportError:
from anthropic.types.content_block import ContentBlock as TextBlock

from sentry_sdk import start_transaction
from sentry_sdk import start_span
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations.anthropic import AnthropicIntegration

Expand Down Expand Up @@ -90,7 +90,7 @@ def test_nonstreaming_create_message(
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
response = client.messages.create(
max_tokens=1024, messages=messages, model="model"
)
Expand Down Expand Up @@ -160,7 +160,7 @@ async def test_nonstreaming_create_message_async(
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
response = await client.messages.create(
max_tokens=1024, messages=messages, model="model"
)
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_streaming_create_message(
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
message = client.messages.create(
max_tokens=1024, messages=messages, model="model", stream=True
)
Expand Down Expand Up @@ -368,7 +368,7 @@ async def test_streaming_create_message_async(
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
message = await client.messages.create(
max_tokens=1024, messages=messages, model="model", stream=True
)
Expand Down Expand Up @@ -500,7 +500,7 @@ def test_streaming_create_message_with_input_json_delta(
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
message = client.messages.create(
max_tokens=1024, messages=messages, model="model", stream=True
)
Expand Down Expand Up @@ -639,7 +639,7 @@ async def test_streaming_create_message_with_input_json_delta_async(
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
message = await client.messages.create(
max_tokens=1024, messages=messages, model="model", stream=True
)
Expand Down Expand Up @@ -736,7 +736,7 @@ def test_span_origin(sentry_init, capture_events):
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
client.messages.create(max_tokens=1024, messages=messages, model="model")

(event,) = events
Expand All @@ -763,7 +763,7 @@ async def test_span_origin_async(sentry_init, capture_events):
}
]

with start_transaction(name="anthropic"):
with start_span(name="anthropic"):
await client.messages.create(max_tokens=1024, messages=messages, model="model")

(event,) = events
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/arq/test_arq.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import pytest

from sentry_sdk import get_client, start_transaction
from sentry_sdk import get_client, start_span
from sentry_sdk.integrations.arq import ArqIntegration

import arq.worker
Expand Down Expand Up @@ -292,7 +292,7 @@ async def dummy_job(_):

events = capture_events()

with start_transaction() as transaction:
with start_span(name="test") as transaction:
await pool.enqueue_job("dummy_job")

(event,) = events
Expand Down Expand Up @@ -343,7 +343,7 @@ async def dummy_job(_):

events = capture_events()

with start_transaction():
with start_span(name="job"):
await pool.enqueue_job("dummy_job")

(event,) = events
Expand Down
28 changes: 14 additions & 14 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from celery.bin import worker

import sentry_sdk
from sentry_sdk import start_transaction, get_current_span
from sentry_sdk import start_span, get_current_span
from sentry_sdk.integrations.celery import (
CeleryIntegration,
_wrap_task_run,
Expand Down Expand Up @@ -126,7 +126,7 @@ def dummy_task(x, y):
foo = 42 # noqa
return x / y

with start_transaction(op="unit test transaction") as transaction:
with start_span(op="unit test transaction") as transaction:
celery_invocation(dummy_task, 1, 2)
_, expected_context = celery_invocation(dummy_task, 1, 0)

Expand Down Expand Up @@ -195,7 +195,7 @@ def dummy_task(x, y):

events = capture_events()

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

if task_fails:
Expand Down Expand Up @@ -275,11 +275,11 @@ def test_simple_no_propagation(capture_events, init_celery):
def dummy_task():
1 / 0

with start_transaction() as transaction:
with start_span(name="task") as root_span:
dummy_task.delay()

(event,) = events
assert event["contexts"]["trace"]["trace_id"] != transaction.trace_id
assert event["contexts"]["trace"]["trace_id"] != root_span.trace_id
assert event["transaction"] == "dummy_task"
(exception,) = event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"
Expand Down Expand Up @@ -350,7 +350,7 @@ def dummy_task(self):
runs.append(1)
1 / 0

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

Expand Down Expand Up @@ -469,7 +469,7 @@ def __call__(self, *args, **kwargs):
def dummy_task(x, y):
return x / y

with start_transaction():
with start_span(name="celery"):
celery_invocation(dummy_task, 1, 0)

assert not events
Expand Down Expand Up @@ -510,7 +510,7 @@ def test_baggage_propagation(init_celery):
def dummy_task(self, x, y):
return _get_headers(self)

with start_transaction() as transaction:
with start_span(name="task") as root_span:
result = dummy_task.apply_async(
args=(1, 0),
headers={"baggage": "custom=value"},
Expand All @@ -519,7 +519,7 @@ def dummy_task(self, x, y):
assert sorted(result["baggage"].split(",")) == sorted(
[
"sentry-release=abcdef",
"sentry-trace_id={}".format(transaction.trace_id),
"sentry-trace_id={}".format(root_span.trace_id),
"sentry-environment=production",
"sentry-sample_rate=1.0",
"sentry-sampled=true",
Expand All @@ -542,8 +542,8 @@ def dummy_task(self, message):
trace_id = get_current_span().trace_id
return trace_id

with start_transaction() as transaction:
transaction_trace_id = transaction.trace_id
with start_span(name="task") as root_span:
transaction_trace_id = root_span.trace_id

# should propagate trace
task_transaction_id = dummy_task.apply_async(
Expand Down Expand Up @@ -710,7 +710,7 @@ def publish(*args, **kwargs):
@celery.task()
def task(): ...

with start_transaction():
with start_span(name="task"):
task.apply_async()

(event,) = events
Expand Down Expand Up @@ -773,7 +773,7 @@ def publish(*args, **kwargs):
@celery.task()
def task(): ...

with start_transaction(name="custom_transaction"):
with start_span(name="custom_transaction"):
task.apply_async()

(event,) = events
Expand All @@ -799,7 +799,7 @@ def test_send_task_wrapped(

events = capture_events()

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

(call,) = patched_send_task.call_args_list # We should have exactly one call
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/celery/test_update_celery_task_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_span_with_transaction(sentry_init):
headers = {}
monitor_beat_tasks = False

with sentry_sdk.start_transaction(name="test_transaction") as transaction:
with sentry_sdk.start_span(name="test_transaction") as transaction:
with sentry_sdk.start_span(op="test_span") as span:
outgoing_headers = _update_celery_task_headers(
headers, span, monitor_beat_tasks
Expand All @@ -97,7 +97,7 @@ def test_span_with_transaction_custom_headers(sentry_init):
"sentry-trace": SENTRY_TRACE_VALUE,
}

with sentry_sdk.start_transaction(name="test_transaction") as transaction:
with sentry_sdk.start_span(name="test_transaction") as transaction:
with sentry_sdk.start_span(op="test_span") as span:
outgoing_headers = _update_celery_task_headers(headers, span, False)

Expand Down
Loading
Loading