diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index cd2b3cc417..8899cc53b2 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -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, diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index a943871335..43321ec89b 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -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, diff --git a/sentry_sdk/integrations/gcp.py b/sentry_sdk/integrations/gcp.py index dd23ad1e0a..ec626ed699 100644 --- a/sentry_sdk/integrations/gcp.py +++ b/sentry_sdk/integrations/gcp.py @@ -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, diff --git a/sentry_sdk/integrations/grpc/aio/server.py b/sentry_sdk/integrations/grpc/aio/server.py index 6d38e91363..4d54b0605c 100644 --- a/sentry_sdk/integrations/grpc/aio/server.py +++ b/sentry_sdk/integrations/grpc/aio/server.py @@ -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, diff --git a/sentry_sdk/integrations/grpc/server.py b/sentry_sdk/integrations/grpc/server.py index fb123c5ca4..d12b43b92b 100644 --- a/sentry_sdk/integrations/grpc/server.py +++ b/sentry_sdk/integrations/grpc/server.py @@ -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, diff --git a/sentry_sdk/integrations/tornado.py b/sentry_sdk/integrations/tornado.py index bb40fbf625..1af8950aa4 100644 --- a/sentry_sdk/integrations/tornado.py +++ b/sentry_sdk/integrations/tornado.py @@ -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. diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 16dfd9c4fa..403ac84220 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -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() ``` """ diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 4b491b152e..7960bc2dcc 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -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 @@ -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("/") @@ -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) @@ -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: @@ -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: diff --git a/tests/integrations/anthropic/test_anthropic.py b/tests/integrations/anthropic/test_anthropic.py index 4a7d7ed458..ece2cfe7a3 100644 --- a/tests/integrations/anthropic/test_anthropic.py +++ b/tests/integrations/anthropic/test_anthropic.py @@ -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 @@ -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" ) @@ -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" ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 @@ -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 diff --git a/tests/integrations/arq/test_arq.py b/tests/integrations/arq/test_arq.py index e74395e26c..0ebb97cd2b 100644 --- a/tests/integrations/arq/test_arq.py +++ b/tests/integrations/arq/test_arq.py @@ -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 @@ -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 @@ -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 diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index 1011429098..2f8de6968a 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -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, @@ -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) @@ -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: @@ -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" @@ -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() @@ -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 @@ -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"}, @@ -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", @@ -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( @@ -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 @@ -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 @@ -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 diff --git a/tests/integrations/celery/test_update_celery_task_headers.py b/tests/integrations/celery/test_update_celery_task_headers.py index 705c00de58..709e49b54a 100644 --- a/tests/integrations/celery/test_update_celery_task_headers.py +++ b/tests/integrations/celery/test_update_celery_task_headers.py @@ -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 @@ -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) diff --git a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py index 2c3d3c41a4..7eb0462231 100644 --- a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py +++ b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py @@ -8,7 +8,7 @@ import clickhouse_driver from clickhouse_driver import Client, connect -from sentry_sdk import start_transaction, capture_message +from sentry_sdk import start_span, capture_message from sentry_sdk.integrations.clickhouse_driver import ClickhouseDriverIntegration from tests.conftest import ApproxDict @@ -227,7 +227,7 @@ def test_clickhouse_client_spans( transaction_trace_id = None transaction_span_id = None - with start_transaction(name="test_clickhouse_transaction") as transaction: + with start_span(name="test_clickhouse_transaction") as transaction: transaction_trace_id = transaction.trace_id transaction_span_id = transaction.span_id @@ -360,7 +360,7 @@ def test_clickhouse_client_spans_with_pii(sentry_init, capture_events) -> None: transaction_trace_id = None transaction_span_id = None - with start_transaction(name="test_clickhouse_transaction") as transaction: + with start_span(name="test_clickhouse_transaction") as transaction: transaction_trace_id = transaction.trace_id transaction_span_id = transaction.span_id @@ -701,7 +701,7 @@ def test_clickhouse_dbapi_spans(sentry_init, capture_events, capture_envelopes) transaction_trace_id = None transaction_span_id = None - with start_transaction(name="test_clickhouse_transaction") as transaction: + with start_span(name="test_clickhouse_transaction") as transaction: transaction_trace_id = transaction.trace_id transaction_span_id = transaction.span_id @@ -835,7 +835,7 @@ def test_clickhouse_dbapi_spans_with_pii( transaction_trace_id = None transaction_span_id = None - with start_transaction(name="test_clickhouse_transaction") as transaction: + with start_span(name="test_clickhouse_transaction") as transaction: transaction_trace_id = transaction.trace_id transaction_span_id = transaction.span_id @@ -975,7 +975,7 @@ def test_span_origin(sentry_init, capture_events, capture_envelopes) -> None: events = capture_events() - with start_transaction(name="test_clickhouse_transaction"): + with start_span(name="test_clickhouse_transaction"): conn = connect("clickhouse://localhost") cursor = conn.cursor() cursor.execute("SELECT 1") diff --git a/tests/integrations/cohere/test_cohere.py b/tests/integrations/cohere/test_cohere.py index 672d71b6b3..ff41ceba11 100644 --- a/tests/integrations/cohere/test_cohere.py +++ b/tests/integrations/cohere/test_cohere.py @@ -4,7 +4,7 @@ import pytest from cohere import Client, ChatMessage -from sentry_sdk import start_transaction +from sentry_sdk import start_span from sentry_sdk.integrations.cohere import CohereIntegration from unittest import mock # python 3.3 and above @@ -41,7 +41,7 @@ def test_nonstreaming_chat( ) ) - with start_transaction(name="cohere tx"): + with start_span(name="cohere tx"): response = client.chat( model="some-model", chat_history=[ChatMessage(role="SYSTEM", message="some context")], @@ -110,7 +110,7 @@ def test_streaming_chat(sentry_init, capture_events, send_default_pii, include_p ) ) - with start_transaction(name="cohere tx"): + with start_span(name="cohere tx"): responses = list( client.chat_stream( model="some-model", @@ -186,7 +186,7 @@ def test_embed(sentry_init, capture_events, send_default_pii, include_prompts): ) ) - with start_transaction(name="cohere tx"): + with start_span(name="cohere tx"): response = client.embed(texts=["hello"], model="text-embedding-3-large") assert len(response.embeddings[0]) == 3 @@ -227,7 +227,7 @@ def test_span_origin_chat(sentry_init, capture_events): ) ) - with start_transaction(name="cohere tx"): + with start_span(name="cohere tx"): client.chat( model="some-model", chat_history=[ChatMessage(role="SYSTEM", message="some context")], @@ -265,7 +265,7 @@ def test_span_origin_embed(sentry_init, capture_events): ) ) - with start_transaction(name="cohere tx"): + with start_span(name="cohere tx"): client.embed(texts=["hello"], model="text-embedding-3-large") (event,) = events diff --git a/tests/integrations/django/test_cache_module.py b/tests/integrations/django/test_cache_module.py index 03e4925ab0..2d8cc3d5d6 100644 --- a/tests/integrations/django/test_cache_module.py +++ b/tests/integrations/django/test_cache_module.py @@ -530,7 +530,7 @@ def test_cache_spans_get_many( from django.core.cache import cache - with sentry_sdk.start_transaction(name="caches"): + with sentry_sdk.start_span(name="caches"): cache.get_many([f"S{id}", f"S{id+1}"]) cache.set(f"S{id}", "Sensitive1") cache.get_many([f"S{id}", f"S{id+1}"]) @@ -574,7 +574,7 @@ def test_cache_spans_set_many( from django.core.cache import cache - with sentry_sdk.start_transaction(name="caches"): + with sentry_sdk.start_span(name="caches"): cache.set_many({f"S{id}": "Sensitive1", f"S{id+1}": "Sensitive2"}) cache.get(f"S{id}") diff --git a/tests/integrations/django/test_db_query_data.py b/tests/integrations/django/test_db_query_data.py index ccbe6ee28a..82f1f339a6 100644 --- a/tests/integrations/django/test_db_query_data.py +++ b/tests/integrations/django/test_db_query_data.py @@ -16,7 +16,7 @@ from freezegun import freeze_time from werkzeug.test import Client -from sentry_sdk import start_transaction, start_span +from sentry_sdk import start_span from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.tracing_utils import record_sql_queries @@ -496,7 +496,7 @@ def test_db_span_origin_executemany(sentry_init, client, capture_events): if "postgres" not in connections: pytest.skip("postgres tests disabled") - with start_transaction(name="test_transaction"): + with start_span(name="test_transaction"): from django.db import connection, transaction cursor = connection.cursor() diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index f43159d80e..7e84d648ee 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -6,7 +6,7 @@ ) from huggingface_hub.errors import OverloadedError -from sentry_sdk import start_transaction +from sentry_sdk import start_span from sentry_sdk.integrations.huggingface_hub import HuggingfaceHubIntegration from unittest import mock # python 3.3 and above @@ -43,7 +43,7 @@ def test_nonstreaming_chat_completion( client.post = mock.Mock( return_value=b'[{"generated_text": "the model response"}]' ) - with start_transaction(name="huggingface_hub tx"): + with start_span(name="huggingface_hub tx"): response = client.text_generation( prompt="hello", details=details_arg, @@ -95,7 +95,7 @@ def test_streaming_chat_completion( }""", ] ) - with start_transaction(name="huggingface_hub tx"): + with start_span(name="huggingface_hub tx"): response = list( client.text_generation( prompt="hello", @@ -154,7 +154,7 @@ def test_span_origin(sentry_init, capture_events): }""", ] ) - with start_transaction(name="huggingface_hub tx"): + with start_span(name="huggingface_hub tx"): list( client.text_generation( prompt="hello", diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index b9e5705b88..2ac6679321 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -14,7 +14,7 @@ from langchain_core.messages import BaseMessage, AIMessageChunk from langchain_core.outputs import ChatGenerationChunk -from sentry_sdk import start_transaction +from sentry_sdk import start_span from sentry_sdk.integrations.langchain import LangchainIntegration from langchain.agents import tool, AgentExecutor, create_openai_tools_agent from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder @@ -163,7 +163,7 @@ def test_langchain_agent( agent_executor = AgentExecutor(agent=agent, tools=[get_word_length], verbose=True) - with start_transaction(): + with start_span(name="agent"): list(agent_executor.stream({"input": "How many letters in the word eudca"})) tx = events[0] @@ -237,7 +237,7 @@ def test_langchain_error(sentry_init, capture_events): agent_executor = AgentExecutor(agent=agent, tools=[get_word_length], verbose=True) - with start_transaction(), pytest.raises(Exception): + with start_span(name="agent"), pytest.raises(Exception): list(agent_executor.stream({"input": "How many letters in the word eudca"})) error = events[0] @@ -332,7 +332,7 @@ def test_span_origin(sentry_init, capture_events): agent_executor = AgentExecutor(agent=agent, tools=[get_word_length], verbose=True) - with start_transaction(): + with start_span(name="agent"): list(agent_executor.stream({"input": "How many letters in the word eudca"})) (event,) = events diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index 011192e49f..793cda8b31 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -6,7 +6,7 @@ from openai.types.chat.chat_completion_chunk import ChoiceDelta, Choice as DeltaChoice from openai.types.create_embedding_response import Usage as EmbeddingTokenUsage -from sentry_sdk import start_transaction +from sentry_sdk import start_span from sentry_sdk.integrations.openai import ( OpenAIIntegration, _calculate_chat_completion_usage, @@ -67,7 +67,7 @@ def test_nonstreaming_chat_completion( client = OpenAI(api_key="z") client.chat.completions._post = mock.Mock(return_value=EXAMPLE_CHAT_COMPLETION) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response = ( client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] @@ -112,7 +112,7 @@ async def test_nonstreaming_chat_completion_async( client = AsyncOpenAI(api_key="z") client.chat.completions._post = AsyncMock(return_value=EXAMPLE_CHAT_COMPLETION) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response = await client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -204,7 +204,7 @@ def test_streaming_chat_completion( ] client.chat.completions._post = mock.Mock(return_value=returned_stream) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response_stream = client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -298,7 +298,7 @@ async def test_streaming_chat_completion_async( ) client.chat.completions._post = AsyncMock(return_value=returned_stream) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response_stream = await client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -392,7 +392,7 @@ def test_embeddings_create( ) client.embeddings._post = mock.Mock(return_value=returned_embedding) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response = client.embeddings.create( input="hello", model="text-embedding-3-large" ) @@ -440,7 +440,7 @@ async def test_embeddings_create_async( ) client.embeddings._post = AsyncMock(return_value=returned_embedding) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response = await client.embeddings.create( input="hello", model="text-embedding-3-large" ) @@ -525,7 +525,7 @@ def test_span_origin_nonstreaming_chat(sentry_init, capture_events): client = OpenAI(api_key="z") client.chat.completions._post = mock.Mock(return_value=EXAMPLE_CHAT_COMPLETION) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -547,7 +547,7 @@ async def test_span_origin_nonstreaming_chat_async(sentry_init, capture_events): client = AsyncOpenAI(api_key="z") client.chat.completions._post = AsyncMock(return_value=EXAMPLE_CHAT_COMPLETION) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): await client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -604,7 +604,7 @@ def test_span_origin_streaming_chat(sentry_init, capture_events): ] client.chat.completions._post = mock.Mock(return_value=returned_stream) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response_stream = client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -668,7 +668,7 @@ async def test_span_origin_streaming_chat_async(sentry_init, capture_events): ) client.chat.completions._post = AsyncMock(return_value=returned_stream) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): response_stream = await client.chat.completions.create( model="some-model", messages=[{"role": "system", "content": "hello"}] ) @@ -703,7 +703,7 @@ def test_span_origin_embeddings(sentry_init, capture_events): ) client.embeddings._post = mock.Mock(return_value=returned_embedding) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): client.embeddings.create(input="hello", model="text-embedding-3-large") (event,) = events @@ -733,7 +733,7 @@ async def test_span_origin_embeddings_async(sentry_init, capture_events): ) client.embeddings._post = AsyncMock(return_value=returned_embedding) - with start_transaction(name="openai tx"): + with start_span(name="openai tx"): await client.embeddings.create(input="hello", model="text-embedding-3-large") (event,) = events diff --git a/tests/integrations/redis/test_redis_cache_module.py b/tests/integrations/redis/test_redis_cache_module.py index e02b1ec31a..b1c012e5ee 100644 --- a/tests/integrations/redis/test_redis_cache_module.py +++ b/tests/integrations/redis/test_redis_cache_module.py @@ -24,7 +24,7 @@ def test_no_cache_basic(sentry_init, capture_events, render_span_tree): events = capture_events() connection = FakeStrictRedis() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="cache"): connection.get("mycachekey") (event,) = events @@ -49,7 +49,7 @@ def test_cache_basic(sentry_init, capture_events, render_span_tree): events = capture_events() connection = FakeStrictRedis() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="cache"): connection.hget("mycachekey", "myfield") connection.get("mycachekey") connection.set("mycachekey1", "bla") @@ -87,7 +87,7 @@ def test_cache_keys(sentry_init, capture_events, render_span_tree): events = capture_events() connection = FakeStrictRedis() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="cache"): connection.get("somethingelse") connection.get("blub") connection.get("blubkeything") @@ -120,7 +120,7 @@ def test_cache_data(sentry_init, capture_events): events = capture_events() connection = FakeStrictRedis(host="mycacheserver.io", port=6378) - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="cache"): connection.get("mycachekey") connection.set("mycachekey", "事实胜于雄辩") connection.get("mycachekey") @@ -203,7 +203,7 @@ def test_cache_prefixes(sentry_init, capture_events): events = capture_events() connection = FakeStrictRedis() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="cache"): connection.mget("yes", "no") connection.mget("no", 1, "yes") connection.mget("no", "yes.1", "yes.2") diff --git a/tests/integrations/redis_py_cluster_legacy/test_redis_py_cluster_legacy.py b/tests/integrations/redis_py_cluster_legacy/test_redis_py_cluster_legacy.py index 5e0b724436..a530fec115 100644 --- a/tests/integrations/redis_py_cluster_legacy/test_redis_py_cluster_legacy.py +++ b/tests/integrations/redis_py_cluster_legacy/test_redis_py_cluster_legacy.py @@ -4,7 +4,7 @@ import rediscluster from sentry_sdk import capture_message -from sentry_sdk.api import start_transaction +from sentry_sdk.api import start_span from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.redis import RedisIntegration from tests.conftest import ApproxDict @@ -84,7 +84,7 @@ def test_rediscluster_pipeline( events = capture_events() rc = rediscluster.RedisCluster(connection_pool=MOCK_CONNECTION_POOL) - with start_transaction(): + with start_span(name="redis"): pipeline = rc.pipeline() pipeline.get("foo") pipeline.set("bar", 1) @@ -120,7 +120,7 @@ def test_db_connection_attributes_client(sentry_init, capture_events, redisclust events = capture_events() rc = rediscluster_cls(connection_pool=MOCK_CONNECTION_POOL) - with start_transaction(): + with start_span(name="redis"): rc.get("foobar") (event,) = events @@ -147,7 +147,7 @@ def test_db_connection_attributes_pipeline( events = capture_events() rc = rediscluster.RedisCluster(connection_pool=MOCK_CONNECTION_POOL) - with start_transaction(): + with start_span(name="redis"): pipeline = rc.pipeline() pipeline.get("foo") pipeline.execute() diff --git a/tests/integrations/socket/test_socket.py b/tests/integrations/socket/test_socket.py index e629114b2b..500e9b5608 100644 --- a/tests/integrations/socket/test_socket.py +++ b/tests/integrations/socket/test_socket.py @@ -1,6 +1,6 @@ import socket -from sentry_sdk import start_transaction +from sentry_sdk import start_span from sentry_sdk.integrations.socket import SocketIntegration from tests.conftest import ApproxDict @@ -9,7 +9,7 @@ def test_getaddrinfo_trace(sentry_init, capture_events): sentry_init(integrations=[SocketIntegration()], traces_sample_rate=1.0) events = capture_events() - with start_transaction(): + with start_span(name="socket"): socket.getaddrinfo("example.com", 443) (event,) = events @@ -31,7 +31,7 @@ def test_create_connection_trace(sentry_init, capture_events): sentry_init(integrations=[SocketIntegration()], traces_sample_rate=1.0) events = capture_events() - with start_transaction(): + with start_span(name="socket"): socket.create_connection(("example.com", 443), timeout, None) (event,) = events @@ -65,7 +65,7 @@ def test_span_origin(sentry_init, capture_events): ) events = capture_events() - with start_transaction(name="foo"): + with start_span(name="foo"): socket.create_connection(("example.com", 443), 1, None) (event,) = events diff --git a/tests/integrations/tornado/test_tornado.py b/tests/integrations/tornado/test_tornado.py index 837da07434..e5dae3fcd9 100644 --- a/tests/integrations/tornado/test_tornado.py +++ b/tests/integrations/tornado/test_tornado.py @@ -4,7 +4,7 @@ import pytest import sentry_sdk -from sentry_sdk import start_transaction, capture_message +from sentry_sdk import start_span, capture_message from sentry_sdk.integrations.tornado import TornadoIntegration from tornado.web import RequestHandler, Application, HTTPError @@ -117,7 +117,7 @@ def test_transactions(tornado_testcase, sentry_init, capture_events, handler, co events = capture_events() client = tornado_testcase(Application([(r"/hi", handler)])) - with start_transaction(name="client") as span: + with start_span(name="client") as span: pass response = client.fetch( @@ -135,7 +135,7 @@ def test_transactions(tornado_testcase, sentry_init, capture_events, handler, co assert client_tx["transaction"] == "client" assert client_tx["transaction_info"] == { "source": "custom" - } # because this is just the start_transaction() above. + } # because this is just the start_span() above. if server_error is not None: assert server_error["exception"]["values"][0]["type"] == "ZeroDivisionError" diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 1b96f27036..f56afe656e 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -198,7 +198,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( thread = threading.current_thread() - with sentry_sdk.start_transaction(name="profiling"): + with sentry_sdk.start_span(name="profiling"): with sentry_sdk.start_span(op="op"): time.sleep(0.05) @@ -209,7 +209,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( envelopes.clear() - with sentry_sdk.start_transaction(name="profiling"): + with sentry_sdk.start_span(name="profiling"): with sentry_sdk.start_span(op="op"): time.sleep(0.05) @@ -219,7 +219,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( envelopes.clear() - with sentry_sdk.start_transaction(name="profiling"): + with sentry_sdk.start_span(name="profiling"): with sentry_sdk.start_span(op="op"): time.sleep(0.05) @@ -260,7 +260,7 @@ def test_continuous_profiler_manual_start_and_stop( envelopes.clear() - with sentry_sdk.start_transaction(name="profiling"): + with sentry_sdk.start_span(name="profiling"): with sentry_sdk.start_span(op="op"): time.sleep(0.05) @@ -270,7 +270,7 @@ def test_continuous_profiler_manual_start_and_stop( envelopes.clear() - with sentry_sdk.start_transaction(name="profiling"): + with sentry_sdk.start_span(name="profiling"): with sentry_sdk.start_span(op="op"): time.sleep(0.05) diff --git a/tests/profiler/test_transaction_profiler.py b/tests/profiler/test_transaction_profiler.py index a77942e788..7679831be3 100644 --- a/tests/profiler/test_transaction_profiler.py +++ b/tests/profiler/test_transaction_profiler.py @@ -9,7 +9,7 @@ import pytest -from sentry_sdk import start_transaction +from sentry_sdk import start_span from sentry_sdk.profiler.transaction_profiler import ( GeventScheduler, Profile, @@ -148,7 +148,7 @@ def test_profiles_sample_rate( with mock.patch( "sentry_sdk.profiler.transaction_profiler.random.random", return_value=0.5 ): - with start_transaction(name="profiling"): + with start_span(name="profiling"): pass items = defaultdict(list) @@ -219,7 +219,7 @@ def test_profiles_sampler( with mock.patch( "sentry_sdk.profiler.transaction_profiler.random.random", return_value=0.5 ): - with start_transaction(name="profiling"): + with start_span(name="profiling"): pass items = defaultdict(list) @@ -249,7 +249,7 @@ def test_minimum_unique_samples_required( envelopes = capture_envelopes() record_lost_event_calls = capture_record_lost_event_calls() - with start_transaction(name="profiling"): + with start_span(name="profiling"): pass items = defaultdict(list) @@ -277,7 +277,7 @@ def test_profile_captured( envelopes = capture_envelopes() - with start_transaction(name="profiling"): + with start_span(name="profiling"): time.sleep(0.05) items = defaultdict(list) diff --git a/tests/test_ai_monitoring.py b/tests/test_ai_monitoring.py index 5e7c7432fa..9ecd75fc84 100644 --- a/tests/test_ai_monitoring.py +++ b/tests/test_ai_monitoring.py @@ -16,7 +16,7 @@ def tool(**kwargs): def pipeline(): tool() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="pipeline"): pipeline() transaction = events[0] @@ -43,7 +43,7 @@ def tool(**kwargs): def pipeline(): tool() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="pipeline"): pipeline(sentry_tags={"user": "colin"}, sentry_data={"some_data": "value"}) transaction = events[0] @@ -74,7 +74,7 @@ async def async_tool(**kwargs): async def async_pipeline(): await async_tool() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="async_pipeline"): await async_pipeline() transaction = events[0] @@ -102,7 +102,7 @@ async def async_tool(**kwargs): async def async_pipeline(): await async_tool() - with sentry_sdk.start_transaction(): + with sentry_sdk.start_span(name="async_pipeline"): await async_pipeline( sentry_tags={"user": "czyber"}, sentry_data={"some_data": "value"} ) diff --git a/tests/test_basics.py b/tests/test_basics.py index 3c05f9848a..cbf0177403 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -16,7 +16,7 @@ capture_event, capture_exception, capture_message, - start_transaction, + start_span, last_event_id, add_breadcrumb, isolation_scope, @@ -174,7 +174,7 @@ def before_send_transaction(event, hint): traces_sample_rate=1.0, ) events = capture_events() - transaction = start_transaction(name="foo") + transaction = start_span(name="foo") transaction.finish() (event,) = events @@ -191,7 +191,7 @@ def before_send_transaction_discard(event, hint): traces_sample_rate=1.0, ) events = capture_events() - transaction = start_transaction(name="foo") + transaction = start_span(name="foo") transaction.finish() assert len(events) == 0 @@ -592,7 +592,7 @@ def foo(event, hint): capture_message("dropped") - with start_transaction(name="dropped"): + with start_span(name="dropped"): pass assert len(events) == 0 @@ -697,7 +697,7 @@ def test_functions_to_trace(sentry_init, capture_events): events = capture_events() - with start_transaction(name="something"): + with start_span(name="something"): time.sleep(0) for word in ["World", "You"]: @@ -733,7 +733,7 @@ def test_functions_to_trace_with_class(sentry_init, capture_events): events = capture_events() - with start_transaction(name="something"): + with start_span(name="something"): wg = WorldGreeter("World") wg.greet() wg.greet("You") @@ -822,7 +822,7 @@ def test_last_event_id_transaction(sentry_init): assert last_event_id() is None - with start_transaction(name="test"): + with start_span(name="test"): pass assert last_event_id() is None, "Transaction should not set last_event_id" diff --git a/tests/test_scope.py b/tests/test_scope.py index e7194e6caf..cdeeec72c9 100644 --- a/tests/test_scope.py +++ b/tests/test_scope.py @@ -785,7 +785,7 @@ def test_nested_scopes_with_tags(sentry_init, capture_envelopes): with sentry_sdk.new_scope() as scope2: scope2.set_tag("current_scope2", 1) - with sentry_sdk.start_transaction(name="trx") as trx: + with sentry_sdk.start_span(name="trx") as trx: trx.set_tag("trx", 1) with sentry_sdk.start_span(op="span1") as span1: @@ -876,7 +876,7 @@ def test_last_event_id_transaction(sentry_init): assert Scope.last_event_id() is None - with sentry_sdk.start_transaction(name="test"): + with sentry_sdk.start_span(name="test"): pass assert Scope.last_event_id() is None, "Transaction should not set last_event_id" diff --git a/tests/test_scrubber.py b/tests/test_scrubber.py index 2c462153dd..8bef3bac10 100644 --- a/tests/test_scrubber.py +++ b/tests/test_scrubber.py @@ -1,7 +1,7 @@ import sys import logging -from sentry_sdk import capture_exception, capture_event, start_transaction, start_span +from sentry_sdk import capture_exception, capture_event, start_span from sentry_sdk.utils import event_from_exception from sentry_sdk.scrubber import EventScrubber from tests.conftest import ApproxDict @@ -145,7 +145,7 @@ def test_span_data_scrubbing(sentry_init, capture_events): sentry_init(traces_sample_rate=1.0) events = capture_events() - with start_transaction(name="hi"): + with start_span(name="hi"): with start_span(op="foo", name="bar") as span: span.set_data("password", "secret") span.set_data("datafoo", "databar")