From f64859d1221c50c5bae2ad005cd6c1eaab5c7c2b Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 22 Sep 2026 11:39:52 +0200 Subject: [PATCH 1/3] ref: Use top-level start_span --- sentry_sdk/integrations/aiohttp.py | 4 +- sentry_sdk/integrations/aiomysql.py | 2 +- sentry_sdk/integrations/anthropic.py | 8 +- sentry_sdk/integrations/arq.py | 4 +- sentry_sdk/integrations/asgi.py | 4 +- sentry_sdk/integrations/asyncio.py | 2 +- sentry_sdk/integrations/asyncpg.py | 2 +- sentry_sdk/integrations/aws_lambda.py | 2 +- sentry_sdk/integrations/boto3.py | 4 +- sentry_sdk/integrations/celery/__init__.py | 8 +- sentry_sdk/integrations/clickhouse_driver.py | 2 +- sentry_sdk/integrations/cohere.py | 4 +- sentry_sdk/integrations/django/__init__.py | 8 +- sentry_sdk/integrations/django/asgi.py | 2 +- sentry_sdk/integrations/django/caching.py | 2 +- sentry_sdk/integrations/django/middleware.py | 2 +- .../integrations/django/signals_handlers.py | 2 +- sentry_sdk/integrations/django/tasks.py | 2 +- sentry_sdk/integrations/django/templates.py | 4 +- sentry_sdk/integrations/django/views.py | 4 +- sentry_sdk/integrations/dramatiq.py | 2 +- sentry_sdk/integrations/gcp.py | 2 +- .../integrations/google_genai/__init__.py | 12 +- sentry_sdk/integrations/google_genai/utils.py | 2 +- sentry_sdk/integrations/graphene.py | 2 +- sentry_sdk/integrations/grpc/aio/client.py | 4 +- sentry_sdk/integrations/grpc/aio/server.py | 2 +- sentry_sdk/integrations/grpc/client.py | 4 +- sentry_sdk/integrations/grpc/server.py | 2 +- sentry_sdk/integrations/httpx.py | 4 +- sentry_sdk/integrations/httpx2.py | 4 +- sentry_sdk/integrations/huey.py | 4 +- sentry_sdk/integrations/huggingface_hub.py | 2 +- sentry_sdk/integrations/langchain.py | 8 +- sentry_sdk/integrations/langgraph.py | 4 +- sentry_sdk/integrations/litellm.py | 2 +- sentry_sdk/integrations/litestar.py | 6 +- sentry_sdk/integrations/mcp.py | 6 +- sentry_sdk/integrations/openai.py | 12 +- .../openai_agents/spans/agent_workflow.py | 2 +- .../openai_agents/spans/execute_tool.py | 2 +- .../openai_agents/spans/handoff.py | 2 +- .../openai_agents/spans/invoke_agent.py | 2 +- .../pydantic_ai/spans/execute_tool.py | 2 +- .../pydantic_ai/spans/invoke_agent.py | 2 +- sentry_sdk/integrations/pymongo.py | 2 +- sentry_sdk/integrations/pyreqwest.py | 2 +- sentry_sdk/integrations/ray.py | 4 +- .../integrations/redis/_async_common.py | 6 +- sentry_sdk/integrations/redis/_sync_common.py | 6 +- sentry_sdk/integrations/rq.py | 2 +- sentry_sdk/integrations/rust_tracing.py | 2 +- sentry_sdk/integrations/sanic.py | 2 +- sentry_sdk/integrations/socket.py | 4 +- sentry_sdk/integrations/starlette.py | 2 +- sentry_sdk/integrations/starlite.py | 2 +- sentry_sdk/integrations/stdlib.py | 8 +- sentry_sdk/integrations/strawberry.py | 10 +- sentry_sdk/integrations/tornado.py | 2 +- sentry_sdk/integrations/wsgi.py | 2 +- sentry_sdk/utils.py | 2 +- tests/integrations/aiohttp/test_aiohttp.py | 10 +- tests/integrations/aiomysql/test_aiomysql.py | 16 +- .../integrations/anthropic/test_anthropic.py | 2 +- tests/integrations/arq/test_arq.py | 4 +- tests/integrations/asgi/test_asgi.py | 2 +- tests/integrations/asyncio/test_asyncio.py | 24 +-- tests/integrations/asyncpg/test_asyncpg.py | 26 +-- .../boto3/test_aws_http_connection.py | 8 +- tests/integrations/boto3/test_s3.py | 16 +- .../boto3/test_trace_propagation.py | 4 +- tests/integrations/celery/test_celery.py | 20 +-- .../celery/test_update_celery_task_headers.py | 8 +- tests/integrations/chalice/test_chalice.py | 4 +- .../test_clickhouse_driver.py | 12 +- .../integrations/django/test_cache_module.py | 6 +- .../integrations/django/test_db_query_data.py | 2 +- .../django/test_db_transactions.py | 18 +- tests/integrations/django/test_tasks.py | 8 +- tests/integrations/dramatiq/test_dramatiq.py | 2 +- tests/integrations/fastapi/test_fastapi.py | 4 +- tests/integrations/fastmcp/test_fastmcp.py | 2 +- tests/integrations/grpc/test_grpc.py | 16 +- tests/integrations/grpc/test_grpc_aio.py | 10 +- tests/integrations/httpx/test_httpx.py | 70 ++++---- tests/integrations/httpx2/test_httpx2.py | 74 ++++----- tests/integrations/huey/test_huey.py | 10 +- .../launchdarkly/test_launchdarkly.py | 2 +- tests/integrations/mcp/test_mcp.py | 2 +- .../openai_agents/test_openai_agents.py | 8 +- .../openfeature/test_openfeature.py | 2 +- .../pydantic_ai/test_pydantic_ai.py | 32 ++-- tests/integrations/pymongo/test_pymongo.py | 10 +- .../integrations/pyreqwest/test_pyreqwest.py | 58 +++---- tests/integrations/ray/test_ray.py | 18 +- .../redis/asyncio/test_redis_asyncio.py | 4 +- .../redis/cluster/test_redis_cluster.py | 6 +- .../test_redis_cluster_asyncio.py | 6 +- tests/integrations/redis/test_redis.py | 22 +-- .../redis/test_redis_cache_module.py | 10 +- .../redis/test_redis_cache_module_async.py | 8 +- tests/integrations/rq/test_rq.py | 2 +- .../rust_tracing/test_rust_tracing.py | 20 +-- tests/integrations/sanic/test_sanic.py | 2 +- tests/integrations/socket/test_socket.py | 6 +- .../sqlalchemy/test_sqlalchemy.py | 20 +-- tests/integrations/statsig/test_statsig.py | 2 +- tests/integrations/stdlib/test_httplib.py | 30 ++-- tests/integrations/stdlib/test_subprocess.py | 6 +- .../integrations/threading/test_threading.py | 14 +- tests/integrations/tornado/test_tornado.py | 4 +- tests/integrations/unleash/test_unleash.py | 2 +- tests/integrations/wsgi/test_wsgi.py | 4 +- tests/profiler/test_continuous_profiler.py | 40 ++--- tests/test_api.py | 10 +- tests/test_attributes.py | 2 +- tests/test_basics.py | 12 +- tests/test_dsc.py | 10 +- tests/test_feature_flags.py | 8 +- tests/test_logs.py | 6 +- tests/test_metrics.py | 2 +- tests/test_monitor.py | 2 +- tests/test_scope.py | 8 +- tests/tracing/test_conversation_id.py | 32 ++-- tests/tracing/test_decorator.py | 8 +- tests/tracing/test_http_headers.py | 4 +- tests/tracing/test_integration_tests.py | 48 +++--- tests/tracing/test_misc.py | 8 +- tests/tracing/test_propagation.py | 10 +- tests/tracing/test_sample_rand.py | 4 +- tests/tracing/test_sample_rand_propagation.py | 4 +- tests/tracing/test_sampling.py | 64 +++---- tests/tracing/test_span_batcher.py | 96 +++++------ tests/tracing/test_span_origin.py | 6 +- tests/tracing/test_span_streaming.py | 156 +++++++++--------- 135 files changed, 715 insertions(+), 729 deletions(-) diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index 32441f4e04..0202efc242 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -197,7 +197,7 @@ async def sentry_app_handle( SPANDATA.USER_IP_ADDRESS, request.remote ) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( # If this name makes it to the UI, AIOHTTP's URL # resolver did not find a route or died trying. name="generic AIOHTTP request", @@ -386,7 +386,7 @@ async def on_request_start( breadcrumb["url"] = url_full if sentry_sdk.traces.get_current_span() is not None: - span = sentry_sdk.traces.start_span(name=span_name, attributes=attributes) + span = sentry_sdk.start_span(name=span_name, attributes=attributes) if should_propagate_trace(client, str(params.url)): # existing `sentry-trace`: skip so it is not duplicated. diff --git a/sentry_sdk/integrations/aiomysql.py b/sentry_sdk/integrations/aiomysql.py index e85baa0b1a..fce49ed8ca 100644 --- a/sentry_sdk/integrations/aiomysql.py +++ b/sentry_sdk/integrations/aiomysql.py @@ -201,7 +201,7 @@ async def _inner(self: "Connection") -> T: "sentry.origin": AioMySQLIntegration.origin, } | breadcrumb_data - with sentry_sdk.traces.start_span(name="connect", attributes=span_attributes): + with sentry_sdk.start_span(name="connect", attributes=span_attributes): return await f(self) return _inner diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 070fbbb0cc..da3f5347cc 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -722,7 +722,7 @@ def _sentry_patched_create_sync(f: "Any", *args: "Any", **kwargs: "Any") -> "Any model = kwargs.get("model", "") - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"chat {model}".strip(), attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -812,7 +812,7 @@ async def _sentry_patched_create_async( model = kwargs.get("model", "") - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"chat {model}".strip(), attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -1053,7 +1053,7 @@ def _sentry_patched_enter(self: "MessageStreamManager") -> "MessageStream": except TypeError: return f(self) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="chat" if patched_self._model is None else f"chat {patched_self._model}".strip(), @@ -1157,7 +1157,7 @@ async def _sentry_patched_aenter( except TypeError: return await f(self) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="chat" if patched_self._model is None else f"chat {patched_self._model}".strip(), diff --git a/sentry_sdk/integrations/arq.py b/sentry_sdk/integrations/arq.py index 021afdfa7b..95a11a45cc 100644 --- a/sentry_sdk/integrations/arq.py +++ b/sentry_sdk/integrations/arq.py @@ -80,7 +80,7 @@ async def _sentry_enqueue_job( if sentry_sdk.traces.get_current_span() is None: return await old_enqueue_job(self, function, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=function, attributes={ "sentry.op": OP.QUEUE_SUBMIT_ARQ, @@ -105,7 +105,7 @@ async def _sentry_run_job(self: "Worker", job_id: str, score: int) -> None: scope._name = "arq" scope.clear_breadcrumbs() - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unknown arq task", attributes={ "sentry.op": OP.QUEUE_TASK_ARQ, diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 9bcecc975c..404afd5f60 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -240,7 +240,7 @@ async def _run_app( Scope.set_custom_sampling_context({"asgi_scope": scope}) attributes["sentry.op"] = f"{ty}.server" - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=transaction_name, attributes=attributes, parent_span=None, @@ -252,7 +252,7 @@ async def _run_app( Scope.set_custom_sampling_context({"asgi_scope": scope}) attributes["sentry.op"] = OP.HTTP_SERVER - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=transaction_name, attributes=attributes, parent_span=None, diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py index 5f1823b0aa..bc38f91617 100644 --- a/sentry_sdk/integrations/asyncio.py +++ b/sentry_sdk/integrations/asyncio.py @@ -149,7 +149,7 @@ async def _task_with_sentry_span_creation() -> "Any": with sentry_sdk.isolation_scope(): span_ctx = nullcontext() if task_spans and sentry_sdk.traces.get_current_span() is not None: - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name=get_name(coro), attributes={ "sentry.op": OP.FUNCTION, diff --git a/sentry_sdk/integrations/asyncpg.py b/sentry_sdk/integrations/asyncpg.py index eff4ca8f66..4e9d09659f 100644 --- a/sentry_sdk/integrations/asyncpg.py +++ b/sentry_sdk/integrations/asyncpg.py @@ -225,7 +225,7 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T": if sentry_sdk.traces.get_current_span() is None: return await f(*args, **kwargs) - with sentry_sdk.traces.start_span(name="connect", attributes=span_attributes): + with sentry_sdk.start_span(name="connect", attributes=span_attributes): return await f(*args, **kwargs) return _inner diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 37b649c67a..409c88e181 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -216,7 +216,7 @@ def sentry_handler( sentry_sdk.traces.continue_trace(headers) Scope.set_custom_sampling_context(sampling_context) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=function_name, parent_span=None, attributes={ diff --git a/sentry_sdk/integrations/boto3.py b/sentry_sdk/integrations/boto3.py index b8f424c281..e32c94e74d 100644 --- a/sentry_sdk/integrations/boto3.py +++ b/sentry_sdk/integrations/boto3.py @@ -86,7 +86,7 @@ def _sentry_request_created( breadcrumb[SPANDATA.HTTP_REQUEST_METHOD] = request.method if sentry_sdk.traces.get_current_span() is not None: - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=description, attributes={ "sentry.op": OP.HTTP_CLIENT, @@ -176,7 +176,7 @@ def _sentry_after_call( if not isinstance(body, StreamingBody): return - streaming_span = sentry_sdk.traces.start_span( + streaming_span = sentry_sdk.start_span( name=span.name, parent_span=span, attributes={ diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 3032ac04f0..d6ef028a81 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -282,7 +282,7 @@ def apply_async(*args: "Any", **kwargs: "Any") -> "Any": not task_started_from_beat and sentry_sdk.traces.get_current_span() is not None ): - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=task_name, attributes={ "sentry.op": OP.QUEUE_SUBMIT_CELERY, @@ -341,7 +341,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any": Scope.set_custom_sampling_context(custom_sampling_context) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=task_name, parent_span=None, # make this a segment attributes={ @@ -383,7 +383,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any": if sentry_sdk.traces.get_current_span() is None: return f(*args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=task.name, attributes={ "sentry.op": OP.QUEUE_PROCESS, @@ -519,7 +519,7 @@ def sentry_publish(self: "Producer", *args: "Any", **kwargs: "Any") -> "Any": if sentry_sdk.traces.get_current_span() is None: return original_publish(self, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=task_name, attributes={ "sentry.op": OP.QUEUE_PUBLISH, diff --git a/sentry_sdk/integrations/clickhouse_driver.py b/sentry_sdk/integrations/clickhouse_driver.py index 224f621d75..7584a31ed2 100644 --- a/sentry_sdk/integrations/clickhouse_driver.py +++ b/sentry_sdk/integrations/clickhouse_driver.py @@ -81,7 +81,7 @@ def _inner(*args: "P.args", **kwargs: "P.kwargs") -> "T": span = None if sentry_sdk.traces.get_current_span() is not None: - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=query, # type: ignore attributes={ "sentry.op": OP.DB, diff --git a/sentry_sdk/integrations/cohere.py b/sentry_sdk/integrations/cohere.py index 5aa25acf4a..06bba671cb 100644 --- a/sentry_sdk/integrations/cohere.py +++ b/sentry_sdk/integrations/cohere.py @@ -161,7 +161,7 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any": message = kwargs.get("message") - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="cohere.client.Chat", attributes={ "sentry.op": consts.OP.COHERE_CHAT_COMPLETIONS_CREATE, @@ -244,7 +244,7 @@ def new_embed(*args: "Any", **kwargs: "Any") -> "Any": if integration is None: return f(*args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="Cohere Embedding Creation", attributes={ "sentry.op": consts.OP.COHERE_EMBEDDINGS_CREATE, diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index 89ab2e8703..b595b4cfc1 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -354,7 +354,7 @@ def sentry_patched_drf_authenticate(self: "Request") -> "Any": ): return old_drf_authenticate(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="authenticate", attributes={ "sentry.op": OP.VIEW_AUTHENTICATE, @@ -833,7 +833,7 @@ def connect(self: "BaseDatabaseWrapper") -> None: if sentry_sdk.traces.get_current_span() is None: return real_connect(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="connect", attributes={ "sentry.op": OP.DB, @@ -852,7 +852,7 @@ def _commit(self: "BaseDatabaseWrapper") -> None: if sentry_sdk.traces.get_current_span() is None: return real_commit(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=SPANNAME.DB_COMMIT, attributes={ "sentry.op": OP.DB, @@ -871,7 +871,7 @@ def _rollback(self: "BaseDatabaseWrapper") -> None: if sentry_sdk.traces.get_current_span() is None: return real_rollback(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=SPANNAME.DB_ROLLBACK, attributes={ "sentry.op": OP.DB, diff --git a/sentry_sdk/integrations/django/asgi.py b/sentry_sdk/integrations/django/asgi.py index 6d124549ad..2904718052 100644 --- a/sentry_sdk/integrations/django/asgi.py +++ b/sentry_sdk/integrations/django/asgi.py @@ -186,7 +186,7 @@ async def sentry_wrapped_callback( if current_span is None: return await callback(request, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=request.resolver_match.view_name, attributes={ "sentry.op": OP.VIEW_RENDER, diff --git a/sentry_sdk/integrations/django/caching.py b/sentry_sdk/integrations/django/caching.py index dedb9b26a4..cf50ff2f01 100644 --- a/sentry_sdk/integrations/django/caching.py +++ b/sentry_sdk/integrations/django/caching.py @@ -61,7 +61,7 @@ def _instrument_call( if sentry_sdk.traces.get_current_span() is None: return original_method(*args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=description, attributes={ "sentry.op": op, diff --git a/sentry_sdk/integrations/django/middleware.py b/sentry_sdk/integrations/django/middleware.py index 6611337340..4fc8f831ac 100644 --- a/sentry_sdk/integrations/django/middleware.py +++ b/sentry_sdk/integrations/django/middleware.py @@ -79,7 +79,7 @@ def _check_middleware_span( if sentry_sdk.traces.get_current_span() is None: return None - middleware_span = sentry_sdk.traces.start_span( + middleware_span = sentry_sdk.start_span( name=description, attributes={ "sentry.op": OP.MIDDLEWARE_DJANGO, diff --git a/sentry_sdk/integrations/django/signals_handlers.py b/sentry_sdk/integrations/django/signals_handlers.py index 832eb60824..4c5b63853b 100644 --- a/sentry_sdk/integrations/django/signals_handlers.py +++ b/sentry_sdk/integrations/django/signals_handlers.py @@ -66,7 +66,7 @@ def wrapper(*args: "Any", **kwargs: "Any") -> "Any": if sentry_sdk.traces.get_current_span() is None: return receiver(*args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=signal_name, attributes={ "sentry.op": OP.EVENT_DJANGO, diff --git a/sentry_sdk/integrations/django/tasks.py b/sentry_sdk/integrations/django/tasks.py index be4989e620..f9a1b90af9 100644 --- a/sentry_sdk/integrations/django/tasks.py +++ b/sentry_sdk/integrations/django/tasks.py @@ -35,7 +35,7 @@ def _sentry_enqueue(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": if sentry_sdk.traces.get_current_span() is None: return old_task_enqueue(self, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=name, attributes={ "sentry.op": OP.QUEUE_SUBMIT_DJANGO, diff --git a/sentry_sdk/integrations/django/templates.py b/sentry_sdk/integrations/django/templates.py index d2eed17972..ee60e872e4 100644 --- a/sentry_sdk/integrations/django/templates.py +++ b/sentry_sdk/integrations/django/templates.py @@ -57,7 +57,7 @@ def rendered_content(self: "SimpleTemplateResponse") -> str: if sentry_sdk.traces.get_current_span() is None: return real_rendered_content.fget(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=_get_template_name_description(self.template_name), attributes={ "sentry.op": OP.TEMPLATE_RENDER, @@ -91,7 +91,7 @@ def render( if sentry_sdk.traces.get_current_span() is None: return real_render(request, template_name, context, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=_get_template_name_description(template_name), attributes={ "sentry.op": OP.TEMPLATE_RENDER, diff --git a/sentry_sdk/integrations/django/views.py b/sentry_sdk/integrations/django/views.py index d493a682dd..1c362776ff 100644 --- a/sentry_sdk/integrations/django/views.py +++ b/sentry_sdk/integrations/django/views.py @@ -24,7 +24,7 @@ def sentry_patched_render(self: "SimpleTemplateResponse") -> "Any": if sentry_sdk.traces.get_current_span() is None: return old_render(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="serialize response", attributes={ "sentry.op": OP.VIEW_RESPONSE_RENDER, @@ -74,7 +74,7 @@ def sentry_wrapped_callback(request: "Any", *args: "Any", **kwargs: "Any") -> "A if sentry_sdk.traces.get_current_span() is None: return callback(request, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=request.resolver_match.view_name, attributes={ "sentry.op": OP.VIEW_RENDER, diff --git a/sentry_sdk/integrations/dramatiq.py b/sentry_sdk/integrations/dramatiq.py index be20fd2871..9147d871d0 100644 --- a/sentry_sdk/integrations/dramatiq.py +++ b/sentry_sdk/integrations/dramatiq.py @@ -139,7 +139,7 @@ def before_process_message(self, broker: "Broker", message: "Message[R]") -> Non scope.set_transaction_name(message.actor_name, source=SegmentNameSource.TASK) sentry_sdk.traces.continue_trace(sentry_headers) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=message.actor_name, attributes={ "sentry.op": OP.QUEUE_TASK_DRAMATIQ, diff --git a/sentry_sdk/integrations/gcp.py b/sentry_sdk/integrations/gcp.py index bbddbdc53a..c6504116c8 100644 --- a/sentry_sdk/integrations/gcp.py +++ b/sentry_sdk/integrations/gcp.py @@ -140,7 +140,7 @@ def sentry_func( sentry_sdk.traces.continue_trace(headers) Scope.set_custom_sampling_context(sampling_context) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=function_name, parent_span=None, attributes={ diff --git a/sentry_sdk/integrations/google_genai/__init__.py b/sentry_sdk/integrations/google_genai/__init__.py index 9bd1161ff2..c97529b7f1 100644 --- a/sentry_sdk/integrations/google_genai/__init__.py +++ b/sentry_sdk/integrations/google_genai/__init__.py @@ -80,7 +80,7 @@ def new_generate_content_stream( _model, contents, model_name = prepare_generate_content_args(args, kwargs) - chat_span = sentry_sdk.traces.start_span( + chat_span = sentry_sdk.start_span( name=f"chat {model_name}", attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -144,7 +144,7 @@ async def new_async_generate_content_stream( _model, contents, model_name = prepare_generate_content_args(args, kwargs) - chat_span = sentry_sdk.traces.start_span( + chat_span = sentry_sdk.start_span( name=f"chat {model_name}", attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -204,7 +204,7 @@ def new_generate_content(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": model, contents, model_name = prepare_generate_content_args(args, kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"chat {model_name}", attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -247,7 +247,7 @@ async def new_async_generate_content( model, contents, model_name = prepare_generate_content_args(args, kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"chat {model_name}", attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -284,7 +284,7 @@ def new_embed_content(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": model_name, contents = prepare_embed_content_args(args, kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"embeddings {model_name}", attributes={ "sentry.op": OP.GEN_AI_EMBEDDINGS, @@ -322,7 +322,7 @@ async def new_async_embed_content( model_name, contents = prepare_embed_content_args(args, kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"embeddings {model_name}", attributes={ "sentry.op": OP.GEN_AI_EMBEDDINGS, diff --git a/sentry_sdk/integrations/google_genai/utils.py b/sentry_sdk/integrations/google_genai/utils.py index 3a9e160294..f33e129761 100644 --- a/sentry_sdk/integrations/google_genai/utils.py +++ b/sentry_sdk/integrations/google_genai/utils.py @@ -681,7 +681,7 @@ def _capture_tool_input( def _create_tool_span(tool_name: str, tool_doc: "Optional[str]") -> "Span": """Create a span for tool execution.""" - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"execute_tool {tool_name}", attributes={ "sentry.op": OP.GEN_AI_EXECUTE_TOOL, diff --git a/sentry_sdk/integrations/graphene.py b/sentry_sdk/integrations/graphene.py index b9fcacb819..c5b9d84fc0 100644 --- a/sentry_sdk/integrations/graphene.py +++ b/sentry_sdk/integrations/graphene.py @@ -165,7 +165,7 @@ def graphql_span( elif should_send_default_pii(): additional_attributes["graphql.document"] = source - _graphql_span = sentry_sdk.traces.start_span( + _graphql_span = sentry_sdk.start_span( name=operation_name, attributes={ "sentry.op": op, diff --git a/sentry_sdk/integrations/grpc/aio/client.py b/sentry_sdk/integrations/grpc/aio/client.py index 3cb8aaced9..b4d79dd985 100644 --- a/sentry_sdk/integrations/grpc/aio/client.py +++ b/sentry_sdk/integrations/grpc/aio/client.py @@ -55,7 +55,7 @@ async def intercept_unary_unary( ) return await continuation(client_call_details, request) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unary unary call to %s" % method.decode(), attributes={ "sentry.op": OP.GRPC_CLIENT, @@ -92,7 +92,7 @@ async def intercept_unary_stream( ) return await continuation(client_call_details, request) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unary stream call to %s" % method.decode(), attributes={ "sentry.op": OP.GRPC_CLIENT, diff --git a/sentry_sdk/integrations/grpc/aio/server.py b/sentry_sdk/integrations/grpc/aio/server.py index 89a8d7b889..069960f280 100644 --- a/sentry_sdk/integrations/grpc/aio/server.py +++ b/sentry_sdk/integrations/grpc/aio/server.py @@ -57,7 +57,7 @@ async def wrapped(request: "Any", context: "ServicerContext") -> "Any": dict(context.invocation_metadata()) ) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=name, attributes={ "sentry.op": OP.GRPC_SERVER, diff --git a/sentry_sdk/integrations/grpc/client.py b/sentry_sdk/integrations/grpc/client.py index cd5381b5d7..8ce529456c 100644 --- a/sentry_sdk/integrations/grpc/client.py +++ b/sentry_sdk/integrations/grpc/client.py @@ -35,7 +35,7 @@ def intercept_unary_unary( client_call_details ) return continuation(client_call_details, request) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unary unary call to %s" % method, attributes={ "sentry.op": OP.GRPC_CLIENT, @@ -66,7 +66,7 @@ def intercept_unary_stream( ) return continuation(client_call_details, request) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unary stream call to %s" % method, attributes={ "sentry.op": OP.GRPC_CLIENT, diff --git a/sentry_sdk/integrations/grpc/server.py b/sentry_sdk/integrations/grpc/server.py index a363652ad8..7bef1da1cd 100644 --- a/sentry_sdk/integrations/grpc/server.py +++ b/sentry_sdk/integrations/grpc/server.py @@ -48,7 +48,7 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message": sentry_sdk.traces.continue_trace(metadata) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=name, attributes={ "sentry.op": OP.GRPC_SERVER, diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index 7ce55d6207..16781ca1c1 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -64,7 +64,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response": if sentry_sdk.traces.get_current_span() is None: span_ctx = nullcontext() else: - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name="%s %s" % ( request.method, @@ -135,7 +135,7 @@ async def send( if sentry_sdk.traces.get_current_span() is None: span_ctx = nullcontext() else: - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name="%s %s" % ( request.method, diff --git a/sentry_sdk/integrations/httpx2.py b/sentry_sdk/integrations/httpx2.py index 58ef6169de..6f8625a33c 100644 --- a/sentry_sdk/integrations/httpx2.py +++ b/sentry_sdk/integrations/httpx2.py @@ -64,7 +64,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response": if sentry_sdk.traces.get_current_span() is None: span_ctx = nullcontext() else: - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name="%s %s" % ( request.method, @@ -135,7 +135,7 @@ async def send( if sentry_sdk.traces.get_current_span() is None: span_ctx = nullcontext() else: - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name="%s %s" % ( request.method, diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index ae3b3adce1..7693c830c8 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -93,7 +93,7 @@ def _sentry_enqueue( } return old_enqueue(self, item) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=span_name, attributes={ "sentry.op": OP.QUEUE_SUBMIT_HUEY, @@ -199,7 +199,7 @@ def _sentry_execute( sentry_headers = task.kwargs.pop("sentry_headers", None) headers = sentry_headers or {} sentry_sdk.traces.continue_trace(headers) - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name=task.name, attributes={ "sentry.op": OP.QUEUE_TASK_HUEY, diff --git a/sentry_sdk/integrations/huggingface_hub.py b/sentry_sdk/integrations/huggingface_hub.py index 1fb951c5dc..34ad01df5a 100644 --- a/sentry_sdk/integrations/huggingface_hub.py +++ b/sentry_sdk/integrations/huggingface_hub.py @@ -95,7 +95,7 @@ def new_huggingface_task(*args: "Any", **kwargs: "Any") -> "Any": model = hf_client.model or kwargs.get("model") or "" operation_name = op.split(".")[-1] - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"{operation_name} {model}", attributes={ "sentry.op": op, diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 73d0d55575..01b7377823 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -257,7 +257,7 @@ def _create_span( self.span_map.get(parent_id) ) if parent: - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( parent_span=parent.span if isinstance(parent, _AgentFrameworkChatGenerationContext) else parent, @@ -269,7 +269,7 @@ def _create_span( ) if span is None: - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=name, attributes={ "sentry.op": op, @@ -1123,7 +1123,7 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": record_inputs = True record_outputs = True - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"invoke_agent {run_name}" if run_name else "invoke_agent", attributes={ "sentry.op": OP.GEN_AI_INVOKE_AGENT, @@ -1179,7 +1179,7 @@ def new_stream(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": record_inputs = True record_outputs = True - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"invoke_agent {run_name}" if run_name else "invoke_agent", attributes={ "sentry.op": OP.GEN_AI_INVOKE_AGENT, diff --git a/sentry_sdk/integrations/langgraph.py b/sentry_sdk/integrations/langgraph.py index 6754505418..34bf8f7df3 100644 --- a/sentry_sdk/integrations/langgraph.py +++ b/sentry_sdk/integrations/langgraph.py @@ -143,7 +143,7 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": graph_name = _get_graph_name(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"invoke_agent {graph_name}".strip() if graph_name else "invoke_agent", attributes={ "sentry.op": OP.GEN_AI_INVOKE_AGENT, @@ -187,7 +187,7 @@ async def new_ainvoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": graph_name = _get_graph_name(self) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"invoke_agent {graph_name}".strip() if graph_name else "invoke_agent", attributes={ "sentry.op": OP.GEN_AI_INVOKE_AGENT, diff --git a/sentry_sdk/integrations/litellm.py b/sentry_sdk/integrations/litellm.py index 7ca8894aed..cb50da2ea7 100644 --- a/sentry_sdk/integrations/litellm.py +++ b/sentry_sdk/integrations/litellm.py @@ -95,7 +95,7 @@ def _input_callback(kwargs: "Dict[str, Any]") -> None: operation = "chat" # Start a new span/transaction - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"{operation} {model}", attributes={ "sentry.op": ( diff --git a/sentry_sdk/integrations/litestar.py b/sentry_sdk/integrations/litestar.py index 95df2c7e1d..156a489ec1 100644 --- a/sentry_sdk/integrations/litestar.py +++ b/sentry_sdk/integrations/litestar.py @@ -170,7 +170,7 @@ async def _create_span_call( middleware_name = self.__class__.__name__ if sentry_sdk.traces.get_current_span() is None: return await old_call(self, scope, receive, send) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=middleware_name, attributes={ "sentry.op": OP.MIDDLEWARE_LITESTAR, @@ -187,7 +187,7 @@ async def _sentry_receive( return await receive(*args, **kwargs) if sentry_sdk.traces.get_current_span() is None: return await receive(*args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=getattr(receive, "__qualname__", str(receive)), attributes={ "sentry.op": OP.MIDDLEWARE_LITESTAR_RECEIVE, @@ -207,7 +207,7 @@ async def _sentry_send(message: "Message") -> None: return await send(message) if sentry_sdk.traces.get_current_span() is None: return await send(message) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=getattr(send, "__qualname__", str(send)), attributes={ "sentry.op": OP.MIDDLEWARE_LITESTAR_SEND, diff --git a/sentry_sdk/integrations/mcp.py b/sentry_sdk/integrations/mcp.py index d8a4643a0e..af3c5272c8 100644 --- a/sentry_sdk/integrations/mcp.py +++ b/sentry_sdk/integrations/mcp.py @@ -268,7 +268,7 @@ async def _instrument_tool_call( request_id, session_id, mcp_transport = _get_request_context_data(ctx=ctx) # Start span and execute - with _active_http_scopes(ctx=ctx), sentry_sdk.traces.start_span( + with _active_http_scopes(ctx=ctx), sentry_sdk.start_span( name=f"tools/call {handler_name}", attributes={ "sentry.op": OP.MCP_SERVER, @@ -360,7 +360,7 @@ async def _instrument_prompt_get( request_id, session_id, mcp_transport = _get_request_context_data(ctx=ctx) # Start span and execute - with _active_http_scopes(ctx=ctx), sentry_sdk.traces.start_span( + with _active_http_scopes(ctx=ctx), sentry_sdk.start_span( name=f"prompts/get {handler_name}", attributes={ "sentry.op": OP.MCP_SERVER, @@ -463,7 +463,7 @@ async def _instrument_resource_read( request_id, session_id, mcp_transport = _get_request_context_data(ctx=ctx) # Start span and execute - with _active_http_scopes(ctx=ctx), sentry_sdk.traces.start_span( + with _active_http_scopes(ctx=ctx), sentry_sdk.start_span( name=f"resources/read {handler_name}", attributes={ "sentry.op": OP.MCP_SERVER, diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index 41a5a07be7..f84b6e3bc8 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -796,7 +796,7 @@ def _new_sync_chat_completion( # Same bool handling as in https://github.com/openai/openai-python/blob/acd0c54d8a68efeedde0e5b4e6c310eef1ce7867/src/openai/resources/completions.py#L585 is_streaming_response = kwargs.get("stream", False) or False - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"chat {model}", attributes={ "sentry.op": consts.OP.GEN_AI_CHAT, @@ -874,7 +874,7 @@ async def _new_async_chat_completion( # Same bool handling as in https://github.com/openai/openai-python/blob/acd0c54d8a68efeedde0e5b4e6c310eef1ce7867/src/openai/resources/completions.py#L585 is_streaming_response = kwargs.get("stream", False) or False - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"chat {model}", attributes={ "sentry.op": consts.OP.GEN_AI_CHAT, @@ -1300,7 +1300,7 @@ def _new_sync_embeddings_create(f: "Any", *args: "Any", **kwargs: "Any") -> "Any model = kwargs.get("model") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"embeddings {model}", attributes={ "sentry.op": consts.OP.GEN_AI_EMBEDDINGS, @@ -1337,7 +1337,7 @@ async def _new_async_embeddings_create( model = kwargs.get("model") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"embeddings {model}", attributes={ "sentry.op": consts.OP.GEN_AI_EMBEDDINGS, @@ -1404,7 +1404,7 @@ def _new_sync_responses_create( # Same bool handling as in https://github.com/openai/openai-python/blob/acd0c54d8a68efeedde0e5b4e6c310eef1ce7867/src/openai/resources/responses/responses.py#L940 is_streaming_response = kwargs.get("stream", False) or False - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"responses {model}", attributes={ "sentry.op": consts.OP.GEN_AI_RESPONSES, @@ -1472,7 +1472,7 @@ async def _new_async_responses_create( # Same bool handling as in https://github.com/openai/openai-python/blob/acd0c54d8a68efeedde0e5b4e6c310eef1ce7867/src/openai/resources/responses/responses.py#L940 is_streaming_response = kwargs.get("stream", False) or False - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"responses {model}", attributes={ "sentry.op": consts.OP.GEN_AI_RESPONSES, diff --git a/sentry_sdk/integrations/openai_agents/spans/agent_workflow.py b/sentry_sdk/integrations/openai_agents/spans/agent_workflow.py index 3748f82e2a..a73690d9c5 100644 --- a/sentry_sdk/integrations/openai_agents/spans/agent_workflow.py +++ b/sentry_sdk/integrations/openai_agents/spans/agent_workflow.py @@ -11,6 +11,6 @@ def agent_workflow_span( agent: "agents.Agent", ) -> "sentry_sdk.traces.Span": - return sentry_sdk.traces.start_span( + return sentry_sdk.start_span( name=f"{agent.name} workflow", attributes={"sentry.origin": SPAN_ORIGIN} ) diff --git a/sentry_sdk/integrations/openai_agents/spans/execute_tool.py b/sentry_sdk/integrations/openai_agents/spans/execute_tool.py index b90b089ebe..9cadea6fdb 100644 --- a/sentry_sdk/integrations/openai_agents/spans/execute_tool.py +++ b/sentry_sdk/integrations/openai_agents/spans/execute_tool.py @@ -18,7 +18,7 @@ def execute_tool_span( tool: "agents.FunctionTool", *args: "Any", **kwargs: "Any" ) -> "Span": - return sentry_sdk.traces.start_span( + return sentry_sdk.start_span( name=f"execute_tool {tool.name}", attributes={ "sentry.op": OP.GEN_AI_EXECUTE_TOOL, diff --git a/sentry_sdk/integrations/openai_agents/spans/handoff.py b/sentry_sdk/integrations/openai_agents/spans/handoff.py index cb7506da45..89efe2740e 100644 --- a/sentry_sdk/integrations/openai_agents/spans/handoff.py +++ b/sentry_sdk/integrations/openai_agents/spans/handoff.py @@ -16,7 +16,7 @@ def handoff_span( from_agent: "Optional[agents.Agent]", to_agent_name: str, ) -> None: - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"handoff from {from_agent.name} to {to_agent_name}", # type: ignore[union-attr] attributes={ "sentry.op": OP.GEN_AI_HANDOFF, diff --git a/sentry_sdk/integrations/openai_agents/spans/invoke_agent.py b/sentry_sdk/integrations/openai_agents/spans/invoke_agent.py index 1477dc8457..ff306e4138 100644 --- a/sentry_sdk/integrations/openai_agents/spans/invoke_agent.py +++ b/sentry_sdk/integrations/openai_agents/spans/invoke_agent.py @@ -24,7 +24,7 @@ def invoke_agent_span( ) -> "Span": client_options = sentry_sdk.get_client().options - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"invoke_agent {agent.name}", attributes={ "sentry.op": OP.GEN_AI_INVOKE_AGENT, diff --git a/sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py b/sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py index d239a9be2a..e40848654a 100644 --- a/sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py +++ b/sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py @@ -29,7 +29,7 @@ def execute_tool_span( agent: The agent executing the tool tool_definition: The definition of the tool, if available """ - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"execute_tool {tool_name}", attributes={ "sentry.op": OP.GEN_AI_EXECUTE_TOOL, diff --git a/sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py b/sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py index 336e67ce26..3631c3fbef 100644 --- a/sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py +++ b/sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py @@ -48,7 +48,7 @@ def invoke_agent_span( if agent and getattr(agent, "name", None): name = agent.name - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name=f"invoke_agent {name}", attributes={ "sentry.op": OP.GEN_AI_INVOKE_AGENT, diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index be65cf8be1..dd396fec32 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -169,7 +169,7 @@ def started(self, event: "CommandStartedEvent") -> None: if sentry_sdk.traces.get_current_span() is None: return - span = sentry_sdk.traces.start_span(name=query, attributes=data) + span = sentry_sdk.start_span(name=query, attributes=data) self._ongoing_operations[self._operation_key(event)] = span diff --git a/sentry_sdk/integrations/pyreqwest.py b/sentry_sdk/integrations/pyreqwest.py index 22f13527e0..9ce47d37ae 100644 --- a/sentry_sdk/integrations/pyreqwest.py +++ b/sentry_sdk/integrations/pyreqwest.py @@ -121,7 +121,7 @@ def _sentry_pyreqwest_span( yield None return - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"{request.method} {parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE}", attributes={ "sentry.op": OP.HTTP_CLIENT, diff --git a/sentry_sdk/integrations/ray.py b/sentry_sdk/integrations/ray.py index 080d0437ef..ad201a632f 100644 --- a/sentry_sdk/integrations/ray.py +++ b/sentry_sdk/integrations/ray.py @@ -92,7 +92,7 @@ def new_func( sentry_sdk.traces.continue_trace(_sentry_tracing or {}) function_name = qualname_from_function(user_f) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unknown Ray task" if function_name is None else function_name, attributes={ "sentry.op": OP.QUEUE_TASK_RAY, @@ -142,7 +142,7 @@ def _remote_method_with_header_propagation( return result - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unknown Ray task" if function_name is None else function_name, attributes={ "sentry.op": OP.QUEUE_SUBMIT_RAY, diff --git a/sentry_sdk/integrations/redis/_async_common.py b/sentry_sdk/integrations/redis/_async_common.py index 8e3fd26001..ce6a107b0d 100644 --- a/sentry_sdk/integrations/redis/_async_common.py +++ b/sentry_sdk/integrations/redis/_async_common.py @@ -55,7 +55,7 @@ async def _sentry_execute(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": if sentry_sdk.traces.get_current_span() is None: return await old_execute(self, *args, **kwargs) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="redis.pipeline.execute", attributes={ "sentry.origin": SPAN_ORIGIN, @@ -125,7 +125,7 @@ async def _sentry_execute_command( cache_span: "Optional[Span]" = None if cache_properties["is_cache_key"] and cache_properties["op"] is not None: - cache_span = sentry_sdk.traces.start_span( + cache_span = sentry_sdk.start_span( name=cache_properties["description"], attributes={ "sentry.op": cache_properties["op"], @@ -140,7 +140,7 @@ async def _sentry_execute_command( name, args ) - db_span = sentry_sdk.traces.start_span( + db_span = sentry_sdk.start_span( name=db_properties["description"], attributes={ "sentry.op": db_properties["op"], diff --git a/sentry_sdk/integrations/redis/_sync_common.py b/sentry_sdk/integrations/redis/_sync_common.py index fbe3841c71..8f42606f05 100644 --- a/sentry_sdk/integrations/redis/_sync_common.py +++ b/sentry_sdk/integrations/redis/_sync_common.py @@ -52,7 +52,7 @@ def sentry_patched_execute(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": if sentry_sdk.traces.get_current_span() is None: return old_execute(self, *args, **kwargs) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="redis.pipeline.execute", attributes={ "sentry.origin": SPAN_ORIGIN, @@ -126,7 +126,7 @@ def sentry_patched_execute_command( cache_span: "Optional[Span]" = None if cache_properties["is_cache_key"] and cache_properties["op"] is not None: - cache_span = sentry_sdk.traces.start_span( + cache_span = sentry_sdk.start_span( name=cache_properties["description"], attributes={ "sentry.op": cache_properties["op"], @@ -141,7 +141,7 @@ def sentry_patched_execute_command( name, args ) - db_span = sentry_sdk.traces.start_span( + db_span = sentry_sdk.start_span( name=db_properties["description"], attributes={ "sentry.op": db_properties["op"], diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index 4cf021d5ab..7e869d0e2c 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -83,7 +83,7 @@ def sentry_patched_perform_job( with capture_internal_exceptions(): func_name = job.func_name - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="unknown RQ task" if func_name is None else func_name, attributes={ "sentry.op": OP.QUEUE_TASK_RQ, diff --git a/sentry_sdk/integrations/rust_tracing.py b/sentry_sdk/integrations/rust_tracing.py index f0fef5d3c9..2018353943 100644 --- a/sentry_sdk/integrations/rust_tracing.py +++ b/sentry_sdk/integrations/rust_tracing.py @@ -207,7 +207,7 @@ def on_new_span(self, attrs: str, span_id: str) -> "Optional[Span]": if sentry_sdk.traces.get_current_span() is None: return None - sentry_span = sentry_sdk.traces.start_span( + sentry_span = sentry_sdk.start_span( name=sentry_span_name, attributes={ "sentry.op": "function", diff --git a/sentry_sdk/integrations/sanic.py b/sentry_sdk/integrations/sanic.py index e2ea3a230b..bd3968cb85 100644 --- a/sentry_sdk/integrations/sanic.py +++ b/sentry_sdk/integrations/sanic.py @@ -142,7 +142,7 @@ async def _context_enter(request: "Request") -> None: elif should_send_default_pii(): scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr) - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( # Unless the request results in a 404 error, the name and source # will get overwritten in _set_transaction name=request.path, diff --git a/sentry_sdk/integrations/socket.py b/sentry_sdk/integrations/socket.py index 022f7c06e2..4c54a32a14 100644 --- a/sentry_sdk/integrations/socket.py +++ b/sentry_sdk/integrations/socket.py @@ -58,7 +58,7 @@ def create_connection( if sentry_sdk.traces.get_current_span() is None: return real_create_connection(address, timeout, source_address) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=_get_span_description(address[0], address[1]), attributes={ "sentry.op": OP.SOCKET_CONNECTION, @@ -95,7 +95,7 @@ def getaddrinfo( if sentry_sdk.traces.get_current_span() is None: return real_getaddrinfo(host, port, family, type, proto, flags) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=_get_span_description(host, port), attributes={ "sentry.op": OP.SOCKET_DNS, diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index dd2e63033e..26dd9e22bc 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -182,7 +182,7 @@ def _start_middleware_span(op: str, name: str) -> "Any": if sentry_sdk.traces.get_current_span() is None: return nullcontext() - return sentry_sdk.traces.start_span( + return sentry_sdk.start_span( name=name, attributes={ "sentry.op": op, diff --git a/sentry_sdk/integrations/starlite.py b/sentry_sdk/integrations/starlite.py index 58a4f520ee..93cce64aa3 100644 --- a/sentry_sdk/integrations/starlite.py +++ b/sentry_sdk/integrations/starlite.py @@ -157,7 +157,7 @@ def _start_middleware_span(op: str, name: str) -> "Any": if sentry_sdk.traces.get_current_span() is None: return nullcontext() - return sentry_sdk.traces.start_span( + return sentry_sdk.start_span( name=name, attributes={ "sentry.op": op, diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index b3efef18c7..45643071ee 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -280,7 +280,7 @@ def putrequest( breadcrumb.update(url_attributes) if sentry_sdk.traces.get_current_span() is not None: - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="%s %s" % ( method, @@ -491,7 +491,7 @@ def sentry_patched_popen_init( if sentry_sdk.traces.get_current_span() is None: return old_popen_init(self, *a, **kw) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=description, attributes={ "sentry.op": OP.SUBPROCESS, @@ -527,7 +527,7 @@ def sentry_patched_popen_wait( ) -> "Any": if sentry_sdk.traces.get_current_span() is None: return old_popen_wait(self, *a, **kw) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=OP.SUBPROCESS_WAIT, attributes={ "sentry.op": OP.SUBPROCESS_WAIT, @@ -547,7 +547,7 @@ def sentry_patched_popen_communicate( ) -> "Any": if sentry_sdk.traces.get_current_span() is None: return old_popen_communicate(self, *a, **kw) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=OP.SUBPROCESS_COMMUNICATE, attributes={ "sentry.op": OP.SUBPROCESS_COMMUNICATE, diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index dbfa084b38..c97d347d1a 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -178,7 +178,7 @@ def on_operation(self) -> "Generator[None, None, None]": if operation_name: additional_attributes["graphql.operation.name"] = operation_name - graphql_span = sentry_sdk.traces.start_span( + graphql_span = sentry_sdk.start_span( name=description, attributes={ "sentry.origin": StrawberryIntegration.origin, @@ -205,7 +205,7 @@ def on_validate(self) -> "Generator[None, None, None]": yield return - validation_span = sentry_sdk.traces.start_span( + validation_span = sentry_sdk.start_span( name="validation", attributes={ "sentry.op": OP.GRAPHQL_VALIDATE, @@ -224,7 +224,7 @@ def on_parse(self) -> "Generator[None, None, None]": yield return - parsing_span = sentry_sdk.traces.start_span( + parsing_span = sentry_sdk.start_span( name="parsing", attributes={ "sentry.op": OP.GRAPHQL_PARSE, @@ -276,7 +276,7 @@ async def resolve( if sentry_sdk.traces.get_current_span() is None: return await self._resolve(_next, root, info, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"resolving {field_path}", attributes={ "sentry.origin": StrawberryIntegration.origin, @@ -303,7 +303,7 @@ def resolve( if sentry_sdk.traces.get_current_span() is None: return _next(root, info, *args, **kwargs) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"resolving {field_path}", attributes={ "sentry.origin": StrawberryIntegration.origin, diff --git a/sentry_sdk/integrations/tornado.py b/sentry_sdk/integrations/tornado.py index 7b87a13fc1..020b0d9cdf 100644 --- a/sentry_sdk/integrations/tornado.py +++ b/sentry_sdk/integrations/tornado.py @@ -107,7 +107,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None] elif should_send_default_pii(): scope.set_attribute(SPANDATA.USER_IP_ADDRESS, self.request.remote_ip) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=_DEFAULT_ROOT_SPAN_NAME, attributes={ "sentry.op": OP.HTTP_SERVER, diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index 0ceba9ee01..a2a9104f89 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -144,7 +144,7 @@ def __call__( if client_ip: scope.set_attribute(SPANDATA.USER_IP_ADDRESS, client_ip) - span_ctx = sentry_sdk.traces.start_span( + span_ctx = sentry_sdk.start_span( name=_DEFAULT_TRANSACTION_NAME, attributes={ "sentry.segment.name.source": SegmentNameSource.ROUTE, diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 5abd52501e..9ab3365dfc 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1767,7 +1767,7 @@ def ensure_integration_enabled( ```python @ensure_integration_enabled(MyIntegration, my_function) def patch_my_function(): - with sentry_sdk.traces.start_span(...): + 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 f0fcce6c5a..5772426c36 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -740,7 +740,7 @@ async def handler(request): items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", attributes={ "sentry.op": "greeting.sniff", @@ -781,7 +781,7 @@ async def handler(request): raw_server = await aiohttp_raw_server(handler) with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", ): client = await aiohttp_client(raw_server) @@ -820,7 +820,7 @@ async def handler(request): "Signature=sixtyseven" ) - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): client = await aiohttp_client(raw_server) resp = await client.get( "/", @@ -862,7 +862,7 @@ async def handler(request): "&X-Amz-Signature=sixtyseven" ) - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): client = await aiohttp_client(raw_server) resp = await client.get(path, headers={"baggage": "vendor=value"}) @@ -2013,7 +2013,7 @@ async def test_user_ip_address_on_all_spans( ) async def hello(request): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass return web.Response(text="hello") diff --git a/tests/integrations/aiomysql/test_aiomysql.py b/tests/integrations/aiomysql/test_aiomysql.py index 2e04ba908f..be044da501 100644 --- a/tests/integrations/aiomysql/test_aiomysql.py +++ b/tests/integrations/aiomysql/test_aiomysql.py @@ -699,7 +699,7 @@ async def test_query_source_disabled(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -746,7 +746,7 @@ async def test_query_source_enabled(sentry_init, capture_items, enable_db_query_ items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -789,7 +789,7 @@ async def test_query_source(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -852,7 +852,7 @@ def fake_record_sql_queries_streaming(*args, **kwargs): span._end_timestamp = datetime.datetime(2024, 1, 1, microsecond=99999) yield span - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -906,7 +906,7 @@ def fake_record_sql_queries_streaming(*args, **kwargs): ) yield span - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -963,7 +963,7 @@ async def test_span_origin(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -996,7 +996,7 @@ async def test_multiline_query_description_normalized(sentry_init, capture_items items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: @@ -1035,7 +1035,7 @@ async def test_db_data_on_spans(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn = await aiomysql.connect(**_connect_args()) async with conn.cursor() as cur: diff --git a/tests/integrations/anthropic/test_anthropic.py b/tests/integrations/anthropic/test_anthropic.py index f7f30f9783..38961ae155 100644 --- a/tests/integrations/anthropic/test_anthropic.py +++ b/tests/integrations/anthropic/test_anthropic.py @@ -3576,7 +3576,7 @@ def test_set_output_data_with_input_json_delta(sentry_init): send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test") + span = sentry_sdk.start_span(name="test") integration = AnthropicIntegration() json_deltas = ["{'test': 'data',", "'more': 'json'}"] _set_output_data( diff --git a/tests/integrations/arq/test_arq.py b/tests/integrations/arq/test_arq.py index fb219d330d..c6da088b47 100644 --- a/tests/integrations/arq/test_arq.py +++ b/tests/integrations/arq/test_arq.py @@ -406,7 +406,7 @@ async def dummy_job(_): pool, _ = init_fixture_method(**{source: [dummy_job]}) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: await pool.enqueue_job("dummy_job") sentry_sdk.flush() @@ -465,7 +465,7 @@ async def dummy_job(_): pool, _ = init_fixture_method(**{source: [dummy_job]}) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await pool.enqueue_job("dummy_job") sentry_sdk.flush() diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index 3f08f5c289..4c4b09de24 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -1104,7 +1104,7 @@ async def app(scope, receive, send): await send({"type": "lifespan.shutdown.complete"}) return - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass await send( diff --git a/tests/integrations/asyncio/test_asyncio.py b/tests/integrations/asyncio/test_asyncio.py index 8bd298c749..f085fede6a 100644 --- a/tests/integrations/asyncio/test_asyncio.py +++ b/tests/integrations/asyncio/test_asyncio.py @@ -77,7 +77,7 @@ async def test_create_task( items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="not so important", attributes={"sentry.op": "root"} ): foo_task = asyncio.create_task(foo()) @@ -128,7 +128,7 @@ async def test_gather( items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="not so important", attributes={"sentry.op": "root"} ): await asyncio.gather(foo(), bar(), return_exceptions=True) @@ -168,8 +168,8 @@ async def test_exception( events = capture_events() - with sentry_sdk.traces.start_span(name="test_exception", parent_span=None): - with sentry_sdk.traces.start_span(name="not so important"): + with sentry_sdk.start_span(name="test_exception", parent_span=None): + with sentry_sdk.start_span(name="not so important"): tasks = [asyncio.create_task(boom()), asyncio.create_task(bar())] await asyncio.wait(tasks, return_when=asyncio.FIRST_EXCEPTION) @@ -386,7 +386,7 @@ async def test_span_origin( items = capture_items("span") - with sentry_sdk.traces.start_span(name="something"): + with sentry_sdk.start_span(name="something"): tasks = [ asyncio.create_task(foo()), ] @@ -421,7 +421,7 @@ async def test_task_spans_false( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_no_spans"): + with sentry_sdk.start_span(name="test_no_spans"): tasks = [asyncio.create_task(foo()), asyncio.create_task(bar())] await asyncio.wait(tasks, return_when=asyncio.FIRST_EXCEPTION) @@ -458,7 +458,7 @@ async def test_enable_asyncio_integration_with_task_spans_false( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await asyncio.create_task(foo()) sentry_sdk.flush() @@ -484,7 +484,7 @@ async def test_delayed_enable_integration( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await asyncio.create_task(foo()) sentry_sdk.flush() @@ -500,7 +500,7 @@ async def test_delayed_enable_integration( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await asyncio.create_task(foo()) sentry_sdk.flush() @@ -576,7 +576,7 @@ async def test_delayed_enable_integration_after_disabling( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await asyncio.create_task(foo()) sentry_sdk.flush() @@ -592,7 +592,7 @@ async def test_delayed_enable_integration_after_disabling( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await asyncio.create_task(foo()) sentry_sdk.flush() @@ -628,7 +628,7 @@ async def internal_task(): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_streamed_span"): + with sentry_sdk.start_span(name="test_streamed_span"): user_task_obj = asyncio.create_task(user_task()) with mark_sentry_task_internal(): diff --git a/tests/integrations/asyncpg/test_asyncpg.py b/tests/integrations/asyncpg/test_asyncpg.py index ca23a7f4bc..83c49c66ac 100644 --- a/tests/integrations/asyncpg/test_asyncpg.py +++ b/tests/integrations/asyncpg/test_asyncpg.py @@ -523,7 +523,7 @@ async def test_query_source_disabled( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute( @@ -571,7 +571,7 @@ async def test_query_source_enabled( sentry_init(**sentry_options) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute( @@ -607,7 +607,7 @@ async def test_query_source(sentry_init, capture_items): ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute( @@ -645,7 +645,7 @@ async def test_query_source_with_module_in_search_path( from asyncpg_helpers.helpers import execute_query_in_connection items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await execute_query_in_connection( @@ -699,7 +699,7 @@ async def test_no_query_source_if_duration_too_short( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute( @@ -740,7 +740,7 @@ async def test_query_source_if_duration_over_threshold(sentry_init, capture_item items = capture_items() - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) @contextmanager @@ -786,7 +786,7 @@ async def test_span_origin(sentry_init, capture_items): ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute("SELECT 1") @@ -825,7 +825,7 @@ async def test_multiline_query_description_normalized( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute( """ @@ -886,7 +886,7 @@ async def test_query_source_execute( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.execute( "INSERT INTO users(name, password, dob) VALUES($1, $2, $3)", @@ -925,7 +925,7 @@ async def test_query_source_executemany( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.executemany( "INSERT INTO users(name, password, dob) VALUES($1, $2, $3)", @@ -961,7 +961,7 @@ async def test_query_source_prepare( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.prepare("SELECT * FROM users WHERE name = $1") await conn.close() @@ -1009,7 +1009,7 @@ async def test_cursor_iteration_creates_db_cursor_iter_spans( items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.executemany( @@ -1051,7 +1051,7 @@ async def test_cursor_fetch_methods_create_spans( items = capture_items() - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): conn: Connection = await connect(PG_CONNECTION_URI) await conn.executemany( diff --git a/tests/integrations/boto3/test_aws_http_connection.py b/tests/integrations/boto3/test_aws_http_connection.py index d66bf33660..4aacf2d2d6 100644 --- a/tests/integrations/boto3/test_aws_http_connection.py +++ b/tests/integrations/boto3/test_aws_http_connection.py @@ -56,7 +56,7 @@ def test_aws_http_connection_adds_missing_unsigned_propagation_headers( integrations=[StdlibIntegration()], ) server, requests = local_http_server - with sentry_sdk.traces.start_span(name="test"): # type: ignore[attr-defined] + with sentry_sdk.start_span(name="test"): # type: ignore[attr-defined] _request(server, []) headers: HTTPMessage = requests[0] @@ -83,7 +83,7 @@ def test_aws_http_connection_appends_baggage_but_preserves_sentry_trace( integrations=[StdlibIntegration()], ) server, requests = local_http_server - with sentry_sdk.traces.start_span(name="test"): # type: ignore[attr-defined] + with sentry_sdk.start_span(name="test"): # type: ignore[attr-defined] _request( server, [ @@ -124,7 +124,7 @@ def test_aws_http_connection_preserves_signed_propagation_headers( "SignedHeaders=baggage;host;sentry-trace, " "Signature=sixtyseven" ) - with sentry_sdk.traces.start_span(name="test"): # type: ignore[attr-defined] + with sentry_sdk.start_span(name="test"): # type: ignore[attr-defined] _request( server, [ @@ -170,7 +170,7 @@ def test_aws_http_connection_preserves_query_signed_baggage( "&X-Amz-SignedHeaders=baggage%3Bhost" "&X-Amz-Signature=sixtyseven" ) - with sentry_sdk.traces.start_span(name="test"): # type: ignore[attr-defined] + with sentry_sdk.start_span(name="test"): # type: ignore[attr-defined] _request( server, [("baggage", "vendor=value")], diff --git a/tests/integrations/boto3/test_s3.py b/tests/integrations/boto3/test_s3.py index e414e5a481..3527049d25 100644 --- a/tests/integrations/boto3/test_s3.py +++ b/tests/integrations/boto3/test_s3.py @@ -33,7 +33,7 @@ def test_basic( bucket = s3.Bucket("bucket") items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent") as span, MockResponse( + with sentry_sdk.start_span(name="custom parent") as span, MockResponse( s3.meta.client, 200, {}, read_fixture("s3_list.xml") ): objects = [obj for obj in bucket.objects.all()] @@ -68,7 +68,7 @@ def test_streaming( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent") as span, MockResponse( + with sentry_sdk.start_span(name="custom parent") as span, MockResponse( s3.meta.client, 200, {}, b"hello" ): body = obj.get()["Body"] @@ -131,7 +131,7 @@ def test_streaming_close( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent") as span, MockResponse( + with sentry_sdk.start_span(name="custom parent") as span, MockResponse( s3.meta.client, 200, {}, b"hello" ): body = obj.get()["Body"] @@ -169,7 +169,7 @@ def test_omit_url_data_if_parsing_fails( "sentry_sdk.integrations.boto3.parse_url", side_effect=ValueError, ): - with sentry_sdk.traces.start_span(name="custom parent") as span, MockResponse( + with sentry_sdk.start_span(name="custom parent") as span, MockResponse( s3.meta.client, 200, {}, read_fixture("s3_list.xml") ): objects = [obj for obj in bucket.objects.all()] @@ -216,7 +216,7 @@ def test_span_origin( bucket = s3.Bucket("bucket") items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"), MockResponse( + with sentry_sdk.start_span(name="custom parent"), MockResponse( s3.meta.client, 200, {}, read_fixture("s3_list.xml") ): _ = [obj for obj in bucket.objects.all()] @@ -241,7 +241,7 @@ def test_breadcrumb(sentry_init, capture_events, send_default_pii): events = capture_events() - with sentry_sdk.traces.start_span(name="custom parent"), MockResponse( + with sentry_sdk.start_span(name="custom parent"), MockResponse( s3.meta.client, 200, {}, read_fixture("s3_list.xml") ): _ = [obj for obj in bucket.objects.all()] @@ -366,7 +366,7 @@ def test_url_query_data_collection( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"), MockResponse( + with sentry_sdk.start_span(name="custom parent"), MockResponse( client, 200, {}, read_fixture("s3_list.xml") ): client.list_objects_v2(Bucket="bucket", Prefix="foo", ContinuationToken="abc") @@ -406,7 +406,7 @@ def test_url_query_data_collection_breadcrumb( events = capture_events() - with sentry_sdk.traces.start_span(name="custom parent"), MockResponse( + with sentry_sdk.start_span(name="custom parent"), MockResponse( client, 200, {}, read_fixture("s3_list.xml") ): client.list_objects_v2(Bucket="bucket", Prefix="foo", ContinuationToken="abc") diff --git a/tests/integrations/boto3/test_trace_propagation.py b/tests/integrations/boto3/test_trace_propagation.py index 7dc9ce4965..b9485ebf53 100644 --- a/tests/integrations/boto3/test_trace_propagation.py +++ b/tests/integrations/boto3/test_trace_propagation.py @@ -75,7 +75,7 @@ def capture_headers_after_instrumentation(request, **kwargs): client.meta.events.register_last( "before-sign", capture_headers_after_instrumentation ) - with sentry_sdk.traces.start_span( # type: ignore[attr-defined] + with sentry_sdk.start_span( # type: ignore[attr-defined] name="incoming" ): response = client.head_object( @@ -143,7 +143,7 @@ def _inject_signed_baggage(request, **kwargs): # inject `baggage` before SigV4; stdlib-only path cannot change signed fields. client.meta.events.register("before-sign", _inject_signed_baggage) - with sentry_sdk.traces.start_span( # type: ignore[attr-defined] + with sentry_sdk.start_span( # type: ignore[attr-defined] name="incoming" ): response = client.head_object( diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index 3ac3fe90e7..2ef2aa36fe 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -137,7 +137,7 @@ def dummy_task(x, y): items = capture_items("event", "span") - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: celery_invocation(dummy_task, 1, 2) _, expected_context = celery_invocation(dummy_task, 1, 0) @@ -333,7 +333,7 @@ def dummy_task(x, y): items = capture_items("event", "span") - with sentry_sdk.traces.start_span(name="submission") as span: + with sentry_sdk.start_span(name="submission") as span: celery_invocation(dummy_task, 1, 0 if task_fails else 1) sentry_sdk.flush() @@ -409,7 +409,7 @@ def test_simple_no_propagation(capture_events, init_celery): def dummy_task(): 1 / 0 - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: dummy_task.delay() (event,) = events @@ -553,7 +553,7 @@ def __call__(self, *args, **kwargs): def dummy_task(x, y): return x / y - with sentry_sdk.traces.start_span(name="task"): + with sentry_sdk.start_span(name="task"): celery_invocation(dummy_task, 1, 0) assert not events @@ -596,7 +596,7 @@ def dummy_task(self, x, y): # patch random.randrange to return a predictable sample_rand value with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: result = dummy_task.apply_async( args=(1, 0), headers={"baggage": "custom=value"}, @@ -632,7 +632,7 @@ def dummy_task(self, message): trace_id = sentry_sdk.traces.get_current_span().trace_id return trace_id - with sentry_sdk.traces.start_span(name="parent") as span: + with sentry_sdk.start_span(name="parent") as span: parent_trace_id = span.trace_id # should propagate trace @@ -815,7 +815,7 @@ def task(): ... items = capture_items("span") - with sentry_sdk.traces.start_span(name="producer test"): + with sentry_sdk.start_span(name="producer test"): task.apply_async() sentry_sdk.flush() @@ -885,7 +885,7 @@ def task(): ... items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): task.apply_async() sentry_sdk.flush() @@ -915,7 +915,7 @@ def test_send_task_wrapped( celery = Celery(__name__, broker="redis://example.com") # noqa: E231 items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent") as outer_span: + with sentry_sdk.start_span(name="custom parent") as outer_span: celery.send_task("very_creative_task_name", args=(1, 2), kwargs={"foo": "bar"}) sentry_sdk.flush() @@ -973,7 +973,7 @@ def custom_headers_task(self): "tenant_id": "tenant-42", } - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): result = custom_headers_task.apply_async(headers=custom_headers) received_headers = result.get() diff --git a/tests/integrations/celery/test_update_celery_task_headers.py b/tests/integrations/celery/test_update_celery_task_headers.py index 0b2dcc6937..7660b00c58 100644 --- a/tests/integrations/celery/test_update_celery_task_headers.py +++ b/tests/integrations/celery/test_update_celery_task_headers.py @@ -74,8 +74,8 @@ def test_span_with_transaction(sentry_init): headers = {} monitor_beat_tasks = False - with sentry_sdk.traces.start_span(name="test_segment") as segment: - with sentry_sdk.traces.start_span(name="test_span") as span: + with sentry_sdk.start_span(name="test_segment") as segment: + with sentry_sdk.start_span(name="test_span") as span: outgoing_headers = _update_celery_task_headers( headers, span, monitor_beat_tasks ) @@ -96,8 +96,8 @@ def test_span_with_transaction_custom_headers(sentry_init): "sentry-trace": SENTRY_TRACE_VALUE, } - with sentry_sdk.traces.start_span(name="test_segment") as segment: - with sentry_sdk.traces.start_span(name="test_span") as span: + with sentry_sdk.start_span(name="test_segment") as segment: + with sentry_sdk.start_span(name="test_span") as span: outgoing_headers = _update_celery_task_headers(headers, span, False) assert outgoing_headers["sentry-trace"] == span._to_traceparent() diff --git a/tests/integrations/chalice/test_chalice.py b/tests/integrations/chalice/test_chalice.py index c1664b302c..0ffe31a2b8 100644 --- a/tests/integrations/chalice/test_chalice.py +++ b/tests/integrations/chalice/test_chalice.py @@ -184,7 +184,7 @@ def test_existing_span(sentry_init, capture_items, app): client = RequestHandler(app) items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="lambda_segment", parent_span=None, attributes={ @@ -217,7 +217,7 @@ def test_existing_span_error( client = RequestHandler(app) items = capture_items("event", "span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="lambda_segment", parent_span=None, attributes={"sentry.origin": "auto.function.aws_lambda"}, diff --git a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py index 15a84e6580..3dca0d8d8e 100644 --- a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py +++ b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py @@ -639,7 +639,7 @@ def test_clickhouse_client_with_data_collection(sentry_init, capture_items) -> N ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = Client("localhost") client.execute("DROP TABLE IF EXISTS test") client.execute("CREATE TABLE test (x Int32) ENGINE = Memory") @@ -678,7 +678,7 @@ def test_clickhouse_client_spans( trace_id = None span_id = None - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: trace_id = span.trace_id span_id = span.span_id @@ -815,7 +815,7 @@ def test_clickhouse_client_spans_with_pii( trace_id = None span_id = None - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: trace_id = span.trace_id span_id = span.span_id @@ -1142,7 +1142,7 @@ def test_clickhouse_dbapi_spans( trace_id = None span_id = None - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: trace_id = span.trace_id span_id = span.span_id @@ -1276,7 +1276,7 @@ def test_clickhouse_dbapi_spans_with_pii( trace_id = None span_id = None - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: trace_id = span.trace_id span_id = span.span_id @@ -1401,7 +1401,7 @@ def test_span_origin( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = connect("clickhouse://localhost") cursor = conn.cursor() cursor.execute("SELECT 1") diff --git a/tests/integrations/django/test_cache_module.py b/tests/integrations/django/test_cache_module.py index c7044e36d4..dd6c24ee29 100644 --- a/tests/integrations/django/test_cache_module.py +++ b/tests/integrations/django/test_cache_module.py @@ -587,7 +587,7 @@ def test_cache_spans_get_custom_default( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): cache.set(f"S{id}", "Sensitive1") cache.set(f"S{id + 1}", "") @@ -653,7 +653,7 @@ def test_cache_spans_get_many( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): 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}"]) @@ -714,7 +714,7 @@ def test_cache_spans_set_many( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): 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 aca27c16fc..b20a1600f1 100644 --- a/tests/integrations/django/test_db_query_data.py +++ b/tests/integrations/django/test_db_query_data.py @@ -576,7 +576,7 @@ def test_db_span_origin_executemany( pytest.skip("postgres tests disabled") items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction cursor = connection.cursor() diff --git a/tests/integrations/django/test_db_transactions.py b/tests/integrations/django/test_db_transactions.py index f3a5041d56..743a329325 100644 --- a/tests/integrations/django/test_db_transactions.py +++ b/tests/integrations/django/test_db_transactions.py @@ -47,7 +47,7 @@ def test_db_transaction_spans_disabled_no_autocommit( client.get(reverse("postgres_insert_orm_no_autocommit_rollback")) client.get(reverse("postgres_insert_orm_no_autocommit")) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction cursor = connection.cursor() @@ -87,7 +87,7 @@ def test_db_transaction_spans_disabled_no_autocommit( transaction.rollback() transaction.set_autocommit(True) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction cursor = connection.cursor() @@ -179,7 +179,7 @@ def test_db_transaction_spans_disabled_atomic( client.get(reverse("postgres_insert_orm_atomic_rollback")) client.get(reverse("postgres_insert_orm_atomic")) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction with transaction.atomic(): @@ -217,7 +217,7 @@ def test_db_transaction_spans_disabled_atomic( cursor.executemany(query, query_list) transaction.set_rollback(True) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction with transaction.atomic(): @@ -350,7 +350,7 @@ def test_db_no_autocommit_executemany( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction cursor = connection.cursor() @@ -500,7 +500,7 @@ def test_db_no_autocommit_rollback_executemany( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction cursor = connection.cursor() @@ -650,7 +650,7 @@ def test_db_atomic_executemany( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction with transaction.atomic(): @@ -798,7 +798,7 @@ def test_db_atomic_rollback_executemany( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction with transaction.atomic(): @@ -947,7 +947,7 @@ def test_db_atomic_executemany_exception( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from django.db import connection, transaction try: diff --git a/tests/integrations/django/test_tasks.py b/tests/integrations/django/test_tasks.py index 1e58de3164..f080d7872c 100644 --- a/tests/integrations/django/test_tasks.py +++ b/tests/integrations/django/test_tasks.py @@ -66,7 +66,7 @@ def test_task_span_is_created( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): simple_task.enqueue() sentry_sdk.flush() @@ -118,7 +118,7 @@ def test_task_enqueue_with_kwargs( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): result = greet.enqueue(name="World", greeting="Hi") assert result.return_value == "Hi, World!" @@ -154,7 +154,7 @@ def test_task_error_reporting( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): result = failing_task.enqueue() with pytest.raises(ValueError, match="Task failed"): @@ -192,7 +192,7 @@ def test_multiple_task_enqueues_create_multiple_spans( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): task_one.enqueue() task_two.enqueue() task_one.enqueue() diff --git a/tests/integrations/dramatiq/test_dramatiq.py b/tests/integrations/dramatiq/test_dramatiq.py index 8f2ab13497..1f24d85a0e 100644 --- a/tests/integrations/dramatiq/test_dramatiq.py +++ b/tests/integrations/dramatiq/test_dramatiq.py @@ -168,7 +168,7 @@ def dummy_actor(x, y): def test_dramatiq_propagate_trace(broker, worker, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="outer") as outer_span: + with sentry_sdk.start_span(name="outer") as outer_span: @dramatiq.actor(max_retries=0) def propagated_trace_task(): diff --git a/tests/integrations/fastapi/test_fastapi.py b/tests/integrations/fastapi/test_fastapi.py index 5d18bf5a55..583f1d47ec 100644 --- a/tests/integrations/fastapi/test_fastapi.py +++ b/tests/integrations/fastapi/test_fastapi.py @@ -928,8 +928,8 @@ async def test_feature_flags(sentry_init, capture_events): async def _error(): add_feature_flag("hello", False) - with sentry_sdk.traces.start_span(name="test-span"): - with sentry_sdk.traces.start_span(name="test-span-2"): + with sentry_sdk.start_span(name="test-span"): + with sentry_sdk.start_span(name="test-span-2"): raise ValueError("something is wrong!") try: diff --git a/tests/integrations/fastmcp/test_fastmcp.py b/tests/integrations/fastmcp/test_fastmcp.py index de4745092a..08f6000926 100644 --- a/tests/integrations/fastmcp/test_fastmcp.py +++ b/tests/integrations/fastmcp/test_fastmcp.py @@ -550,7 +550,7 @@ def code_help_prompt(language: str): return [message] items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await stdio( mcp._mcp_server, method="prompts/get", diff --git a/tests/integrations/grpc/test_grpc.py b/tests/integrations/grpc/test_grpc.py index 18f3d859b6..5dc356f674 100644 --- a/tests/integrations/grpc/test_grpc.py +++ b/tests/integrations/grpc/test_grpc.py @@ -138,7 +138,7 @@ def test_grpc_server_continues_transaction( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent") as segment_span: + with sentry_sdk.start_span(name="custom parent") as segment_span: metadata = ( ( "baggage", @@ -189,7 +189,7 @@ def test_grpc_client_starts_span( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): stub.TestServe(gRPCTestMessage(text="test")) _tear_down(server=server) @@ -241,7 +241,7 @@ def test_grpc_client_unary_stream_starts_span( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): [el for el in stub.TestUnaryStream(gRPCTestMessage(text="test"))] _tear_down(server=server) @@ -304,7 +304,7 @@ def test_grpc_client_other_interceptor( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): stub.TestServe(gRPCTestMessage(text="test")) _tear_down(server=server) @@ -359,7 +359,7 @@ def test_prevent_dual_client_interceptor( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): stub.TestServe(gRPCTestMessage(text="test")) _tear_down(server=server) @@ -400,7 +400,7 @@ def test_grpc_client_and_servers_interceptors_integration( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): stub.TestServe(gRPCTestMessage(text="test")) _tear_down(server=server) @@ -469,7 +469,7 @@ def test_span_origin( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): stub.TestServe(gRPCTestMessage(text="test")) _tear_down(server=server) @@ -494,7 +494,7 @@ class TestService(gRPCTestServiceServicer): @staticmethod def TestServe(request, context): # noqa: N802 - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="test", attributes={ "sentry.op": "test", diff --git a/tests/integrations/grpc/test_grpc_aio.py b/tests/integrations/grpc/test_grpc_aio.py index 104bfbd096..63911c7c80 100644 --- a/tests/integrations/grpc/test_grpc_aio.py +++ b/tests/integrations/grpc/test_grpc_aio.py @@ -127,7 +127,7 @@ async def test_grpc_server_continues_transaction( stub = gRPCTestServiceStub(channel) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent") as segment_span: + with sentry_sdk.start_span(name="custom parent") as segment_span: metadata = ( ( "baggage", @@ -213,7 +213,7 @@ async def test_grpc_client_starts_span( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: await stub.TestServe(gRPCTestMessage(text="test")) sentry_sdk.flush() @@ -258,7 +258,7 @@ async def test_grpc_client_unary_stream_starts_span( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = stub.TestUnaryStream(gRPCTestMessage(text="test")) [_ async for _ in response] @@ -332,7 +332,7 @@ async def test_span_origin( stub = gRPCTestServiceStub(channel) items = capture_items_forksafe("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await stub.TestServe(gRPCTestMessage(text="test")) sentry_sdk.flush() @@ -359,7 +359,7 @@ def __init__(self): @classmethod async def TestServe(cls, request, context): # noqa: N802 - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="test", attributes={ "sentry.op": "test", diff --git a/tests/integrations/httpx/test_httpx.py b/tests/integrations/httpx/test_httpx.py index 02b15865ec..0cbfe667b4 100644 --- a/tests/integrations/httpx/test_httpx.py +++ b/tests/integrations/httpx/test_httpx.py @@ -37,7 +37,7 @@ def before_breadcrumb(crumb, hint): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = httpx.Client().get(url) @@ -93,7 +93,7 @@ def before_breadcrumb(crumb, hint): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = await httpx.AsyncClient().get(url) @@ -219,7 +219,7 @@ def test_crumb_capture_client_error_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = httpx.Client().get(url) @@ -281,7 +281,7 @@ async def test_crumb_capture_client_error_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = await httpx.AsyncClient().get(url) @@ -484,7 +484,7 @@ def test_outgoing_trace_headers_sync(sentry_init, capture_items, httpx_mock): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = httpx.Client().get(url) sentry_sdk.flush() @@ -513,7 +513,7 @@ async def test_outgoing_trace_headers_async(sentry_init, capture_items, httpx_mo items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -547,7 +547,7 @@ def test_outgoing_trace_headers_append_to_baggage_sync( items = capture_items("span") with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = httpx.Client().get(url, headers={"baGGage": "custom=data"}) sentry_sdk.flush() @@ -580,7 +580,7 @@ async def test_outgoing_trace_headers_append_to_baggage_async( items = capture_items("span") with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = await httpx.AsyncClient().get( url, headers={"baGGage": "custom=data"} ) @@ -686,7 +686,7 @@ def test_request_source_disabled_sync(sentry_init, capture_items, httpx_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -714,7 +714,7 @@ async def test_request_source_disabled_async(sentry_init, capture_items, httpx_m url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -750,7 +750,7 @@ def test_request_source_enabled_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -787,7 +787,7 @@ async def test_request_source_enabled_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -814,7 +814,7 @@ def test_request_source_sync(sentry_init, capture_items, httpx_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -857,7 +857,7 @@ async def test_request_source_async(sentry_init, capture_items, httpx_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -906,7 +906,7 @@ def test_request_source_with_module_in_search_path_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): from httpx_helpers.helpers import get_request_with_client get_request_with_client(httpx.Client(), url) @@ -951,7 +951,7 @@ async def test_request_source_with_module_in_search_path_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): from httpx_helpers.helpers import async_get_request_with_client await async_get_request_with_client(httpx.AsyncClient(), url) @@ -996,7 +996,7 @@ def test_no_request_source_if_duration_too_short_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1027,7 +1027,7 @@ async def test_no_request_source_if_duration_too_short_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1057,7 +1057,7 @@ def test_request_source_if_duration_over_threshold_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1106,7 +1106,7 @@ async def test_request_source_if_duration_over_threshold_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1149,7 +1149,7 @@ def test_span_origin_sync(sentry_init, capture_items, httpx_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1172,7 +1172,7 @@ async def test_span_origin_async(sentry_init, capture_items, httpx_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1198,7 +1198,7 @@ def test_http_url_attributes_sync( url = "http://example.com/?foo=bar#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1235,7 +1235,7 @@ async def test_http_url_attributes_async( url = "http://example.com/?foo=bar#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1271,7 +1271,7 @@ def test_http_url_attributes_no_query_or_fragment_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1306,7 +1306,7 @@ async def test_http_url_attributes_no_query_or_fragment_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1416,7 +1416,7 @@ def test_url_query_data_collection_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1522,7 +1522,7 @@ async def test_url_query_data_collection_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1571,7 +1571,7 @@ def test_url_full_reassembly_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1618,7 +1618,7 @@ async def test_url_full_reassembly_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1672,7 +1672,7 @@ def test_url_query_params_off_keeps_bare_url_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx.Client().get(url) sentry_sdk.flush() @@ -1734,7 +1734,7 @@ async def test_url_query_params_off_keeps_bare_url_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx.AsyncClient().get(url) sentry_sdk.flush() @@ -1812,7 +1812,7 @@ def test_crumb_url_query_data_collection_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() httpx.Client().get(url) @@ -1894,7 +1894,7 @@ async def test_crumb_url_query_data_collection_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() await httpx.AsyncClient().get(url) @@ -1930,7 +1930,7 @@ def test_omit_url_data_if_parsing_fails( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() with mock.patch( diff --git a/tests/integrations/httpx2/test_httpx2.py b/tests/integrations/httpx2/test_httpx2.py index 09c87113da..279024d2c5 100644 --- a/tests/integrations/httpx2/test_httpx2.py +++ b/tests/integrations/httpx2/test_httpx2.py @@ -37,7 +37,7 @@ def before_breadcrumb(crumb, hint): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = httpx2.Client().get(url) @@ -93,7 +93,7 @@ def before_breadcrumb(crumb, hint): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = await httpx2.AsyncClient().get(url) @@ -219,7 +219,7 @@ def test_crumb_capture_client_error_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = httpx2.Client().get(url) @@ -281,7 +281,7 @@ async def test_crumb_capture_client_error_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() response = await httpx2.AsyncClient().get(url) @@ -484,7 +484,7 @@ def test_outgoing_trace_headers_sync(sentry_init, capture_items, httpx2_mock): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = httpx2.Client().get(url) sentry_sdk.flush() @@ -513,7 +513,7 @@ async def test_outgoing_trace_headers_async(sentry_init, capture_items, httpx2_m items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -547,7 +547,7 @@ def test_outgoing_trace_headers_append_to_baggage_sync( items = capture_items("span") with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = httpx2.Client().get(url, headers={"baGGage": "custom=data"}) sentry_sdk.flush() @@ -580,7 +580,7 @@ async def test_outgoing_trace_headers_append_to_baggage_async( items = capture_items("span") with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): response = await httpx2.AsyncClient().get( url, headers={"baGGage": "custom=data"} ) @@ -686,7 +686,7 @@ def test_request_source_disabled_sync(sentry_init, capture_items, httpx2_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -714,7 +714,7 @@ async def test_request_source_disabled_async(sentry_init, capture_items, httpx2_ url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -750,7 +750,7 @@ def test_request_source_enabled_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -787,7 +787,7 @@ async def test_request_source_enabled_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -814,7 +814,7 @@ def test_request_source_sync(sentry_init, capture_items, httpx2_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -857,7 +857,7 @@ async def test_request_source_async(sentry_init, capture_items, httpx2_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -906,7 +906,7 @@ def test_request_source_with_module_in_search_path_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): from httpx2_helpers.helpers import get_request_with_client get_request_with_client(httpx2.Client(), url) @@ -951,7 +951,7 @@ async def test_request_source_with_module_in_search_path_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): from httpx2_helpers.helpers import async_get_request_with_client await async_get_request_with_client(httpx2.AsyncClient(), url) @@ -996,7 +996,7 @@ def test_no_request_source_if_duration_too_short_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1027,7 +1027,7 @@ async def test_no_request_source_if_duration_too_short_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1057,7 +1057,7 @@ def test_request_source_if_duration_over_threshold_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1106,7 +1106,7 @@ async def test_request_source_if_duration_over_threshold_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1149,7 +1149,7 @@ def test_span_origin_sync(sentry_init, capture_items, httpx2_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1172,7 +1172,7 @@ async def test_span_origin_async(sentry_init, capture_items, httpx2_mock): url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1195,7 +1195,7 @@ def test_http_url_attributes_sync(sentry_init, capture_items, httpx2_mock): url = "http://example.com/?foo=bar#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1223,7 +1223,7 @@ async def test_http_url_attributes_async(sentry_init, capture_items, httpx2_mock url = "http://example.com/?foo=bar#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1252,7 +1252,7 @@ def test_http_url_attributes_no_query_or_fragment_sync( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1282,7 +1282,7 @@ async def test_http_url_attributes_no_query_or_fragment_async( url = "http://example.com/" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1308,7 +1308,7 @@ def test_http_url_attributes_pii_disabled_sync(sentry_init, capture_items, httpx url = "http://example.com/?foo=bar#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1337,7 +1337,7 @@ async def test_http_url_attributes_pii_disabled_async( url = "http://example.com/?foo=bar#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1443,7 +1443,7 @@ def test_url_query_data_collection_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1549,7 +1549,7 @@ async def test_url_query_data_collection_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1598,7 +1598,7 @@ def test_url_full_reassembly_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1645,7 +1645,7 @@ async def test_url_full_reassembly_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1699,7 +1699,7 @@ def test_url_query_params_off_keeps_bare_url_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): httpx2.Client().get(url) sentry_sdk.flush() @@ -1761,7 +1761,7 @@ async def test_url_query_params_off_keeps_bare_url_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): await httpx2.AsyncClient().get(url) sentry_sdk.flush() @@ -1839,7 +1839,7 @@ def test_crumb_url_query_data_collection_sync( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() httpx2.Client().get(url) @@ -1921,7 +1921,7 @@ async def test_crumb_url_query_data_collection_async( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() await httpx2.AsyncClient().get(url) @@ -1957,7 +1957,7 @@ def test_omit_url_data_if_parsing_fails( url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): events = capture_events() with mock.patch( diff --git a/tests/integrations/huey/test_huey.py b/tests/integrations/huey/test_huey.py index 516266cc9e..d528307033 100644 --- a/tests/integrations/huey/test_huey.py +++ b/tests/integrations/huey/test_huey.py @@ -245,7 +245,7 @@ def dummy_task(): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): dummy_task() sentry_sdk.get_client().flush() @@ -275,7 +275,7 @@ def test_huey_propagate_trace(init_huey, capture_items): def propagated_trace_task(): pass - with sentry_sdk.traces.start_span(name="producer"): + with sentry_sdk.start_span(name="producer"): execute_huey_task(huey, propagated_trace_task) sentry_sdk.get_client().flush() @@ -302,7 +302,7 @@ def dummy_task(): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): dummy_task() sentry_sdk.get_client().flush() @@ -356,7 +356,7 @@ def task2(): items = capture_items("span") - with sentry_sdk.traces.start_span(name="submission"): + with sentry_sdk.start_span(name="submission"): huey.enqueue(group([task1.s(), task2.s()])) for _ in range(2): @@ -443,7 +443,7 @@ def task2(results): pass items = capture_items("span") - with sentry_sdk.traces.start_span(name="submission"): + with sentry_sdk.start_span(name="submission"): huey.enqueue(chord([task1.s()], task2.s())) for _ in range(2): diff --git a/tests/integrations/launchdarkly/test_launchdarkly.py b/tests/integrations/launchdarkly/test_launchdarkly.py index f456f7c99d..5a9048becc 100644 --- a/tests/integrations/launchdarkly/test_launchdarkly.py +++ b/tests/integrations/launchdarkly/test_launchdarkly.py @@ -208,7 +208,7 @@ def test_launchdarkly_span_integration( items = capture_items("span") - with sentry_sdk.traces.start_span(name="bar"): + with sentry_sdk.start_span(name="bar"): client.variation("hello", Context.create("my-org", "organization"), False) client.variation("other", Context.create("my-org", "organization"), False) diff --git a/tests/integrations/mcp/test_mcp.py b/tests/integrations/mcp/test_mcp.py index ac3f4f014b..53996a21ce 100644 --- a/tests/integrations/mcp/test_mcp.py +++ b/tests/integrations/mcp/test_mcp.py @@ -1007,7 +1007,7 @@ async def prompt_handler(ctx, params): server.add_request_handler("prompts/get", GetPromptRequestParams, prompt_handler) items = capture_items("span") - tx_ctx = sentry_sdk.traces.start_span(name="mcp tx") + tx_ctx = sentry_sdk.start_span(name="mcp tx") with tx_ctx: await stdio( diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py index cf67c09147..5c56379d5d 100644 --- a/tests/integrations/openai_agents/test_openai_agents.py +++ b/tests/integrations/openai_agents/test_openai_agents.py @@ -2651,7 +2651,7 @@ async def test_hosted_mcp_tool_propagation_header_streamed( {"sentry-trace": "01234567890123456789012345678901-0000000000000000"} ) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", attributes={ "sentry.op": "greeting.sniff", @@ -2753,7 +2753,7 @@ async def test_hosted_mcp_tool_propagation_headers( {"sentry-trace": "01234567890123456789012345678901-0000000000000000"} ) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", attributes={ "sentry.op": "greeting.sniff", @@ -3147,7 +3147,7 @@ def test_openai_agents_message_role_mapping(sentry_init, test_message, expected_ get_response_kwargs = {"input": [test_message]} - with sentry_sdk.traces.start_span(name="test") as span: + with sentry_sdk.start_span(name="test") as span: _set_input_data(span, get_response_kwargs) # Verify that messages were processed and roles were mapped @@ -3705,7 +3705,7 @@ async def test_streaming_span_update_captures_response_data( ] # Test the unified update function (works for both streaming and non-streaming) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( attributes={"sentry.op": "gen_ai.chat"}, name="test chat" ) as span: update_ai_client_span(span, mock_streaming_response) diff --git a/tests/integrations/openfeature/test_openfeature.py b/tests/integrations/openfeature/test_openfeature.py index 73fc7c8f3a..fd5b2a8c85 100644 --- a/tests/integrations/openfeature/test_openfeature.py +++ b/tests/integrations/openfeature/test_openfeature.py @@ -170,7 +170,7 @@ def test_openfeature_span_integration( client = api.get_client() items = capture_items("span") - with sentry_sdk.traces.start_span(name="bar"): + with sentry_sdk.start_span(name="bar"): client.get_boolean_value("hello", default_value=False) client.get_boolean_value("world", default_value=False) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 21349213e2..ce71054387 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -1591,7 +1591,7 @@ async def test_update_invoke_agent_span_with_none_output( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Update with None output - should not raise update_invoke_agent_span(span, None) @@ -1616,7 +1616,7 @@ async def test_update_ai_client_span_with_none_response( traces_sample_rate=1.0, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Update with None response - should not raise update_ai_client_span(span, None) @@ -1664,7 +1664,7 @@ async def test_input_messages_error_handling( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Pass invalid messages that would cause an error invalid_messages = [object()] # Plain object without expected attributes @@ -1692,7 +1692,7 @@ async def test_available_tools_error_handling( traces_sample_rate=1.0, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create mock agent with invalid toolset mock_agent = MagicMock() @@ -1719,7 +1719,7 @@ async def test_set_usage_data_with_none_usage( traces_sample_rate=1.0, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Pass None usage - should not raise _set_usage_data(span, None) @@ -1744,7 +1744,7 @@ async def test_set_usage_data_with_partial_fields( traces_sample_rate=1.0, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create usage object with only some fields mock_usage = MagicMock() @@ -1816,7 +1816,7 @@ async def test_message_parts_with_list_content( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create message with list content mock_msg = MagicMock() @@ -1927,7 +1927,7 @@ async def test_output_data_error_handling( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create mock response that will cause error mock_response = MagicMock() @@ -1959,7 +1959,7 @@ async def test_message_with_system_prompt_part( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create message with SystemPromptPart system_part = messages.SystemPromptPart(content="You are a helpful assistant") @@ -1993,7 +1993,7 @@ async def test_message_with_instructions( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create message with instructions mock_msg = MagicMock() @@ -2025,7 +2025,7 @@ async def test_set_input_messages_without_prompts( send_default_pii=True, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Even with messages, should not set them messages = ["test"] @@ -2143,7 +2143,7 @@ async def test_set_available_tools_without_toolset( traces_sample_rate=1.0, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create agent without _function_toolset mock_agent = MagicMock() @@ -2172,7 +2172,7 @@ async def test_set_available_tools_with_schema( traces_sample_rate=1.0, ) - span = sentry_sdk.traces.start_span(name="test_span") + span = sentry_sdk.start_span(name="test_span") # Create agent with toolset containing schema mock_agent = MagicMock() @@ -2507,7 +2507,7 @@ async def test_binary_content_encoding_image( ) items = capture_items("span") - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="custom span", attributes={"sentry.op": "test_span"} ) binary_content = BinaryContent( @@ -2542,7 +2542,7 @@ async def test_binary_content_encoding_mixed_content( ) items = capture_items("span") - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="custom span", attributes={"sentry.op": "test_span"} ) binary_content = BinaryContent(data=b"fake_image_bytes", media_type="image/jpeg") @@ -2620,7 +2620,7 @@ async def test_set_usage_data_with_cache_tokens( ) items = capture_items("span") - span = sentry_sdk.traces.start_span( + span = sentry_sdk.start_span( name="custom span", attributes={"sentry.op": "test_span"} ) usage = RequestUsage( diff --git a/tests/integrations/pymongo/test_pymongo.py b/tests/integrations/pymongo/test_pymongo.py index ee5a4a1f85..41dbaab3bb 100644 --- a/tests/integrations/pymongo/test_pymongo.py +++ b/tests/integrations/pymongo/test_pymongo.py @@ -71,7 +71,7 @@ def test_segment(sentry_init, capture_items, mongo_server, with_pii): connection = MongoClient(mongo_server.uri) - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): list( connection["test_db"]["test_collection"].find({"foobar": 1}) ) # force query execution @@ -144,7 +144,7 @@ def test_segment_with_data_collection( connection = MongoClient(mongo_server.uri) - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): list( connection["test_db"]["test_collection"].find({"foobar": 1}) ) # force query execution @@ -557,7 +557,7 @@ def test_span_origin(sentry_init, capture_items, mongo_server): connection = MongoClient(mongo_server.uri) - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): list( connection["test_db"]["test_collection"].find({"foobar": 1}) ) # force query execution @@ -579,7 +579,7 @@ def test_status_on_success(sentry_init, capture_items, mongo_server): connection = MongoClient(mongo_server.uri) - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): connection["test_db"]["test_collection"].insert_one({"foo": 1}) sentry_sdk.flush() @@ -599,7 +599,7 @@ def test_status_on_failure(sentry_init, capture_items, mongo_server): connection = MongoClient(mongo_server.uri) - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): try: connection["test_db"]["erroneous"].insert_many([{"bar": 3}]) pytest.fail("Request should raise") diff --git a/tests/integrations/pyreqwest/test_pyreqwest.py b/tests/integrations/pyreqwest/test_pyreqwest.py index 42b778a5c4..2732cc2cd7 100644 --- a/tests/integrations/pyreqwest/test_pyreqwest.py +++ b/tests/integrations/pyreqwest/test_pyreqwest.py @@ -75,7 +75,7 @@ def test_sync_client_spans( url = f"http://localhost:{server_port}/hello?q=test#frag" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() response = client.get(url).build().send() assert response.status == 200 @@ -121,7 +121,7 @@ async def test_async_client_spans( items = capture_items("span") async with ClientBuilder().build() as client: - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = await client.get(url).build().send() assert response.status == 200 @@ -157,7 +157,7 @@ def test_sync_simple_request_spans( url = f"http://localhost:{server_port}/hello-simple" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = sync_pyreqwest_get(url).send() assert response.status == 200 @@ -194,7 +194,7 @@ async def test_async_simple_request_spans( url = f"http://localhost:{server_port}/hello-simple-async" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = await async_pyreqwest_get(url).send() assert response.status == 200 @@ -227,7 +227,7 @@ def test_span_origin( url = f"http://localhost:{server_port}/origin" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() client.get(url).build().send() @@ -250,7 +250,7 @@ def test_outgoing_trace_headers( url = f"http://localhost:{server_port}/trace" items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="custom parent", ): client = SyncClientBuilder().build() @@ -288,7 +288,7 @@ def test_outgoing_trace_headers_append_to_baggage( items = capture_items("span") with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=500000): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", attributes={ "sentry.op": "greeting.sniff", @@ -368,7 +368,7 @@ def test_omit_url_data_if_parsing_fails( url = f"http://localhost:{server_port}/parse-fail" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): with mock.patch( "sentry_sdk.integrations.pyreqwest.parse_url", side_effect=ValueError, @@ -403,7 +403,7 @@ def test_request_source_disabled( url = f"http://localhost:{server_port}/hello" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() client.get(url).build().send() @@ -438,7 +438,7 @@ def test_request_source_enabled( url = f"http://localhost:{server_port}/hello" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() client.get(url).build().send() @@ -468,7 +468,7 @@ def test_request_source( url = f"http://localhost:{server_port}/hello" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() client.get(url).build().send() @@ -508,7 +508,7 @@ def test_request_source_with_module_in_search_path( url = f"http://localhost:{server_port}/hello" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from pyreqwest_helpers.helpers import get_request_with_client client = SyncClientBuilder().build() @@ -545,8 +545,8 @@ def test_no_request_source_if_duration_too_short( url = f"http://localhost:{server_port}/hello" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): - original_start_span = sentry_sdk.traces.start_span + with sentry_sdk.start_span(name="custom parent"): + original_start_span = sentry_sdk.start_span @contextmanager def fake_start_span(*args, **kwargs): @@ -559,7 +559,7 @@ def fake_start_span(*args, **kwargs): span._end_timestamp = None with mock.patch( - "sentry_sdk.integrations.pyreqwest.sentry_sdk.traces.start_span", + "sentry_sdk.integrations.pyreqwest.sentry_sdk.start_span", fake_start_span, ): client = SyncClientBuilder().build() @@ -591,8 +591,8 @@ def test_request_source_if_duration_over_threshold( url = f"http://localhost:{server_port}/hello" items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): - original_start_span = sentry_sdk.traces.start_span + with sentry_sdk.start_span(name="custom parent"): + original_start_span = sentry_sdk.start_span @contextmanager def fake_start_span(*args, **kwargs): @@ -605,7 +605,7 @@ def fake_start_span(*args, **kwargs): span._end_timestamp = None with mock.patch( - "sentry_sdk.integrations.pyreqwest.sentry_sdk.traces.start_span", + "sentry_sdk.integrations.pyreqwest.sentry_sdk.start_span", fake_start_span, ): client = SyncClientBuilder().build() @@ -685,7 +685,7 @@ async def test_async_crumb_capture( events = capture_events() - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): async with ClientBuilder().build() as client: response = await client.get(url).build().send() assert response.status == 200 @@ -735,7 +735,7 @@ def test_crumb_capture_client_error( events = capture_events() - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): client = SyncClientBuilder().build() response = client.get(url).build().send() assert response.status == status_code @@ -855,7 +855,7 @@ def test_url_query_data_collection_sync( url = f"http://localhost:{server_port}/hello?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() response = client.get(url).build().send() assert response.status == 200 @@ -966,7 +966,7 @@ async def test_url_query_data_collection_async( url = f"http://localhost:{server_port}/hello?toy=tennisball&color=red&auth=secret#frag" async with ClientBuilder().build() as client: - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = await client.get(url).build().send() assert response.status == 200 @@ -1024,7 +1024,7 @@ def test_url_full_reassembly_sync( base_url = f"http://localhost:{server_port}/hello" url = f"{base_url}?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() response = client.get(url).build().send() assert response.status == 200 @@ -1082,7 +1082,7 @@ async def test_url_full_reassembly_async( url = f"{base_url}?toy=tennisball&color=red&auth=secret#frag" async with ClientBuilder().build() as client: - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = await client.get(url).build().send() assert response.status == 200 @@ -1140,7 +1140,7 @@ def test_url_query_params_off_keeps_bare_url_sync( base_url = f"http://localhost:{server_port}/hello" url = f"{base_url}?toy=tennisball&color=red&auth=secret#frag" - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): client = SyncClientBuilder().build() response = client.get(url).build().send() assert response.status == 200 @@ -1208,7 +1208,7 @@ async def test_url_query_params_off_keeps_bare_url_async( url = f"{base_url}?toy=tennisball&color=red&auth=secret#frag" async with ClientBuilder().build() as client: - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): response = await client.get(url).build().send() assert response.status == 200 @@ -1273,7 +1273,7 @@ def test_crumb_url_query_data_collection_sync( events = capture_events() - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): client = SyncClientBuilder().build() response = client.get(url).build().send() assert response.status == 200 @@ -1342,7 +1342,7 @@ async def test_crumb_url_query_data_collection_async( events = capture_events() - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): async with ClientBuilder().build() as client: response = await client.get(url).build().send() assert response.status == 200 @@ -1382,7 +1382,7 @@ def test_omit_url_data_if_parsing_fails_data_collection( events = capture_events() - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): with mock.patch( "sentry_sdk.integrations.pyreqwest.parse_url", side_effect=ValueError, diff --git a/tests/integrations/ray/test_ray.py b/tests/integrations/ray/test_ray.py index 924cc3b908..51fd21f3e1 100644 --- a/tests/integrations/ray/test_ray.py +++ b/tests/integrations/ray/test_ray.py @@ -136,7 +136,7 @@ def read_spans_from_log(job_id, ray_temp_dir, min_spans=1, timeout=10): def example_task(): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="example task step", attributes={ "sentry.op": "task", @@ -147,7 +147,7 @@ def example_task(): # RayIntegration must leave variadic keyword arguments at the end def example_task_with_kwargs(**kwargs): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="example task step", attributes={"sentry.op": "task"} ): ... @@ -195,7 +195,7 @@ def test_tracing_in_ray_tasks( _temp_dir=ray_temp_dir, ) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="ray test parent", attributes={"sentry.op": "task"} ): future = example_task.remote() @@ -262,7 +262,7 @@ def test_errors_in_ray_tasks(): def example_task(): 1 / 0 - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="ray test parent", attributes={"sentry.op": "task"} ): with pytest.raises(ZeroDivisionError): @@ -306,7 +306,7 @@ def __init__(self): self.n = 0 def increment(self): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="example actor execution", attributes={"sentry.op": "task"} ): self.n += 1 @@ -318,7 +318,7 @@ def __init__(self): self.n = 0 def increment(self): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="example actor execution", attributes={"sentry.op": "task"} ): self.n += 1 @@ -335,7 +335,7 @@ def increment(self): _temp_dir=ray_temp_dir, ) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="ray test parent", attributes={"sentry.op": "task"} ): counter = Counter.remote() @@ -390,14 +390,14 @@ def __init__(self): self.n = 0 def increment(self): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="example actor execution", attributes={"sentry.op": "task"} ): 1 / 0 return sentry_sdk.get_client().transport.envelopes - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="ray test parent", attributes={"sentry.op": "task"} ): with pytest.raises(ZeroDivisionError): diff --git a/tests/integrations/redis/asyncio/test_redis_asyncio.py b/tests/integrations/redis/asyncio/test_redis_asyncio.py index 72d0ae262c..f2a07bc0a4 100644 --- a/tests/integrations/redis/asyncio/test_redis_asyncio.py +++ b/tests/integrations/redis/asyncio/test_redis_asyncio.py @@ -60,7 +60,7 @@ async def test_async_redis_pipeline( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): pipeline = connection.pipeline(transaction=is_transaction) pipeline.get("foo") pipeline.set("bar", 1) @@ -95,7 +95,7 @@ async def test_async_span_origin(sentry_init, capture_events, capture_items): connection = FakeRedis() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): # default case await connection.set("somekey", "somevalue") diff --git a/tests/integrations/redis/cluster/test_redis_cluster.py b/tests/integrations/redis/cluster/test_redis_cluster.py index 81d3b6a8e2..2f6072f844 100644 --- a/tests/integrations/redis/cluster/test_redis_cluster.py +++ b/tests/integrations/redis/cluster/test_redis_cluster.py @@ -78,7 +78,7 @@ def test_rediscluster_basic( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rc = redis.RedisCluster(host="localhost", port=6379) rc.set("bar", 1) @@ -128,7 +128,7 @@ def test_rediscluster_pipeline( rc = redis.RedisCluster(host="localhost", port=6379) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): pipeline = rc.pipeline() pipeline.get("foo") pipeline.set("bar", 1) @@ -169,7 +169,7 @@ def test_rediscluster_span_origin( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): # default case rc.set("somekey", "somevalue") diff --git a/tests/integrations/redis/cluster_asyncio/test_redis_cluster_asyncio.py b/tests/integrations/redis/cluster_asyncio/test_redis_cluster_asyncio.py index 83c2dca022..adaf968272 100644 --- a/tests/integrations/redis/cluster_asyncio/test_redis_cluster_asyncio.py +++ b/tests/integrations/redis/cluster_asyncio/test_redis_cluster_asyncio.py @@ -86,7 +86,7 @@ async def test_async_basic( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await connection.set("bar", 1) sentry_sdk.flush() @@ -130,7 +130,7 @@ async def test_async_redis_pipeline( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): pipeline = connection.pipeline() pipeline.get("foo") pipeline.set("bar", 1) @@ -163,7 +163,7 @@ async def test_async_span_origin(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): # default case await connection.set("somekey", "somevalue") diff --git a/tests/integrations/redis/test_redis.py b/tests/integrations/redis/test_redis.py index c3a7cce69f..608da76f2c 100644 --- a/tests/integrations/redis/test_redis.py +++ b/tests/integrations/redis/test_redis.py @@ -67,7 +67,7 @@ def test_redis_pipeline( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): pipeline = connection.pipeline(transaction=is_transaction) pipeline.get("foo") pipeline.set("bar", 1) @@ -118,7 +118,7 @@ def test_redis_pipeline_data_collection( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): pipeline = connection.pipeline(transaction=False) pipeline.get("foo") pipeline.set("bar", 1) @@ -154,7 +154,7 @@ def test_sensitive_data( connection = FakeRedis() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.get("this is super secret") sentry_sdk.flush() @@ -181,7 +181,7 @@ def test_pii_data_redacted( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.set("somekey1", "my secret string1") connection.set("somekey2", "my secret string2") connection.get("somekey2") @@ -232,7 +232,7 @@ def test_data_collection_database_query_data( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.set("somekey1", "my secret string1") sentry_sdk.flush() @@ -277,7 +277,7 @@ def test_database_query_data_takes_precedence_over_send_default_pii( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.set("somekey1", "my secret string1") sentry_sdk.flush() @@ -302,7 +302,7 @@ def test_pii_data_sent(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.set("somekey1", "my secret string1") connection.set("somekey2", "my secret string2") connection.get("somekey2") @@ -342,7 +342,7 @@ def test_no_data_truncation_by_default(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.set("somekey1", long_string) connection.set("somekey2", short_string) @@ -416,7 +416,7 @@ def test_db_connection_attributes_client(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection = FakeRedis(connection_pool=MOCK_CONNECTION_POOL) connection.get("foobar") @@ -445,7 +445,7 @@ def test_db_connection_attributes_pipeline(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection = FakeRedis(connection_pool=MOCK_CONNECTION_POOL) pipeline = connection.pipeline(transaction=False) pipeline.get("foo") @@ -479,7 +479,7 @@ def test_span_origin(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): # default case connection.set("somekey", "somevalue") diff --git a/tests/integrations/redis/test_redis_cache_module.py b/tests/integrations/redis/test_redis_cache_module.py index 92f7421841..87984a2fc8 100644 --- a/tests/integrations/redis/test_redis_cache_module.py +++ b/tests/integrations/redis/test_redis_cache_module.py @@ -25,7 +25,7 @@ def test_no_cache_basic(sentry_init, capture_events, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.get("mycachekey") sentry_sdk.flush() @@ -50,7 +50,7 @@ def test_cache_basic(sentry_init, capture_events, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.hget("mycachekey", "myfield") connection.get("mycachekey") connection.set("mycachekey1", "bla") @@ -118,7 +118,7 @@ def test_cache_keys(sentry_init, capture_events, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.get("somethingelse") connection.get("blub") connection.get("blubkeything") @@ -171,7 +171,7 @@ def test_cache_data(sentry_init, capture_events, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.get("mycachekey") connection.set("mycachekey", "事实胜于雄辩") connection.get("mycachekey") @@ -249,7 +249,7 @@ def test_cache_prefixes(sentry_init, capture_events, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): connection.mget("yes", "no") connection.mget("no", 1, "yes") connection.mget("no", "yes.1", "yes.2") diff --git a/tests/integrations/redis/test_redis_cache_module_async.py b/tests/integrations/redis/test_redis_cache_module_async.py index 5fc89b432b..669efbe0ee 100644 --- a/tests/integrations/redis/test_redis_cache_module_async.py +++ b/tests/integrations/redis/test_redis_cache_module_async.py @@ -34,7 +34,7 @@ async def test_no_cache_basic(sentry_init, capture_events, capture_items): connection = FakeRedisAsync() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await connection.get("myasynccachekey") sentry_sdk.flush() @@ -58,7 +58,7 @@ async def test_cache_basic(sentry_init, capture_events, capture_items): connection = FakeRedisAsync() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await connection.get("myasynccachekey") sentry_sdk.flush() @@ -84,7 +84,7 @@ async def test_cache_keys(sentry_init, capture_events, capture_items): connection = FakeRedisAsync() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await connection.get("asomethingelse") await connection.get("ablub") await connection.get("ablubkeything") @@ -136,7 +136,7 @@ async def test_cache_data(sentry_init, capture_events, capture_items): connection = FakeRedisAsync(host=host, port=6378) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): await connection.get("myasynccachekey") await connection.set("myasynccachekey", "事实胜于雄辩") await connection.get("myasynccachekey") diff --git a/tests/integrations/rq/test_rq.py b/tests/integrations/rq/test_rq.py index de95bffb3e..68a3afae3b 100644 --- a/tests/integrations/rq/test_rq.py +++ b/tests/integrations/rq/test_rq.py @@ -228,7 +228,7 @@ def test_tracing_enabled( worker = rq.SimpleWorker([queue], connection=queue.connection) items = capture_items("event", "span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="custom parent", attributes={ "sentry.op": "rq transaction", diff --git a/tests/integrations/rust_tracing/test_rust_tracing.py b/tests/integrations/rust_tracing/test_rust_tracing.py index f8c76d6f30..ff010a241c 100644 --- a/tests/integrations/rust_tracing/test_rust_tracing.py +++ b/tests/integrations/rust_tracing/test_rust_tracing.py @@ -78,7 +78,7 @@ def test_on_new_span_on_close( traces_sample_rate=1.0, ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) sentry_first_rust_span = sentry_sdk.traces.get_current_span() @@ -128,7 +128,7 @@ def test_nested_on_new_span_on_close( traces_sample_rate=1.0, ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): original_sentry_span = sentry_sdk.traces.get_current_span() rust_tracing.new_span(RustTracingLevel.Info, 3, index_arg=10) @@ -226,7 +226,7 @@ def test_on_event_exception( items = capture_items("event") sentry_sdk.get_isolation_scope().clear_breadcrumbs() - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) # Mapped to Exception @@ -267,7 +267,7 @@ def test_on_event_breadcrumb( items = capture_items("event") sentry_sdk.get_isolation_scope().clear_breadcrumbs() - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) # Mapped to Breadcrumb @@ -302,7 +302,7 @@ def test_on_event_event( items = capture_items("event") sentry_sdk.get_isolation_scope().clear_breadcrumbs() - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) # Mapped to Event @@ -343,7 +343,7 @@ def test_on_event_ignored( items = capture_items("span") sentry_sdk.get_isolation_scope().clear_breadcrumbs() - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) # Ignored @@ -380,7 +380,7 @@ def span_filter(metadata: Dict[str, object]) -> bool: traces_sample_rate=1.0, ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): original_sentry_span = sentry_sdk.traces.get_current_span() # Span is not ignored @@ -418,7 +418,7 @@ def test_record( integrations=[integration], traces_sample_rate=1.0, ) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) span_before_record = sentry_sdk.traces.get_current_span()._to_json() @@ -448,7 +448,7 @@ def span_filter(metadata: Dict[str, object]) -> bool: integrations=[integration], traces_sample_rate=1.0, ) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) span_before_record = sentry_sdk.traces.get_current_span()._to_json() @@ -491,7 +491,7 @@ def test_include_tracing_fields( traces_sample_rate=1.0, send_default_pii=send_default_pii, ) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) span_before_record = sentry_sdk.traces.get_current_span()._to_json() diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index db6c46a648..a66e85c498 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -500,7 +500,7 @@ def test_user_ip_address_on_all_spans( @app.route("/child-span") def child_span_handler(request): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass return response.text("ok") diff --git a/tests/integrations/socket/test_socket.py b/tests/integrations/socket/test_socket.py index cc7016cf9c..fe18355847 100644 --- a/tests/integrations/socket/test_socket.py +++ b/tests/integrations/socket/test_socket.py @@ -15,7 +15,7 @@ def test_getaddrinfo_trace(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="root"): + with sentry_sdk.start_span(name="root"): socket.getaddrinfo("localhost", PORT) sentry_sdk.flush() @@ -40,7 +40,7 @@ def test_create_connection_trace(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="root"): + with sentry_sdk.start_span(name="root"): socket.create_connection(("localhost", PORT), timeout, None) sentry_sdk.flush() @@ -69,7 +69,7 @@ def test_span_origin(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): socket.create_connection(("localhost", PORT), 1, None) sentry_sdk.flush() diff --git a/tests/integrations/sqlalchemy/test_sqlalchemy.py b/tests/integrations/sqlalchemy/test_sqlalchemy.py index 0a19ece92f..d4f0dca3aa 100644 --- a/tests/integrations/sqlalchemy/test_sqlalchemy.py +++ b/tests/integrations/sqlalchemy/test_sqlalchemy.py @@ -118,7 +118,7 @@ class Address(Base): session = Session() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): with session.begin_nested(): session.query(Person).first() @@ -202,7 +202,7 @@ class Address(Base): session = Session() items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): with session.begin_nested(): session.query(Person).first() @@ -242,7 +242,7 @@ def test_long_sql_query_preserved( "sqlite:///:memory:", connect_args={"check_same_thread": False} ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): with engine.connect() as con: con.execute(text(" UNION ".join("SELECT {}".format(i) for i in range(100)))) @@ -284,7 +284,7 @@ def test_query_source_disabled( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): Base = declarative_base() # noqa: N806 class Person(Base): @@ -341,7 +341,7 @@ def test_query_source_enabled( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): Base = declarative_base() # noqa: N806 class Person(Base): @@ -391,7 +391,7 @@ def test_query_source( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): Base = declarative_base() # noqa: N806 class Person(Base): @@ -464,7 +464,7 @@ def test_query_source_with_module_in_search_path( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): Base = declarative_base() # noqa: N806 class Person(Base): @@ -533,7 +533,7 @@ def test_no_query_source_if_duration_too_short( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): Base = declarative_base() # noqa: N806 class Person(Base): @@ -602,7 +602,7 @@ def test_query_source_if_duration_over_threshold( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): Base = declarative_base() # noqa: N806 class Person(Base): @@ -689,7 +689,7 @@ def test_span_origin( "sqlite:///:memory:", connect_args={"check_same_thread": False} ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): with engine.connect() as con: con.execute(text("SELECT 0")) diff --git a/tests/integrations/statsig/test_statsig.py b/tests/integrations/statsig/test_statsig.py index ce5849c89b..7446f321b3 100644 --- a/tests/integrations/statsig/test_statsig.py +++ b/tests/integrations/statsig/test_statsig.py @@ -197,7 +197,7 @@ def test_statsig_span_integration( user = StatsigUser(user_id="user-id") items = capture_items("span") - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): statsig.check_gate(user, "hello") statsig.check_gate(user, "world") diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index aeaaf1f5f0..27521ed961 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -313,7 +313,7 @@ def getresponse(self, *args, **kwargs): items = capture_items("span") sentry_sdk.traces.continue_trace(headers) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", attributes={ "sentry.op": "greeting.sniff", @@ -377,7 +377,7 @@ def getresponse(self, *args, **kwargs): sentry_sdk.traces.continue_trace({}) with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000): - with sentry_sdk.traces.start_span(name="Head SDK tx"): + with sentry_sdk.start_span(name="Head SDK tx"): connection = HTTPSConnectionRecordingRequestHeaders("localhost", port=PORT) connection.request("GET", "/top-chasers") connection.getresponse() @@ -570,7 +570,7 @@ def getresponse(self, *args, **kwargs): } sentry_sdk.traces.continue_trace(headers) - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", attributes={ "sentry.op": "greeting.sniff", @@ -603,7 +603,7 @@ def test_request_source_disabled( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", port=PORT) conn.request("GET", "/foo") conn.getresponse() @@ -639,7 +639,7 @@ def test_request_source_enabled( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", port=PORT) conn.request("GET", "/foo") conn.getresponse() @@ -667,7 +667,7 @@ def test_request_source( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", port=PORT) conn.request("GET", "/foo") conn.getresponse() @@ -713,7 +713,7 @@ def test_request_source_with_module_in_search_path( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): from httplib_helpers.helpers import get_request_with_connection conn = HTTPConnection("localhost", port=PORT) @@ -765,7 +765,7 @@ def add_http_request_source_with_pinned_timestamps(span): "sentry_sdk.integrations.stdlib.add_http_request_source", add_http_request_source_with_pinned_timestamps, ): - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): conn = HTTPConnection("localhost", port=PORT) conn.request("GET", "/foo") conn.getresponse() @@ -807,7 +807,7 @@ def add_http_request_source_with_pinned_timestamps(span): "sentry_sdk.integrations.stdlib.add_http_request_source", add_http_request_source_with_pinned_timestamps, ): - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): conn = HTTPConnection("localhost", port=PORT) conn.request("GET", "/foo") conn.getresponse() @@ -852,7 +852,7 @@ def test_span_origin( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", port=PORT) conn.request("GET", "/foo") conn.getresponse() @@ -880,7 +880,7 @@ def test_http_timeout( items = capture_items("span") with pytest.raises(TimeoutError): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="name", attributes={ "sentry.op": "op", @@ -912,7 +912,7 @@ def test_proxy_http_tunnel( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", PROXY_PORT) conn.set_tunnel("api.example.com", tunnel_port) conn.request("GET", "/foo?bar=1") @@ -954,7 +954,7 @@ def test_chunked_response_span_covers_body_read( min_expected_duration = CHUNK_DELAY * NUM_CHUNKS items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", CHUNKED_PORT) conn.request("GET", "/chunked") response = conn.getresponse() @@ -1055,7 +1055,7 @@ def test_url_query_data_collection( items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", PORT) conn.request( "GET", "/some/random/url?toy=tennisball&color=red&auth=secret#frag" @@ -1111,7 +1111,7 @@ def test_url_full_reassembly(sentry_init, capture_items, init_kwargs, expected_s items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): conn = HTTPConnection("localhost", PORT) conn.request( "GET", "/some/random/url?toy=tennisball&color=red&auth=secret#frag" diff --git a/tests/integrations/stdlib/test_subprocess.py b/tests/integrations/stdlib/test_subprocess.py index 1d4b7777bf..4969f7db7b 100644 --- a/tests/integrations/stdlib/test_subprocess.py +++ b/tests/integrations/stdlib/test_subprocess.py @@ -63,7 +63,7 @@ def test_subprocess_basic( ) items = capture_items("event", "span") - with sentry_sdk.traces.start_span(name="custom parent") as span: + with sentry_sdk.start_span(name="custom parent") as span: args = [ sys.executable, "-c", @@ -172,7 +172,7 @@ def test_subprocess_empty_env( integrations=[StdlibIntegration()], traces_sample_rate=1.0, ) - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): args = [ sys.executable, "-c", @@ -206,7 +206,7 @@ def test_subprocess_span_origin( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): + with sentry_sdk.start_span(name="custom parent"): args = [ sys.executable, "-c", diff --git a/tests/integrations/threading/test_threading.py b/tests/integrations/threading/test_threading.py index a21f9f72bb..87c8569a99 100644 --- a/tests/integrations/threading/test_threading.py +++ b/tests/integrations/threading/test_threading.py @@ -137,16 +137,16 @@ def test_spans_from_multiple_threads( items = capture_items("span") def do_some_work(number): - with sentry_sdk.traces.start_span(name=f"inner-run-{number}") as span: + with sentry_sdk.start_span(name=f"inner-run-{number}") as span: inner_run_spans[number] = span threads = [] outer_submit_spans = {} inner_run_spans = {} - with sentry_sdk.traces.start_span(name="outer-seg", parent_span=None) as outer: + with sentry_sdk.start_span(name="outer-seg", parent_span=None) as outer: for number in range(5): - with sentry_sdk.traces.start_span(name=f"outer-submit-{number}") as span: + with sentry_sdk.start_span(name=f"outer-submit-{number}") as span: t = Thread(target=do_some_work, args=(number,)) t.start() threads.append(t) @@ -200,18 +200,16 @@ def test_spans_from_threadpool( items = capture_items() def do_some_work(number): - with sentry_sdk.traces.start_span(name=f"inner-run-{number}") as span: + with sentry_sdk.start_span(name=f"inner-run-{number}") as span: inner_run_spans[number] = span outer_submit_spans = {} inner_run_spans = {} - with sentry_sdk.traces.start_span(name="outer-seg") as outer: + with sentry_sdk.start_span(name="outer-seg") as outer: with futures.ThreadPoolExecutor(max_workers=1) as executor: for number in range(5): - with sentry_sdk.traces.start_span( - name=f"outer-submit-{number}" - ) as span: + with sentry_sdk.start_span(name=f"outer-submit-{number}") as span: outer_submit_spans[number] = span future = executor.submit(do_some_work, number) future.result() diff --git a/tests/integrations/tornado/test_tornado.py b/tests/integrations/tornado/test_tornado.py index 4b5163b5f1..ee7cb475c4 100644 --- a/tests/integrations/tornado/test_tornado.py +++ b/tests/integrations/tornado/test_tornado.py @@ -69,7 +69,7 @@ async def post(self): class ChildSpanHandler(RequestHandler): def get(self): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass self.write("ok") @@ -512,7 +512,7 @@ def test_transactions( client = tornado_testcase(Application([(r"/hi", handler)])) - with sentry_sdk.traces.start_span(name="client") as span: + with sentry_sdk.start_span(name="client") as span: request_headers = dict(span._iter_headers()) response = client.fetch( diff --git a/tests/integrations/unleash/test_unleash.py b/tests/integrations/unleash/test_unleash.py index c6920a8d61..9287fe51c4 100644 --- a/tests/integrations/unleash/test_unleash.py +++ b/tests/integrations/unleash/test_unleash.py @@ -181,7 +181,7 @@ def test_unleash_span_integration( client = UnleashClient() # type: ignore[arg-type] items = capture_items("span") - with sentry_sdk.traces.start_span(name="bar"): + with sentry_sdk.start_span(name="bar"): client.is_enabled("hello") client.is_enabled("other") diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index bb2ab905b4..747851d970 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -1110,7 +1110,7 @@ def dogpark(environ, start_response): @pytest.mark.parametrize("send_default_pii", [True, False]) def test_user_ip_address_on_all_spans(sentry_init, capture_items, send_default_pii): def dogpark(environ, start_response): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass start_response("200 OK", []) return ["Go get the ball! Good dog!"] @@ -1143,7 +1143,7 @@ def test_user_info_span_attributes_data_collection( sentry_init, capture_items, init_kwargs, expect_ip ): def dogpark(environ, start_response): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass start_response("200 OK", []) return ["Go get the ball! Good dog!"] diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 60c05ccc21..e7a75a022d 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -297,8 +297,8 @@ def test_continuous_profiler_auto_start_and_manual_stop( thread = threading.current_thread() - with sentry_sdk.traces.start_span(name="profiling"): - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="profiling"): + with sentry_sdk.start_span(name="op"): pass for _ in range(3): @@ -309,8 +309,8 @@ def test_continuous_profiler_auto_start_and_manual_stop( envelopes.clear() - with sentry_sdk.traces.start_span(name="profiling"): - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="profiling"): + with sentry_sdk.start_span(name="op"): time.sleep(0.05) sentry_sdk.flush() @@ -320,8 +320,8 @@ def test_continuous_profiler_auto_start_and_manual_stop( envelopes.clear() - with sentry_sdk.traces.start_span(name="profiling"): - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="profiling"): + with sentry_sdk.start_span(name="op"): pass stop_profiler() @@ -361,9 +361,9 @@ def test_continuous_profiler_manual_start_and_stop_sampled( envelopes.clear() - with sentry_sdk.traces.start_span(name="profiling"): + with sentry_sdk.start_span(name="profiling"): assert get_profiler_id() is not None, "profiler should be running" - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="op"): time.sleep(0.1) assert get_profiler_id() is not None, "profiler should be running" @@ -379,9 +379,9 @@ def test_continuous_profiler_manual_start_and_stop_sampled( envelopes.clear() - with sentry_sdk.traces.start_span(name="profiling"): + with sentry_sdk.start_span(name="profiling"): assert get_profiler_id() is None, "profiler should not be running" - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="op"): time.sleep(0.1) assert get_profiler_id() is None, "profiler should not be running" @@ -414,8 +414,8 @@ def test_continuous_profiler_manual_start_and_stop_unsampled( start_profiler() - with sentry_sdk.traces.start_span(name="profiling"): - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="profiling"): + with sentry_sdk.start_span(name="op"): pass stop_profiler() @@ -457,11 +457,11 @@ def test_continuous_profiler_auto_start_and_stop_sampled( profiler_ids = set() - with sentry_sdk.traces.start_span(name="profiling 1"): + with sentry_sdk.start_span(name="profiling 1"): profiler_id = get_profiler_id() assert profiler_id is not None, "profiler should be running" profiler_ids.add(profiler_id) - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="op"): time.sleep(0.1) profiler_id = get_profiler_id() assert profiler_id is not None, "profiler should be running" @@ -475,11 +475,11 @@ def test_continuous_profiler_auto_start_and_stop_sampled( assert profiler_id is not None, "profiler should be running" profiler_ids.add(profiler_id) - with sentry_sdk.traces.start_span(name="profiling 2"): + with sentry_sdk.start_span(name="profiling 2"): profiler_id = get_profiler_id() assert profiler_id is not None, "profiler should be running" profiler_ids.add(profiler_id) - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="op"): time.sleep(0.1) profiler_id = get_profiler_id() assert profiler_id is not None, "profiler should be running" @@ -525,9 +525,9 @@ def test_continuous_profiler_auto_start_and_stop_unsampled( for _ in range(3): envelopes.clear() - with sentry_sdk.traces.start_span(name="profiling"): + with sentry_sdk.start_span(name="profiling"): assert get_profiler_id() is None, "profiler should not be running" - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="op"): time.sleep(0.05) assert get_profiler_id() is None, "profiler should not be running" @@ -608,8 +608,8 @@ def test_continuous_profiler_run_does_not_null_buffer( # Start and verify profiler works start_profiler() envelopes.clear() - with sentry_sdk.traces.start_span(name="profiling"): - with sentry_sdk.traces.start_span(name="op"): + with sentry_sdk.start_span(name="profiling"): + with sentry_sdk.start_span(name="op"): pass # Get the scheduler and create a sentinel buffer. diff --git a/tests/test_api.py b/tests/test_api.py index dc323731f5..3225233de4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -54,14 +54,14 @@ def test_get_current_span_with_segment(sentry_init): assert sentry_sdk.traces.get_current_span() is None - with sentry_sdk.traces.start_span(name="segment") as new_segment: + with sentry_sdk.start_span(name="segment") as new_segment: assert sentry_sdk.traces.get_current_span() == new_segment def test_traceparent_with_tracing_enabled(sentry_init): sentry_init(traces_sample_rate=1.0) - with sentry_sdk.traces.start_span(name="span") as segment: + with sentry_sdk.start_span(name="span") as segment: expected_traceparent = "%s-%s-1" % ( segment.trace_id, segment.span_id, @@ -97,7 +97,7 @@ def test_baggage_with_tracing_enabled(sentry_init): release="1.0.0", environment="dev", ) - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: expected_baggage_re = r"^sentry-trace_id={},sentry-sample_rand=0\.\d{{6}},sentry-environment=dev,sentry-release=1\.0\.0,sentry-transaction=segment,sentry-sample_rate=1\.0,sentry-sampled={}$".format( segment.trace_id, "true" if segment.sampled else "false" ) @@ -112,7 +112,7 @@ def test_baggage_with_dsn(sentry_init): environment="dev", transport=TestTransportWithOptions, ) - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: expected_baggage_re = r"^sentry-trace_id={},sentry-sample_rand=0\.\d{{6}},sentry-environment=dev,sentry-release=2\.0\.0,sentry-public_key=97333d956c9e40989a0139756c121c34,sentry-transaction=segment,sentry-sample_rate=1\.0,sentry-sampled={}$".format( segment.trace_id, "true" if segment.sampled else "false" ) @@ -131,7 +131,7 @@ def test_continue_trace(sentry_init): "baggage": "sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-sample_rand=0.123456", } ) - with sentry_sdk.traces.start_span(name="some name") as segment: + with sentry_sdk.start_span(name="some name") as segment: assert segment.name == "some name" propagation_context = get_isolation_scope()._propagation_context diff --git a/tests/test_attributes.py b/tests/test_attributes.py index bba1141f33..75e1ecb260 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -204,7 +204,7 @@ def test_user_attributes(sentry_init, capture_items): } ) - with sentry_sdk.traces.start_span(name="login"): + with sentry_sdk.start_span(name="login"): sentry_sdk.metrics.count("test", 1) sentry_sdk.get_client().flush() diff --git a/tests/test_basics.py b/tests/test_basics.py index eb4eb516fe..d34f29e6a8 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -754,7 +754,7 @@ def test_functions_to_trace(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="something"): + with sentry_sdk.start_span(name="something"): time.sleep(0) for word in ["World", "You"]: @@ -797,7 +797,7 @@ def test_functions_to_trace_with_class(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="something"): + with sentry_sdk.start_span(name="something"): wg = WorldGreeter("World") wg.greet() wg.greet("You") @@ -845,7 +845,7 @@ def test_staticmethod_class_tracing(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): assert TracingTestClass.static(1) == 1 sentry_sdk.flush() @@ -870,7 +870,7 @@ def test_staticmethod_instance_tracing(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): assert TracingTestClass().static(1) == 1 sentry_sdk.flush() @@ -894,7 +894,7 @@ def test_classmethod_class_tracing(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): assert TracingTestClass.class_(1) == (TracingTestClass, 1) sentry_sdk.flush() @@ -918,7 +918,7 @@ def test_classmethod_instance_tracing(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): assert TracingTestClass().class_(1) == (TracingTestClass, 1) sentry_sdk.flush() diff --git a/tests/test_dsc.py b/tests/test_dsc.py index 7d61b68850..303fef5ecd 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -31,7 +31,7 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes): envelopes = capture_envelopes() # We start a new segment - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): pass sentry_sdk.flush() @@ -89,7 +89,7 @@ def test_dsc_head_of_trace_uses_custom_org_id(sentry_init, capture_envelopes): envelopes = capture_envelopes() # We start a new segment - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): pass sentry_sdk.flush() @@ -138,7 +138,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes): # We continue the incoming trace and start a new segment sentry_sdk.traces.continue_trace(incoming_http_headers) - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): pass sentry_sdk.flush() @@ -219,7 +219,7 @@ def my_traces_sampler(sampling_context): # We continue the incoming trace and start a new segment with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=125000): sentry_sdk.traces.continue_trace(incoming_http_headers) - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): pass sentry_sdk.flush() @@ -323,7 +323,7 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes): envelopes = capture_envelopes() # We start a new segment and an error occurs - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): try: 1 / 0 except ZeroDivisionError as exp: diff --git a/tests/test_feature_flags.py b/tests/test_feature_flags.py index dd2a353d41..4ba432b2d5 100644 --- a/tests/test_feature_flags.py +++ b/tests/test_feature_flags.py @@ -38,8 +38,8 @@ async def test_featureflags_integration_spans_async(sentry_init, capture_events) add_feature_flag("hello", False) try: - with sentry_sdk.traces.start_span(name="test-span"): - with sentry_sdk.traces.start_span(name="test-span-2"): + with sentry_sdk.start_span(name="test-span"): + with sentry_sdk.start_span(name="test-span-2"): raise ValueError("something wrong!") except ValueError as e: sentry_sdk.capture_exception(e) @@ -66,8 +66,8 @@ def test_featureflags_integration_spans_sync(sentry_init, capture_events): add_feature_flag("hello", False) try: - with sentry_sdk.traces.start_span(name="test-span"): - with sentry_sdk.traces.start_span(name="test-span-2"): + with sentry_sdk.start_span(name="test-span"): + with sentry_sdk.start_span(name="test-span-2"): raise ValueError("something wrong!") except ValueError as e: sentry_sdk.capture_exception(e) diff --git a/tests/test_logs.py b/tests/test_logs.py index 28f7d39046..3db3c9c8d3 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -233,7 +233,7 @@ def test_logs_tied_to_segments(sentry_init, capture_items): sentry_init(traces_sample_rate=1.0) items = capture_items("log") - with sentry_sdk.traces.start_span(name="test-segment") as sgmt: + with sentry_sdk.start_span(name="test-segment") as sgmt: sentry_sdk.logger.warning("This is a log tied to a segment") sentry_sdk.flush() @@ -267,8 +267,8 @@ def test_logs_tied_to_spans(sentry_init, capture_items): sentry_init(traces_sample_rate=1.0) items = capture_items("log") - with sentry_sdk.traces.start_span(name="test-segment"): - with sentry_sdk.traces.start_span(name="test-span") as span: + with sentry_sdk.start_span(name="test-segment"): + with sentry_sdk.start_span(name="test-span") as span: sentry_sdk.logger.warning("This is a log tied to a span") sentry_sdk.flush() diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 140f2e77dc..95388db2b3 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -105,7 +105,7 @@ def test_metrics_with_span(sentry_init, capture_items): sentry_init(traces_sample_rate=1.0) items = capture_items("trace_metric") - with sentry_sdk.traces.start_span(name="test-span") as segment: + with sentry_sdk.start_span(name="test-span") as segment: sentry_sdk.metrics.count("test.span.counter", 1) sentry_sdk.flush() diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 3501fa1e6b..2696dd5c94 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -78,7 +78,7 @@ def test_segment_uses_downsampled_rate( # make sure we don't sample the segment with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=750000): - with sentry_sdk.traces.start_span(name="foobar") as segment: + with sentry_sdk.start_span(name="foobar") as segment: assert segment.sampled is False assert segment._sample_rate == 0.5 diff --git a/tests/test_scope.py b/tests/test_scope.py index cba5b50298..c9e3653577 100644 --- a/tests/test_scope.py +++ b/tests/test_scope.py @@ -90,7 +90,7 @@ def test_set_user_none_values_are_dropped_when_copying_to_attributes( ) items = capture_items("span") - with sentry_sdk.traces.start_span(name="test_segment"): + with sentry_sdk.start_span(name="test_segment"): sentry_sdk.get_isolation_scope().set_user( {"email": "ada@beans.com", "username": None} ) @@ -974,9 +974,9 @@ def test_handle_error_on_token_reset_isolation_scope(error_cls, scope_manager): def test_trace_context_tracing(sentry_init): sentry_init(traces_sample_rate=1.0) - with sentry_sdk.traces.start_span(name="seg") as segment: - with sentry_sdk.traces.start_span(name="span1"): - with sentry_sdk.traces.start_span(name="span2") as span: + with sentry_sdk.start_span(name="seg") as segment: + with sentry_sdk.start_span(name="span1"): + with sentry_sdk.start_span(name="span2") as span: trace_context = sentry_sdk.get_current_scope().get_trace_context() assert trace_context["trace_id"] == segment.trace_id diff --git a/tests/tracing/test_conversation_id.py b/tests/tracing/test_conversation_id.py index 388b3c1654..72cc553e08 100644 --- a/tests/tracing/test_conversation_id.py +++ b/tests/tracing/test_conversation_id.py @@ -11,8 +11,8 @@ def test_conversation_id_propagates_to_span_with_gen_ai_operation_name( scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-op-name-test") - with sentry_sdk.traces.start_span(name="test-sg"): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span(name="test-sg"): + with sentry_sdk.start_span( name="client", attributes={"sentry.op": "http.client"} ) as span: span.set_attribute("gen_ai.operation.name", "chat") @@ -35,8 +35,8 @@ def test_conversation_id_propagates_to_span_with_ai_op(sentry_init, capture_item scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-ai-op-test") - with sentry_sdk.traces.start_span(name="test-tx"): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span(name="test-tx"): + with sentry_sdk.start_span( name="completion", attributes={"sentry.op": "ai.chat.completions"} ): pass @@ -65,8 +65,8 @@ def test_conversation_id_propagates_to_span_with_gen_ai_op( scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-gen-ai-op-test") - with sentry_sdk.traces.start_span(name="test-tx"): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span(name="test-tx"): + with sentry_sdk.start_span( name="invoke", attributes={"sentry.op": "gen_ai.invoke_agent"} ): pass @@ -87,8 +87,8 @@ def test_conversation_id_not_propagated_to_non_ai_span(sentry_init, capture_item scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-should-not-appear") - with sentry_sdk.traces.start_span(name="test-sg"): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span(name="test-sg"): + with sentry_sdk.start_span( name="client", attributes={"sentry.op": "http.client"} ) as span: span.set_attribute("some.other.data", "value") @@ -111,8 +111,8 @@ def test_conversation_id_not_propagated_when_not_set(sentry_init, capture_items) scope = sentry_sdk.get_current_scope() scope.remove_conversation_id() - with sentry_sdk.traces.start_span(name="test-sg"): - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span(name="test-sg"): + with sentry_sdk.start_span( name="completion", attributes={"sentry.op": "ai.chat.completions"} ): pass @@ -135,8 +135,8 @@ def test_conversation_id_not_propagated_to_span_without_op(sentry_init, capture_ scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-no-op-test") - with sentry_sdk.traces.start_span(name="test-sg"): - with sentry_sdk.traces.start_span(name="unnamed-span") as span: + with sentry_sdk.start_span(name="test-sg"): + with sentry_sdk.start_span(name="unnamed-span") as span: span.set_attribute("regular.data", "value") sentry_sdk.flush() @@ -159,8 +159,8 @@ def test_conversation_id_propagates_with_gen_ai_operation_name_no_op( scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-no-op-but-data-test") - with sentry_sdk.traces.start_span(name="test-sg"): - with sentry_sdk.traces.start_span(name="unnamed-span") as span: + with sentry_sdk.start_span(name="test-sg"): + with sentry_sdk.start_span(name="unnamed-span") as span: span.set_attribute("gen_ai.operation.name", "embedding") sentry_sdk.flush() @@ -183,7 +183,7 @@ def test_conversation_id_propagates_to_segment_with_ai_op(sentry_init, capture_i scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-tx-ai-op-test") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="AI Workflow", attributes={"sentry.op": "ai.workflow"} ): pass @@ -202,7 +202,7 @@ def test_conversation_id_not_propagated_to_non_ai_segment(sentry_init, capture_i scope = sentry_sdk.get_current_scope() scope.set_conversation_id("conv-tx-should-not-appear") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="HTTP Request", attributes={"sentry.op": "http.server"} ): pass diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index 79cdf3a706..6ad316c36d 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -75,7 +75,7 @@ def test_trace_decorator_inactive(sentry_init, capture_items): @sentry_sdk.traces.trace(name="outer", active=False) def traced_function(): - with sentry_sdk.traces.start_span(name="inner"): + with sentry_sdk.start_span(name="inner"): return "ok" result = traced_function() @@ -159,7 +159,7 @@ async def test_trace_decorator_async_inactive(sentry_init, capture_items): @sentry_sdk.traces.trace(name="outer", active=False) async def traced_function(): - with sentry_sdk.traces.start_span(name="inner"): + with sentry_sdk.start_span(name="inner"): return "ok" result = await traced_function() @@ -189,7 +189,7 @@ def test_trace_decorator_child(sentry_init, capture_items): def _some_function_traced_stream(a, b, c): return True - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: result = _some_function_traced_stream(1, 2, 3) assert result is True @@ -221,7 +221,7 @@ async def test_trace_decorator_async_child(sentry_init, capture_items): async def _some_function_traced_stream(a, b, c): return True - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: result = await _some_function_traced_stream(1, 2, 3) assert result is True diff --git a/tests/tracing/test_http_headers.py b/tests/tracing/test_http_headers.py index 8dd92fd2da..7fa8edbf44 100644 --- a/tests/tracing/test_http_headers.py +++ b/tests/tracing/test_http_headers.py @@ -13,7 +13,7 @@ def test_to_traceparent(sentry_init, traces_sample_rate): traces_sample_rate=traces_sample_rate, ) - with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span: + with sentry_sdk.start_span(name="/interactions/other-dogs/new-dog") as span: traceparent = sentry_sdk.get_traceparent() parts = traceparent.split("-") @@ -76,7 +76,7 @@ def test_iter_headers(sentry_init, monkeypatch): mock.Mock(return_value="12312012123120121231201212312012-0415201309082013-0"), ) - with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span: + with sentry_sdk.start_span(name="/interactions/other-dogs/new-dog") as span: headers = dict(span._iter_headers()) assert ( headers["sentry-trace"] diff --git a/tests/tracing/test_integration_tests.py b/tests/tracing/test_integration_tests.py index f23f572069..2e727953d0 100644 --- a/tests/tracing/test_integration_tests.py +++ b/tests/tracing/test_integration_tests.py @@ -17,12 +17,12 @@ def test_basic(sentry_init, capture_items, sample_rate): sentry_init(traces_sample_rate=sample_rate) items = capture_items() - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): with pytest.raises(ZeroDivisionError): - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): 1 / 0 - with sentry_sdk.traces.start_span(name="bar"): + with sentry_sdk.start_span(name="bar"): pass sentry_sdk.flush() @@ -51,7 +51,7 @@ def test_error_event_linked_without_performance(sentry_init, capture_items): sentry_init(traces_sample_rate=None) items = capture_items("event") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="no-op span", attributes={"sentry.segment.name.source": "custom segment source"}, ): @@ -106,7 +106,7 @@ def test_continue_trace(sentry_init, capture_items, parent_sampled, sample_rate) sentry_sdk.traces.continue_trace(headers) # child segment, to prove that we can read 'sentry-trace' header data correctly - with sentry_sdk.traces.start_span(name="WRONG") as child_segment: + with sentry_sdk.start_span(name="WRONG") as child_segment: assert child_segment is not None assert child_segment._parent_sampled == parent_sampled assert child_segment.trace_id == trace_id @@ -199,11 +199,11 @@ def test_dynamic_sampling_head_sdk_creates_dsc( # make sure segment is sampled for both cases with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000): sentry_sdk.traces.new_trace() - with sentry_sdk.traces.start_span(name="Head SDK segment") as segment: + with sentry_sdk.start_span(name="Head SDK segment") as segment: baggage = segment._baggage assert baggage is None - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): pass sentry_sdk.flush() @@ -257,9 +257,9 @@ def test_memory_usage(sentry_init, capture_events, args): references = weakref.WeakSet() - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): for i in range(100): - with sentry_sdk.traces.start_span(name=f"hi {i}") as span: + with sentry_sdk.start_span(name=f"hi {i}") as span: def foo(): pass @@ -288,7 +288,7 @@ def before_send(event, hint): ) items = capture_items() - with sentry_sdk.traces.start_span(name="/"): + with sentry_sdk.start_span(name="/"): pass sentry_sdk.flush() @@ -299,12 +299,12 @@ def before_send(event, hint): def test_start_span_after_finish(sentry_init, capture_items): class CustomTransport(Transport): def capture_envelope(self, envelope): - with sentry_sdk.traces.start_span(name="toolate"): + with sentry_sdk.start_span(name="toolate"): pass sentry_sdk.flush() def capture_event(self, event): - with sentry_sdk.traces.start_span(name="justdont"): + with sentry_sdk.start_span(name="justdont"): pass sentry_sdk.flush() @@ -314,7 +314,7 @@ def capture_event(self, event): ) items = capture_items() - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): pass sentry_sdk.flush() @@ -333,8 +333,8 @@ def test_trace_propagation_meta_head_sdk(sentry_init): meta = None span = None - with sentry_sdk.traces.start_span(name="Head SDK segment") as segment: - with sentry_sdk.traces.start_span(name="foo") as current_span: + with sentry_sdk.start_span(name="Head SDK segment") as segment: + with sentry_sdk.start_span(name="foo") as current_span: span = current_span meta = sentry_sdk.get_current_scope().trace_propagation_meta() @@ -362,9 +362,9 @@ def test_non_error_exceptions( sentry_init(traces_sample_rate=1.0) items = capture_items() - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): with pytest.raises(exception_cls): - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): raise exception_cls(exception_value) sentry_sdk.flush() @@ -381,9 +381,9 @@ def test_good_sysexit_doesnt_fail_segment(sentry_init, capture_items, exception_ sentry_init(traces_sample_rate=1.0) items = capture_items() - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): with pytest.raises(SystemExit): - with sentry_sdk.traces.start_span(name="foo"): + with sentry_sdk.start_span(name="foo"): if exception_value is not False: sys.exit(exception_value) else: @@ -440,7 +440,7 @@ def test_continue_trace_strict_trace_continuation( sentry_sdk.traces.continue_trace(headers) - with sentry_sdk.traces.start_span(name="strict trace") as segment: + with sentry_sdk.start_span(name="strict trace") as segment: headers = sentry_sdk.get_current_scope().iter_trace_propagation_headers(segment) if should_continue_trace: @@ -462,11 +462,11 @@ def test_continue_trace_forces_new_traces_when_no_propagation( sentry_init(traces_sample_rate=1.0) sentry_sdk.traces.continue_trace({}) - with sentry_sdk.traces.start_span(name="segment1") as segment1: + with sentry_sdk.start_span(name="segment1") as segment1: pass sentry_sdk.traces.continue_trace({}) - with sentry_sdk.traces.start_span(name="segment2") as segment2: + with sentry_sdk.start_span(name="segment2") as segment2: pass assert segment1.trace_id != segment2.trace_id @@ -478,11 +478,11 @@ def test_continue_trace_forces_new_traces_when_no_propagation_with_new_trace( sentry_init(traces_sample_rate=1.0) sentry_sdk.traces.new_trace() - with sentry_sdk.traces.start_span(name="segment1") as segment1: + with sentry_sdk.start_span(name="segment1") as segment1: pass sentry_sdk.traces.new_trace() - with sentry_sdk.traces.start_span(name="segment2") as segment2: + with sentry_sdk.start_span(name="segment2") as segment2: pass assert segment1.trace_id != segment2.trace_id diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index cf77da5dd3..7c38828627 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -14,7 +14,7 @@ def test_finds_segment_on_scope(sentry_init): traces_sample_rate=1.0, ) - with sentry_sdk.traces.start_span(name="dogpark"): + with sentry_sdk.start_span(name="dogpark"): scope = sentry_sdk.get_current_scope() assert scope.span is not None assert isinstance(scope.span, Span) @@ -30,8 +30,8 @@ def test_finds_span_on_scope(sentry_init): traces_sample_rate=1.0, ) - segment = sentry_sdk.traces.start_span(name="dogpark") - sentry_sdk.traces.start_span(name="sniffing", parent_span=segment) + segment = sentry_sdk.start_span(name="dogpark") + sentry_sdk.start_span(name="sniffing", parent_span=segment) scope = sentry_sdk.get_current_scope() @@ -120,7 +120,7 @@ def test_start_span_segment_updates_scope_name(sentry_init): scope = sentry_sdk.get_current_scope() - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="foobar", attributes={"sentry.segment.name.source": "test"} ): assert scope._transaction == "foobar" diff --git a/tests/tracing/test_propagation.py b/tests/tracing/test_propagation.py index 378610564a..6ef1697f1a 100644 --- a/tests/tracing/test_propagation.py +++ b/tests/tracing/test_propagation.py @@ -4,8 +4,8 @@ def test_span_in_segment(sentry_init): sentry_init(traces_sample_rate=1.0) - with sentry_sdk.traces.start_span(name="test"): - with sentry_sdk.traces.start_span(name="test2") as span: + with sentry_sdk.start_span(name="test"): + with sentry_sdk.start_span(name="test2") as span: # Ensure the headers are there next(span._iter_headers()) @@ -13,8 +13,8 @@ def test_span_in_segment(sentry_init): def test_span_in_span_in_segment(sentry_init): sentry_init(traces_sample_rate=1.0) - with sentry_sdk.traces.start_span(name="test"): - with sentry_sdk.traces.start_span(name="test2"): - with sentry_sdk.traces.start_span(name="test3") as span_inner: + with sentry_sdk.start_span(name="test"): + with sentry_sdk.start_span(name="test2"): + with sentry_sdk.start_span(name="test3") as span_inner: # Ensure the headers are there next(span_inner._iter_headers()) diff --git a/tests/tracing/test_sample_rand.py b/tests/tracing/test_sample_rand.py index f2bdff629b..62c6bd4c26 100644 --- a/tests/tracing/test_sample_rand.py +++ b/tests/tracing/test_sample_rand.py @@ -34,7 +34,7 @@ def test_deterministic_sampled(sentry_init, capture_items, sample_rate, sample_r "sentry_sdk.tracing_utils.Random.randrange", return_value=int(sample_rand * 1000000), ): - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert ( span._get_baggage().sentry_items["sample_rand"] == f"{sample_rand:.6f}" # noqa: E231 ) @@ -65,7 +65,7 @@ def test_segment_uses_incoming_sample_rand( } ) - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert ( span._get_baggage().sentry_items["sample_rand"] == f"{sample_rand:.6f}" # noqa: E231 ) diff --git a/tests/tracing/test_sample_rand_propagation.py b/tests/tracing/test_sample_rand_propagation.py index 56a087e0ee..792ff0e3dd 100644 --- a/tests/tracing/test_sample_rand_propagation.py +++ b/tests/tracing/test_sample_rand_propagation.py @@ -24,7 +24,7 @@ def test_continue_trace_with_sample_rand(sentry_init): } sentry_sdk.traces.continue_trace(headers) - with sentry_sdk.traces.start_span(name="span") as segment: + with sentry_sdk.start_span(name="span") as segment: assert segment._get_baggage().sentry_items["sample_rand"] == "0.100000" @@ -44,5 +44,5 @@ def test_continue_trace_missing_sample_rand(sentry_init): "sentry_sdk.tracing_utils.Random.randrange", Mock(return_value=500000) ): sentry_sdk.traces.continue_trace(headers) - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert span._get_baggage().sentry_items["sample_rand"] == "0.500000" diff --git a/tests/tracing/test_sampling.py b/tests/tracing/test_sampling.py index dbbde25e63..d0de184476 100644 --- a/tests/tracing/test_sampling.py +++ b/tests/tracing/test_sampling.py @@ -14,10 +14,10 @@ def test_sampling_decided_only_for_segments(sentry_init, capture_events): traces_sample_rate=0.5, ) - with sentry_sdk.traces.start_span(name="hi") as segment: + with sentry_sdk.start_span(name="hi") as segment: assert segment.sampled is not None - with sentry_sdk.traces.start_span(name="hey") as span: + with sentry_sdk.start_span(name="hey") as span: assert span.sampled == segment.sampled @@ -30,7 +30,7 @@ def test_no_double_sampling(sentry_init, capture_items): ) items = capture_items() - with sentry_sdk.traces.start_span(name="/"): + with sentry_sdk.start_span(name="/"): pass sentry_sdk.flush() @@ -50,9 +50,9 @@ def test_get_span_from_scope_regardless_of_sampling_decision( } ) - with sentry_sdk.traces.start_span(name="/"): - with sentry_sdk.traces.start_span(name="child-span"): - with sentry_sdk.traces.start_span(name="child-child-span"): + with sentry_sdk.start_span(name="/"): + with sentry_sdk.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-child-span"): scope = sentry_sdk.get_current_scope() if sampling_decision is True: assert scope.span.name == "child-child-span" @@ -82,7 +82,7 @@ def test_uses_traces_sample_rate_correctly( } ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is expected_decision @@ -106,7 +106,7 @@ def test_uses_traces_sampler_return_value_correctly( } ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is expected_decision @@ -118,7 +118,7 @@ def test_tolerates_traces_sampler_returning_a_boolean( traces_sampler=mock.Mock(return_value=traces_sampler_return_value), ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is traces_sampler_return_value @@ -139,7 +139,7 @@ def test_traces_sampler_raising_falls_back_to_parent_sampling_decision( } ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is parent_sampling_decision @@ -164,7 +164,7 @@ def test_traces_sampler_raising_falls_back_to_traces_sample_rate( } ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is expected_decision @@ -188,7 +188,7 @@ def test_traces_sampler_raising_no_incoming_trace_falls_back_to_traces_sample_ra "sentry_sdk.tracing_utils._generate_sample_rand", lambda *a, **kw: 0.5 ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is expected_decision @@ -199,7 +199,7 @@ def test_traces_sampler_raising_no_incoming_trace_and_no_traces_sample_rate( traces_sampler=mock.Mock(side_effect=ValueError("boom")), ) - with sentry_sdk.traces.start_span(name="dogpark") as span: + with sentry_sdk.start_span(name="dogpark") as span: assert span.sampled is False @@ -214,7 +214,7 @@ def test_only_captures_segment_when_sampled_is_true( ) items = capture_items() - span = sentry_sdk.traces.start_span(name="dogpark") + span = sentry_sdk.start_span(name="dogpark") span.end() sentry_sdk.flush() @@ -238,7 +238,7 @@ def test_prefers_traces_sampler_to_traces_sample_rate( traces_sampler=traces_sampler, ) - span = sentry_sdk.traces.start_span(name="dogpark") + span = sentry_sdk.start_span(name="dogpark") assert traces_sampler.called is True assert span.sampled is traces_sampler_return_value @@ -259,7 +259,7 @@ def test_ignores_inherited_sample_decision_when_traces_sampler_defined( "sentry-trace": f"0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-{parent_sampling_decision}" } ) - span = sentry_sdk.traces.start_span(name="dogpark") + span = sentry_sdk.start_span(name="dogpark") assert span.sampled is not bool(int(parent_sampling_decision)) @@ -282,7 +282,7 @@ def test_inherits_parent_sampling_decision_when_traces_sampler_undefined( # precedence mock_random_value = 0.25 if parent_sampling_decision == "0" else 0.75 with mock.patch.object(random, "random", return_value=mock_random_value): - span = sentry_sdk.traces.start_span(name="dogpark") + span = sentry_sdk.start_span(name="dogpark") assert span.sampled is bool(int(parent_sampling_decision)) @@ -309,7 +309,7 @@ def traces_sampler(sampling_context): } ) - with sentry_sdk.traces.start_span(name="span"): + with sentry_sdk.start_span(name="span"): ... @@ -329,14 +329,14 @@ def traces_sampler(sampling_context): sentry_sdk.get_current_scope().set_custom_sampling_context({"custom_value": 1}) - with sentry_sdk.traces.start_span(name="span", attributes={"first": True}): + with sentry_sdk.start_span(name="span", attributes={"first": True}): ... sentry_sdk.traces.new_trace() sentry_sdk.get_current_scope().set_custom_sampling_context({"custom_value": 2}) - with sentry_sdk.traces.start_span(name="span", attributes={"first": False}): + with sentry_sdk.start_span(name="span", attributes={"first": False}): ... @@ -372,7 +372,7 @@ def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value( ) with mock.patch.object(logger, "warning", mock.Mock()): - span = sentry_sdk.traces.start_span(name="dogpark") + span = sentry_sdk.start_span(name="dogpark") logger.warning.assert_any_call(StringContaining("Given sample rate is invalid")) assert span.sampled is False @@ -399,7 +399,7 @@ def test_records_lost_event_only_if_traces_sample_rate_enabled( sentry_init(traces_sample_rate=traces_sample_rate) record_lost_event_calls = capture_record_lost_event_calls() - span = sentry_sdk.traces.start_span(name="dogpark") + span = sentry_sdk.start_span(name="dogpark") assert span.sampled is sampled_output span.end() @@ -429,7 +429,7 @@ def test_records_lost_event_only_if_traces_sampler_enabled( sentry_init(traces_sampler=traces_sampler) record_lost_event_calls = capture_record_lost_event_calls() - segment = sentry_sdk.traces.start_span(name="dogpark") + segment = sentry_sdk.start_span(name="dogpark") assert segment.sampled is sampled_output segment.end() @@ -447,10 +447,10 @@ def test_unsampled_spans_produce_client_report_if_traces_sample_rate_defined( items = capture_items("span") record_lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="segment"): - with sentry_sdk.traces.start_span(name="child1"): + with sentry_sdk.start_span(name="segment"): + with sentry_sdk.start_span(name="child1"): pass - with sentry_sdk.traces.start_span(name="child2"): + with sentry_sdk.start_span(name="child2"): pass sentry_sdk.get_client().flush() @@ -475,10 +475,10 @@ def test_unsampled_spans_produce_client_report_if_traces_sampler_defined( items = capture_items("span") record_lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="segment"): - with sentry_sdk.traces.start_span(name="child1"): + with sentry_sdk.start_span(name="segment"): + with sentry_sdk.start_span(name="child1"): pass - with sentry_sdk.traces.start_span(name="child2"): + with sentry_sdk.start_span(name="child2"): pass sentry_sdk.get_client().flush() @@ -503,10 +503,10 @@ def test_no_client_reports_if_tracing_is_off( items = capture_items("span") record_lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="segment"): - with sentry_sdk.traces.start_span(name="child1"): + with sentry_sdk.start_span(name="segment"): + with sentry_sdk.start_span(name="child1"): pass - with sentry_sdk.traces.start_span(name="child2"): + with sentry_sdk.start_span(name="child2"): pass sentry_sdk.get_client().flush() diff --git a/tests/tracing/test_span_batcher.py b/tests/tracing/test_span_batcher.py index 9ea62d4495..e3901ccfc6 100644 --- a/tests/tracing/test_span_batcher.py +++ b/tests/tracing/test_span_batcher.py @@ -20,23 +20,19 @@ def test_envelope_by_trace_id(sentry_init, capture_envelopes, monkeypatch): with sentry_sdk.new_scope(): sentry_sdk.traces.new_trace() # Keep parent open as its bucket in the batcher would be emptied when it is finished. - parent_a = sentry_sdk.traces.start_span(name="parent a") - with sentry_sdk.traces.start_span( - name="span 1a", parent_span=parent_a - ) as span1: + parent_a = sentry_sdk.start_span(name="parent a") + with sentry_sdk.start_span(name="span 1a", parent_span=parent_a) as span1: trace_id1 = span1.trace_id - with sentry_sdk.traces.start_span(name="span 1b", parent_span=parent_a): + with sentry_sdk.start_span(name="span 1b", parent_span=parent_a): pass with sentry_sdk.new_scope(): sentry_sdk.traces.new_trace() - parent_b = sentry_sdk.traces.start_span(name="parent b") + parent_b = sentry_sdk.start_span(name="parent b") # Keep parent open as its bucket in the batcher would be emptied when it is finished. - with sentry_sdk.traces.start_span( - name="span 2a", parent_span=parent_b - ) as span2: + with sentry_sdk.start_span(name="span 2a", parent_span=parent_b) as span2: trace_id2 = span2.trace_id - with sentry_sdk.traces.start_span(name="span 2b", parent_span=parent_b): + with sentry_sdk.start_span(name="span 2b", parent_span=parent_b): pass sentry_sdk.flush() @@ -71,16 +67,16 @@ def test_max_envelope_size(sentry_init, capture_envelopes, monkeypatch): envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="span 1"): + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="span 1"): pass - with sentry_sdk.traces.start_span(name="span 2"): + with sentry_sdk.start_span(name="span 2"): pass - with sentry_sdk.traces.start_span(name="span 3"): + with sentry_sdk.start_span(name="span 3"): pass - with sentry_sdk.traces.start_span(name="span 4"): + with sentry_sdk.start_span(name="span 4"): pass - with sentry_sdk.traces.start_span(name="span 5"): + with sentry_sdk.start_span(name="span 5"): pass sentry_sdk.flush() @@ -113,12 +109,12 @@ def test_drop_after_max_reached( envelopes = capture_envelopes() record_lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="span 1"): + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="span 1"): pass - with sentry_sdk.traces.start_span(name="span 2"): + with sentry_sdk.start_span(name="span 2"): pass - with sentry_sdk.traces.start_span(name="span 3"): + with sentry_sdk.start_span(name="span 3"): pass sentry_sdk.flush() @@ -148,21 +144,21 @@ def test_drop_isolated_per_bucket( with sentry_sdk.new_scope(): # Keep parent open as its bucket in the batcher would be emptied when it is finished. - parent_a = sentry_sdk.traces.start_span(name="parent a") - with sentry_sdk.traces.start_span(name="a1", parent_span=parent_a) as span_a: + parent_a = sentry_sdk.start_span(name="parent a") + with sentry_sdk.start_span(name="a1", parent_span=parent_a) as span_a: trace_id_a = span_a.trace_id - with sentry_sdk.traces.start_span(name="a2", parent_span=parent_a): + with sentry_sdk.start_span(name="a2", parent_span=parent_a): pass - with sentry_sdk.traces.start_span(name="a3"): + with sentry_sdk.start_span(name="a3"): pass with sentry_sdk.new_scope(): sentry_sdk.traces.new_trace() # Keep parent open as its bucket in the batcher would be emptied when it is finished. - parent_b = sentry_sdk.traces.start_span(name="parent b") - with sentry_sdk.traces.start_span(name="b1", parent_span=parent_b) as span_b: + parent_b = sentry_sdk.start_span(name="parent b") + with sentry_sdk.start_span(name="b1", parent_span=parent_b) as span_b: trace_id_b = span_b.trace_id - with sentry_sdk.traces.start_span(name="b2", parent_span=parent_b): + with sentry_sdk.start_span(name="b2", parent_span=parent_b): pass sentry_sdk.flush() @@ -195,8 +191,8 @@ def test_length_based_flushing(sentry_init, capture_items, monkeypatch): items = capture_items("span") - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="span"): + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="span"): pass time.sleep(0.1) @@ -218,8 +214,8 @@ def test_weight_based_flushing(sentry_init, capture_envelopes, monkeypatch): envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="span"): + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="span"): pass time.sleep(0.1) @@ -243,8 +239,8 @@ def test_weight_based_flushing_by_attribute_size( envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="small span") as bare_span: + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="small span") as bare_span: pass bare_span_size = SpanBatcher._estimate_size(bare_span._to_json()) @@ -257,9 +253,7 @@ def test_weight_based_flushing_by_attribute_size( # The first span alone is well under the byte limit, so no flush yet. assert len(envelopes) == 0 - with sentry_sdk.traces.start_span( - name="big span", attributes={"big": big_attr} - ): + with sentry_sdk.start_span(name="big span", attributes={"big": big_attr}): pass time.sleep(0.1) @@ -282,19 +276,19 @@ def test_bucket_recreated_after_flush(sentry_init, capture_envelopes, monkeypatc sentry_sdk.traces.new_trace() - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="span 1") as span1: + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="span 1") as span1: trace_id = span1.trace_id - with sentry_sdk.traces.start_span(name="span 2"): + with sentry_sdk.start_span(name="span 2"): pass time.sleep(0.1) assert len(envelopes) == 1 - with sentry_sdk.traces.start_span(name="span 3"): + with sentry_sdk.start_span(name="span 3"): pass - with sentry_sdk.traces.start_span(name="span 4"): + with sentry_sdk.start_span(name="span 4"): pass time.sleep(0.1) @@ -329,8 +323,8 @@ def test_quiet_buckets_flush_eventually(sentry_init, capture_envelopes, monkeypa envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="custom parent"): - with sentry_sdk.traces.start_span(name="span 1"): + with sentry_sdk.start_span(name="custom parent"): + with sentry_sdk.start_span(name="span 1"): pass time.sleep(0.3) @@ -358,19 +352,19 @@ def test_quiet_buckets_flushed_with_busy_neighbors( with sentry_sdk.new_scope(): # Keep parent open as its bucket in the batcher would be emptied when it is finished. - parent_a = sentry_sdk.traces.start_span(name="parent a") - with sentry_sdk.traces.start_span(name="span 1", parent_span=parent_a) as span1: + parent_a = sentry_sdk.start_span(name="parent a") + with sentry_sdk.start_span(name="span 1", parent_span=parent_a) as span1: trace_id1 = span1.trace_id with sentry_sdk.new_scope(): sentry_sdk.traces.new_trace() # Keep parent open as its bucket in the batcher would be emptied when it is finished. - parent_b = sentry_sdk.traces.start_span(name="parent b") - with sentry_sdk.traces.start_span(name="span 2", parent_span=parent_b) as span2: + parent_b = sentry_sdk.start_span(name="parent b") + with sentry_sdk.start_span(name="span 2", parent_span=parent_b) as span2: trace_id2 = span2.trace_id for i in range(3, 10): - with sentry_sdk.traces.start_span(name=f"span {i}", parent_span=parent_b): + with sentry_sdk.start_span(name=f"span {i}", parent_span=parent_b): pass time.sleep(0.3) @@ -406,7 +400,7 @@ def test_transport_format(sentry_init, capture_envelopes): envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): ... sentry_sdk.get_client().flush() @@ -457,8 +451,8 @@ def test_trace_bucket_flushes_when_segment_ends( sentry_init(traces_sample_rate=1.0) items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment span"): - with sentry_sdk.traces.start_span(name="child"): + with sentry_sdk.start_span(name="segment span"): + with sentry_sdk.start_span(name="child"): pass time.sleep(0.1) diff --git a/tests/tracing/test_span_origin.py b/tests/tracing/test_span_origin.py index c2b8fa2e96..758de8b066 100644 --- a/tests/tracing/test_span_origin.py +++ b/tests/tracing/test_span_origin.py @@ -5,7 +5,7 @@ def test_span_origin_manual(sentry_init, capture_items): sentry_init(traces_sample_rate=1.0) items = capture_items("span") - with sentry_sdk.traces.start_span(name="hi"): + with sentry_sdk.start_span(name="hi"): pass sentry_sdk.flush() @@ -20,12 +20,12 @@ def test_span_origin_custom(sentry_init, capture_items): sentry_init(traces_sample_rate=1.0) items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="hi", attributes={"sentry.origin": "foo.foo2.foo3"} ): pass - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="ho", attributes={"sentry.origin": "baz.baz2.baz3"} ): pass diff --git a/tests/tracing/test_span_streaming.py b/tests/tracing/test_span_streaming.py index ebadefa17d..76837bc9d2 100644 --- a/tests/tracing/test_span_streaming.py +++ b/tests/tracing/test_span_streaming.py @@ -25,9 +25,9 @@ def test_start_span(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: assert segment._is_segment() is True - with sentry_sdk.traces.start_span(name="child") as child: + with sentry_sdk.start_span(name="child") as child: assert child._is_segment() is False assert child._segment == segment @@ -64,8 +64,8 @@ def test_start_span_no_context_manager(sentry_init, capture_items): items = capture_items("span") - segment = sentry_sdk.traces.start_span(name="segment") - child = sentry_sdk.traces.start_span(name="child") + segment = sentry_sdk.start_span(name="segment") + child = sentry_sdk.start_span(name="child") assert child._segment == segment child.end() segment.end() @@ -111,7 +111,7 @@ def traces_sampler(sampling_context): items = capture_items("span") - segment = sentry_sdk.traces.start_span(name="segment") + segment = sentry_sdk.start_span(name="segment") segment.set_attribute("delayed_attribute", 12) segment.end() @@ -132,9 +132,7 @@ def test_start_span_attributes(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span( - name="segment", attributes={"my_attribute": "my_value"} - ): + with sentry_sdk.start_span(name="segment", attributes={"my_attribute": "my_value"}): ... sentry_sdk.get_client().flush() @@ -163,9 +161,7 @@ def traces_sampler(sampling_context): items = capture_items("span") - with sentry_sdk.traces.start_span( - name="segment", attributes={"my_attribute": "my_value"} - ): + with sentry_sdk.start_span(name="segment", attributes={"my_attribute": "my_value"}): ... sentry_sdk.get_client().flush() @@ -203,7 +199,7 @@ def traces_sampler(sampling_context): items = capture_items("span") - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: trace_id = span._trace_id assert received_trace_id == trace_id @@ -232,7 +228,7 @@ def before_send_span(span, hint): items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="span", attributes={ "drop": True, @@ -272,7 +268,7 @@ def before_send_span(span, hint): items = capture_items("span") - with sentry_sdk.traces.start_span(name="span"): + with sentry_sdk.start_span(name="span"): ... sentry_sdk.get_client().flush() @@ -298,7 +294,7 @@ def before_send_span(span, hint): items = capture_items("span") - with sentry_sdk.traces.start_span(name="span"): + with sentry_sdk.start_span(name="span"): ... sentry_sdk.get_client().flush() @@ -329,7 +325,7 @@ def before_send_span(span, hint): items = capture_items("span") - with sentry_sdk.traces.start_span(name="ignored"): + with sentry_sdk.start_span(name="ignored"): ... sentry_sdk.get_client().flush() @@ -355,7 +351,7 @@ def before_send_span(span, hint): items = capture_items("span") - with sentry_sdk.traces.start_span(name="span", attributes={"original": "value"}): + with sentry_sdk.start_span(name="span", attributes={"original": "value"}): ... sentry_sdk.get_client().flush() @@ -378,7 +374,7 @@ def test_span_attributes(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name="segment", attributes={"attribute1": "value"} ) as span: assert span.get_attributes()["attribute1"] == "value" @@ -414,7 +410,7 @@ def test_span_attributes_serialize_early(sentry_init, capture_items): class Class: pass - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: span.set_attributes( { # arrays of different types will be serialized @@ -455,9 +451,9 @@ def traces_sampler(sampling_context): items = capture_items("span") - with sentry_sdk.traces.start_span(name="dropped", attributes={"drop": True}): + with sentry_sdk.start_span(name="dropped", attributes={"drop": True}): ... - with sentry_sdk.traces.start_span(name="retained", attributes={"drop": False}): + with sentry_sdk.start_span(name="retained", attributes={"drop": False}): ... sentry_sdk.get_client().flush() @@ -484,11 +480,11 @@ def traces_sampler(sampling_context): traces_sampler=traces_sampler, ) - with sentry_sdk.traces.start_span(name="segment") as segment: - with sentry_sdk.traces.start_span(name="child1"): + with sentry_sdk.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="child1"): ... - with sentry_sdk.traces.start_span(name="child2"): - with sentry_sdk.traces.start_span(name="child3"): + with sentry_sdk.start_span(name="child2"): + with sentry_sdk.start_span(name="child3"): ... assert traces_sampler_called == 1 @@ -502,9 +498,9 @@ def test_start_inactive_span(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment") as segment: - with sentry_sdk.traces.start_span(name="child1", active=False): - with sentry_sdk.traces.start_span(name="child2"): + with sentry_sdk.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="child1", active=False): + with sentry_sdk.start_span(name="child2"): # Should have segment as parent since child1 is inactive pass @@ -538,9 +534,9 @@ def test_start_span_override_parent(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment") as segment: - with sentry_sdk.traces.start_span(name="child1"): - with sentry_sdk.traces.start_span(name="child2", parent_span=segment): + with sentry_sdk.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="child1"): + with sentry_sdk.start_span(name="child2", parent_span=segment): pass sentry_sdk.get_client().flush() @@ -576,10 +572,10 @@ def test_sibling_segments(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment1"): + with sentry_sdk.start_span(name="segment1"): ... - with sentry_sdk.traces.start_span(name="segment2"): + with sentry_sdk.start_span(name="segment2"): ... sentry_sdk.get_client().flush() @@ -608,12 +604,12 @@ def test_sibling_segments_new_trace(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment1"): + with sentry_sdk.start_span(name="segment1"): ... sentry_sdk.traces.new_trace() - with sentry_sdk.traces.start_span(name="segment2"): + with sentry_sdk.start_span(name="segment2"): ... sentry_sdk.get_client().flush() @@ -654,7 +650,7 @@ def test_continue_trace_sampled(sentry_init, capture_items): } ) - with sentry_sdk.traces.start_span(name="segment") as span: + with sentry_sdk.start_span(name="segment") as span: ... assert span.sampled is True @@ -693,7 +689,7 @@ def test_continue_trace_unsampled(sentry_init, capture_items): } ) - with sentry_sdk.traces.start_span(name="segment") as span: + with sentry_sdk.start_span(name="segment") as span: ... assert span.sampled is False @@ -746,7 +742,7 @@ def test_backpressure_outcome( } ) - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: pass sentry_sdk.get_client().flush() @@ -788,7 +784,7 @@ def test_continue_trace_no_sample_rand(sentry_init, capture_items): } ) - with sentry_sdk.traces.start_span(name="segment") as span: + with sentry_sdk.start_span(name="segment") as span: ... assert span.sampled is True @@ -831,7 +827,7 @@ def test_outgoing_traceparent_and_baggage_head_sdk(sentry_init, traces_sample_ra sentry_sdk.traces.new_trace() - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert span.sampled is expected_sampled trace_id = span.trace_id @@ -930,7 +926,7 @@ def test_outgoing_traceparent_and_baggage_incoming_trace( } ) - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert span.sampled is parent_sampled traceparent = sentry_sdk.get_traceparent() @@ -996,7 +992,7 @@ def test_outgoing_traceparent_and_baggage_inconsistent_incoming_trace( } ) - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert span.sampled is False traceparent = sentry_sdk.get_traceparent() @@ -1052,7 +1048,7 @@ def test_outgoing_traceparent_and_baggage_incoming_trace_deferred( } ) - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: assert span.sampled is expected_sampled traceparent = sentry_sdk.get_traceparent() @@ -1108,7 +1104,7 @@ def test_outgoing_traceparent_and_baggage_ignored_segment(sentry_init): } ) - with sentry_sdk.traces.start_span(name="ignored") as span: + with sentry_sdk.start_span(name="ignored") as span: assert span.sampled is False traceparent = sentry_sdk.get_traceparent() @@ -1145,10 +1141,10 @@ def test_outgoing_traceparent_and_baggage_ignored_child_span(sentry_init): } ) - with sentry_sdk.traces.start_span(name="span") as segment: + with sentry_sdk.start_span(name="span") as segment: assert segment.sampled is True - with sentry_sdk.traces.start_span(name="ignored") as child: + with sentry_sdk.start_span(name="ignored") as child: assert child.sampled is False traceparent = sentry_sdk.get_traceparent() @@ -1170,10 +1166,10 @@ def test_set_span_status(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: span.status = SpanStatus.ERROR - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: span.status = "error" sentry_sdk.get_client().flush() @@ -1194,7 +1190,7 @@ def test_set_span_status_on_error(sentry_init, capture_items): items = capture_items("span") with pytest.raises(ValueError): - with sentry_sdk.traces.start_span(name="span") as span: + with sentry_sdk.start_span(name="span") as span: raise ValueError("oh no!") sentry_sdk.get_client().flush() @@ -1214,7 +1210,7 @@ def test_set_span_status_on_ignored_span(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="ignored") as span: + with sentry_sdk.start_span(name="ignored") as span: span.status = "error" sentry_sdk.get_client().flush() @@ -1312,10 +1308,10 @@ def test_ignore_spans_basic( items = capture_items("span") lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="ignored") as ignored_span: + with sentry_sdk.start_span(name="ignored") as ignored_span: assert ignored_span.sampled is False - with sentry_sdk.traces.start_span(name="not ignored") as span: + with sentry_sdk.start_span(name="not ignored") as span: assert span.sampled is True sentry_sdk.get_client().flush() @@ -1343,15 +1339,15 @@ def test_ignore_spans_ignored_segment_drops_whole_tree( items = capture_items("span") lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="ignored") as ignored_span: + with sentry_sdk.start_span(name="ignored") as ignored_span: assert ignored_span.sampled is False assert isinstance(ignored_span, NoOpSpan) - with sentry_sdk.traces.start_span(name="not ignored") as span1: + with sentry_sdk.start_span(name="not ignored") as span1: assert span1.sampled is False assert isinstance(span1, NoOpSpan) - with sentry_sdk.traces.start_span(name="not ignored") as span2: + with sentry_sdk.start_span(name="not ignored") as span2: assert span2.sampled is False assert isinstance(span2, NoOpSpan) @@ -1377,15 +1373,15 @@ def test_ignore_spans_ignored_segment_drops_whole_tree_explicit_parent_span( items = capture_items("span") lost_event_calls = capture_record_lost_event_calls() - ignored_span = sentry_sdk.traces.start_span(name="ignored") + ignored_span = sentry_sdk.start_span(name="ignored") assert isinstance(ignored_span, NoOpSpan) assert ignored_span.sampled is False - span1 = sentry_sdk.traces.start_span(name="not ignored 1", parent_span=ignored_span) + span1 = sentry_sdk.start_span(name="not ignored 1", parent_span=ignored_span) assert isinstance(span1, NoOpSpan) assert span1.sampled is False - span2 = sentry_sdk.traces.start_span(name="not ignored 2", parent_span=ignored_span) + span2 = sentry_sdk.start_span(name="not ignored 2", parent_span=ignored_span) assert isinstance(span2, NoOpSpan) assert span2.sampled is False @@ -1416,16 +1412,16 @@ def test_ignore_spans_set_ignored_child_span_as_parent( items = capture_items("span") lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="segment") as segment: + with sentry_sdk.start_span(name="segment") as segment: assert segment.sampled is True - with sentry_sdk.traces.start_span(name="ignored") as ignored_span1: + with sentry_sdk.start_span(name="ignored") as ignored_span1: assert ignored_span1.sampled is False - with sentry_sdk.traces.start_span(name="ignored") as ignored_span2: + with sentry_sdk.start_span(name="ignored") as ignored_span2: assert ignored_span2.sampled is False - with sentry_sdk.traces.start_span(name="child") as span: + with sentry_sdk.start_span(name="child") as span: assert span.sampled is True assert span._parent_span_id == segment.span_id @@ -1455,22 +1451,20 @@ def test_ignore_spans_set_ignored_child_span_as_parent_explicit_parent_span( items = capture_items("span") lost_event_calls = capture_record_lost_event_calls() - segment = sentry_sdk.traces.start_span(name="segment") + segment = sentry_sdk.start_span(name="segment") assert not isinstance(segment, NoOpSpan) assert segment.sampled is True assert segment._parent_span_id is None - ignored_span1 = sentry_sdk.traces.start_span(name="ignored", parent_span=segment) + ignored_span1 = sentry_sdk.start_span(name="ignored", parent_span=segment) assert isinstance(ignored_span1, NoOpSpan) assert ignored_span1.sampled is False - ignored_span2 = sentry_sdk.traces.start_span( - name="ignored", parent_span=ignored_span1 - ) + ignored_span2 = sentry_sdk.start_span(name="ignored", parent_span=ignored_span1) assert isinstance(ignored_span2, NoOpSpan) assert ignored_span2.sampled is False - span = sentry_sdk.traces.start_span(name="child", parent_span=ignored_span2) + span = sentry_sdk.start_span(name="child", parent_span=ignored_span2) assert not isinstance(span, NoOpSpan) assert span.sampled is True assert span._parent_span_id == segment.span_id @@ -1502,21 +1496,21 @@ def test_ignore_spans_reparenting(sentry_init, capture_items): items = capture_items("span") - with sentry_sdk.traces.start_span(name="segment") as span1: + with sentry_sdk.start_span(name="segment") as span1: assert span1.sampled is True assert span1._parent_span_id is None - with sentry_sdk.traces.start_span(name="ignored") as span2: + with sentry_sdk.start_span(name="ignored") as span2: assert span2.sampled is False - with sentry_sdk.traces.start_span(name="child 1") as span3: + with sentry_sdk.start_span(name="child 1") as span3: assert span3.sampled is True assert span3._parent_span_id == span1.span_id - with sentry_sdk.traces.start_span(name="ignored") as span4: + with sentry_sdk.start_span(name="ignored") as span4: assert span4.sampled is False - with sentry_sdk.traces.start_span(name="child 2") as span5: + with sentry_sdk.start_span(name="child 2") as span5: assert span5.sampled is True assert span5._parent_span_id == span3.span_id @@ -1543,10 +1537,10 @@ def test_ignored_spans_produce_client_report( items = capture_items("span") record_lost_event_calls = capture_record_lost_event_calls() - with sentry_sdk.traces.start_span(name="ignored"): - with sentry_sdk.traces.start_span(name="span1"): + with sentry_sdk.start_span(name="ignored"): + with sentry_sdk.start_span(name="span1"): pass - with sentry_sdk.traces.start_span(name="span2"): + with sentry_sdk.start_span(name="span2"): pass sentry_sdk.get_client().flush() @@ -1578,7 +1572,7 @@ def test_segment_span_has_profiler_id( items = capture_items("span") envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="profiled segment"): + with sentry_sdk.start_span(name="profiled segment"): time.sleep(0.1) sentry_sdk.get_client().flush() @@ -1612,7 +1606,7 @@ def test_segment_span_no_profiler_id_when_unsampled( items = capture_items("span") envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="segment"): + with sentry_sdk.start_span(name="segment"): time.sleep(0.05) sentry_sdk.get_client().flush() @@ -1646,7 +1640,7 @@ def test_profile_stops_when_segment_ends( ) capture_envelopes() - with sentry_sdk.traces.start_span(name="segment") as span: + with sentry_sdk.start_span(name="segment") as span: time.sleep(0.1) assert span._continuous_profile is not None assert span._continuous_profile.active is True @@ -1667,7 +1661,7 @@ def test_default_attributes(sentry_init, capture_envelopes): envelopes = capture_envelopes() - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): ... sentry_sdk.get_client().flush() @@ -1723,7 +1717,7 @@ def test_ignore_spans_top_level( items = capture_items("span") - with sentry_sdk.traces.start_span(name=name, attributes=attributes) as span: + with sentry_sdk.start_span(name=name, attributes=attributes) as span: if ignored: assert span.sampled is False assert isinstance(span, NoOpSpan) From 8de2116c6e262ccec7377b9b22b7bb6de4cdbcd6 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 22 Sep 2026 13:23:52 +0200 Subject: [PATCH 2/3] chore: Use top-level API instead internally --- sentry_sdk/feature_flags.py | 2 +- sentry_sdk/integrations/aiohttp.py | 4 +- sentry_sdk/integrations/aiomysql.py | 2 +- sentry_sdk/integrations/arq.py | 2 +- sentry_sdk/integrations/asgi.py | 4 +- sentry_sdk/integrations/asyncio.py | 2 +- sentry_sdk/integrations/asyncpg.py | 2 +- sentry_sdk/integrations/aws_lambda.py | 2 +- sentry_sdk/integrations/boto3.py | 2 +- sentry_sdk/integrations/celery/__init__.py | 13 +++--- sentry_sdk/integrations/chalice.py | 2 +- sentry_sdk/integrations/clickhouse_driver.py | 2 +- sentry_sdk/integrations/django/__init__.py | 8 ++-- sentry_sdk/integrations/django/asgi.py | 2 +- sentry_sdk/integrations/django/caching.py | 2 +- sentry_sdk/integrations/django/middleware.py | 2 +- .../integrations/django/signals_handlers.py | 2 +- sentry_sdk/integrations/django/tasks.py | 2 +- sentry_sdk/integrations/django/templates.py | 4 +- sentry_sdk/integrations/django/views.py | 6 +-- sentry_sdk/integrations/dramatiq.py | 2 +- sentry_sdk/integrations/fastapi.py | 2 +- sentry_sdk/integrations/gcp.py | 2 +- sentry_sdk/integrations/graphene.py | 2 +- sentry_sdk/integrations/grpc/aio/client.py | 4 +- sentry_sdk/integrations/grpc/aio/server.py | 4 +- sentry_sdk/integrations/grpc/client.py | 4 +- sentry_sdk/integrations/grpc/server.py | 2 +- sentry_sdk/integrations/httpx.py | 4 +- sentry_sdk/integrations/httpx2.py | 4 +- sentry_sdk/integrations/huey.py | 4 +- sentry_sdk/integrations/litestar.py | 6 +-- sentry_sdk/integrations/mistral.py | 4 +- sentry_sdk/integrations/pymongo.py | 2 +- sentry_sdk/integrations/pyreqwest.py | 2 +- sentry_sdk/integrations/ray.py | 4 +- .../integrations/redis/_async_common.py | 4 +- sentry_sdk/integrations/redis/_sync_common.py | 4 +- sentry_sdk/integrations/rq.py | 4 +- sentry_sdk/integrations/rust_tracing.py | 2 +- sentry_sdk/integrations/sanic.py | 2 +- sentry_sdk/integrations/socket.py | 4 +- sentry_sdk/integrations/starlette.py | 6 +-- sentry_sdk/integrations/starlite.py | 2 +- sentry_sdk/integrations/stdlib.py | 8 ++-- sentry_sdk/integrations/strawberry.py | 10 ++--- sentry_sdk/integrations/tornado.py | 2 +- sentry_sdk/integrations/wsgi.py | 2 +- tests/integrations/celery/test_celery.py | 2 +- tests/integrations/httpx/test_httpx.py | 4 +- tests/integrations/httpx2/test_httpx2.py | 4 +- .../openai_agents/test_openai_agents.py | 4 +- .../rust_tracing/test_rust_tracing.py | 40 +++++++++---------- tests/integrations/stdlib/test_httplib.py | 10 ++--- tests/test_api.py | 14 +++---- tests/test_dsc.py | 6 +-- tests/tracing/test_decorator.py | 20 +++++----- tests/tracing/test_integration_tests.py | 16 ++++---- tests/tracing/test_sample_rand.py | 2 +- tests/tracing/test_sample_rand_propagation.py | 4 +- tests/tracing/test_sampling.py | 18 ++++----- tests/tracing/test_span_batcher.py | 12 +++--- tests/tracing/test_span_streaming.py | 22 +++++----- 63 files changed, 170 insertions(+), 177 deletions(-) diff --git a/sentry_sdk/feature_flags.py b/sentry_sdk/feature_flags.py index 6f6ab41b43..1baf21068a 100644 --- a/sentry_sdk/feature_flags.py +++ b/sentry_sdk/feature_flags.py @@ -61,6 +61,6 @@ def add_feature_flag(flag: str, result: bool) -> None: flags = sentry_sdk.get_isolation_scope().flags flags.set(flag, result) - span = sentry_sdk.traces.get_current_span() + span = sentry_sdk.get_current_span() if span is not None: span.set_attribute(f"flag.evaluation.{flag}", result) diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index 0202efc242..50eaaed816 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -130,7 +130,7 @@ async def sentry_app_handle( headers = dict(request.headers) - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) Scope.set_custom_sampling_context({"aiohttp_request": request}) header_attributes: "dict[str, Any]" = {} @@ -385,7 +385,7 @@ async def on_request_start( attributes["url.full"] = url_full breadcrumb["url"] = url_full - if sentry_sdk.traces.get_current_span() is not None: + if sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span(name=span_name, attributes=attributes) if should_propagate_trace(client, str(params.url)): diff --git a/sentry_sdk/integrations/aiomysql.py b/sentry_sdk/integrations/aiomysql.py index fce49ed8ca..687759fcdd 100644 --- a/sentry_sdk/integrations/aiomysql.py +++ b/sentry_sdk/integrations/aiomysql.py @@ -193,7 +193,7 @@ async def _inner(self: "Connection") -> T: message="connect", category="query", data=breadcrumb_data ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await f(self) span_attributes: dict[str, Any] = { diff --git a/sentry_sdk/integrations/arq.py b/sentry_sdk/integrations/arq.py index 95a11a45cc..f028b938fa 100644 --- a/sentry_sdk/integrations/arq.py +++ b/sentry_sdk/integrations/arq.py @@ -77,7 +77,7 @@ async def _sentry_enqueue_job( if client.get_integration(ArqIntegration) is None: return await old_enqueue_job(self, function, *args, **kwargs) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await old_enqueue_job(self, function, *args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 404afd5f60..3214cf4584 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -235,7 +235,7 @@ async def _run_app( if ty in ("http", "websocket"): if ty == "websocket" or method in self.http_methods_to_capture: - sentry_sdk.traces.continue_trace(_get_headers(scope)) + sentry_sdk.continue_trace(_get_headers(scope)) Scope.set_custom_sampling_context({"asgi_scope": scope}) @@ -247,7 +247,7 @@ async def _run_app( ) sentry_scope.get_current_scope()._server_segment_span = span else: - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() Scope.set_custom_sampling_context({"asgi_scope": scope}) diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py index bc38f91617..2443808f23 100644 --- a/sentry_sdk/integrations/asyncio.py +++ b/sentry_sdk/integrations/asyncio.py @@ -148,7 +148,7 @@ async def _task_with_sentry_span_creation() -> "Any": with sentry_sdk.isolation_scope(): span_ctx = nullcontext() - if task_spans and sentry_sdk.traces.get_current_span() is not None: + if task_spans and sentry_sdk.get_current_span() is not None: span_ctx = sentry_sdk.start_span( name=get_name(coro), attributes={ diff --git a/sentry_sdk/integrations/asyncpg.py b/sentry_sdk/integrations/asyncpg.py index 4e9d09659f..f4e7724510 100644 --- a/sentry_sdk/integrations/asyncpg.py +++ b/sentry_sdk/integrations/asyncpg.py @@ -222,7 +222,7 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T": message="connect", category="query", data=span_attributes ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await f(*args, **kwargs) with sentry_sdk.start_span(name="connect", attributes=span_attributes): diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 409c88e181..b28f7315e3 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -213,7 +213,7 @@ def sentry_handler( function_name = aws_context.function_name - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) Scope.set_custom_sampling_context(sampling_context) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/boto3.py b/sentry_sdk/integrations/boto3.py index e32c94e74d..63719b124d 100644 --- a/sentry_sdk/integrations/boto3.py +++ b/sentry_sdk/integrations/boto3.py @@ -85,7 +85,7 @@ def _sentry_request_created( if request.method is not None: breadcrumb[SPANDATA.HTTP_REQUEST_METHOD] = request.method - if sentry_sdk.traces.get_current_span() is not None: + if sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span( name=description, attributes={ diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index d6ef028a81..92ea1a32e1 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -94,7 +94,7 @@ def setup_once() -> None: def _set_status(status: str) -> None: with capture_internal_exceptions(): - span = sentry_sdk.traces.get_current_span() + span = sentry_sdk.get_current_span() if span is not None: span.status = "ok" if status == "ok" else "error" @@ -278,10 +278,7 @@ def apply_async(*args: "Any", **kwargs: "Any") -> "Any": task_started_from_beat = sentry_sdk.get_isolation_scope()._name == "celery-beat" span = None - if ( - not task_started_from_beat - and sentry_sdk.traces.get_current_span() is not None - ): + if not task_started_from_beat and sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span( name=task_name, attributes={ @@ -337,7 +334,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any": # something such as attribute access can fail. with capture_internal_exceptions(): headers = args[3].get("headers") or {} - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) Scope.set_custom_sampling_context(custom_sampling_context) @@ -380,7 +377,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any": return f(*args, **kwargs) try: - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return f(*args, **kwargs) with sentry_sdk.start_span( @@ -516,7 +513,7 @@ def sentry_publish(self: "Producer", *args: "Any", **kwargs: "Any") -> "Any": routing_key = kwargs.get("routing_key") exchange = kwargs.get("exchange") - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return original_publish(self, *args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/chalice.py b/sentry_sdk/integrations/chalice.py index f161d82bfc..cfe2c13634 100644 --- a/sentry_sdk/integrations/chalice.py +++ b/sentry_sdk/integrations/chalice.py @@ -82,7 +82,7 @@ def wrapped_view_function(**function_args: "Any") -> "Any": source=SegmentNameSource.COMPONENT, ) - current_span = sentry_sdk.traces.get_current_span() + current_span = sentry_sdk.get_current_span() segment = None if type(current_span) is Span: # A segment already exists (created by the AWS Lambda diff --git a/sentry_sdk/integrations/clickhouse_driver.py b/sentry_sdk/integrations/clickhouse_driver.py index 7584a31ed2..edbe19850d 100644 --- a/sentry_sdk/integrations/clickhouse_driver.py +++ b/sentry_sdk/integrations/clickhouse_driver.py @@ -80,7 +80,7 @@ def _inner(*args: "P.args", **kwargs: "P.kwargs") -> "T": query = args[1] span = None - if sentry_sdk.traces.get_current_span() is not None: + if sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span( name=query, # type: ignore attributes={ diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index b595b4cfc1..c362277038 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -350,7 +350,7 @@ def sentry_patched_drf_authenticate(self: "Request") -> "Any": if ( integration is None or not getattr(self, "authenticators", None) - or sentry_sdk.traces.get_current_span() is None + or sentry_sdk.get_current_span() is None ): return old_drf_authenticate(self) @@ -831,7 +831,7 @@ def connect(self: "BaseDatabaseWrapper") -> None: with capture_internal_exceptions(): sentry_sdk.add_breadcrumb(message="connect", category="query") - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_connect(self) with sentry_sdk.start_span( name="connect", @@ -849,7 +849,7 @@ def _commit(self: "BaseDatabaseWrapper") -> None: if integration is None or not integration.db_transaction_spans: return real_commit(self) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_commit(self) with sentry_sdk.start_span( @@ -868,7 +868,7 @@ def _rollback(self: "BaseDatabaseWrapper") -> None: if integration is None or not integration.db_transaction_spans: return real_rollback(self) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_rollback(self) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/django/asgi.py b/sentry_sdk/integrations/django/asgi.py index 2904718052..d237c4d946 100644 --- a/sentry_sdk/integrations/django/asgi.py +++ b/sentry_sdk/integrations/django/asgi.py @@ -174,7 +174,7 @@ async def sentry_wrapped_callback( request: "Any", *args: "Any", **kwargs: "Any" ) -> "Any": client = sentry_sdk.get_client() - current_span = sentry_sdk.traces.get_current_span() + current_span = sentry_sdk.get_current_span() if type(current_span) is Span: segment = current_span._segment segment._update_active_thread() diff --git a/sentry_sdk/integrations/django/caching.py b/sentry_sdk/integrations/django/caching.py index cf50ff2f01..24bf8a6c08 100644 --- a/sentry_sdk/integrations/django/caching.py +++ b/sentry_sdk/integrations/django/caching.py @@ -58,7 +58,7 @@ def _instrument_call( op = OP.CACHE_PUT if is_set_operation else OP.CACHE_GET description = _get_span_description(method_name, args, kwargs) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return original_method(*args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/django/middleware.py b/sentry_sdk/integrations/django/middleware.py index 4fc8f831ac..af4ac249e8 100644 --- a/sentry_sdk/integrations/django/middleware.py +++ b/sentry_sdk/integrations/django/middleware.py @@ -76,7 +76,7 @@ def _check_middleware_span( if function_basename: description = "{}.{}".format(description, function_basename) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return None middleware_span = sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/django/signals_handlers.py b/sentry_sdk/integrations/django/signals_handlers.py index 4c5b63853b..bbc76c9b4f 100644 --- a/sentry_sdk/integrations/django/signals_handlers.py +++ b/sentry_sdk/integrations/django/signals_handlers.py @@ -63,7 +63,7 @@ def sentry_sync_receiver_wrapper( def wrapper(*args: "Any", **kwargs: "Any") -> "Any": signal_name = _get_receiver_name(receiver) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return receiver(*args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/django/tasks.py b/sentry_sdk/integrations/django/tasks.py index f9a1b90af9..d1fdc72854 100644 --- a/sentry_sdk/integrations/django/tasks.py +++ b/sentry_sdk/integrations/django/tasks.py @@ -32,7 +32,7 @@ def _sentry_enqueue(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": name = qualname_from_function(self.func) or "" - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_task_enqueue(self, *args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/django/templates.py b/sentry_sdk/integrations/django/templates.py index ee60e872e4..db0efb4c7d 100644 --- a/sentry_sdk/integrations/django/templates.py +++ b/sentry_sdk/integrations/django/templates.py @@ -54,7 +54,7 @@ def patch_templates() -> None: @property # type: ignore @ensure_integration_enabled(DjangoIntegration, real_rendered_content.fget) def rendered_content(self: "SimpleTemplateResponse") -> str: - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_rendered_content.fget(self) with sentry_sdk.start_span( @@ -88,7 +88,7 @@ def render( sentry_sdk.get_current_scope().trace_propagation_meta() ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_render(request, template_name, context, *args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/django/views.py b/sentry_sdk/integrations/django/views.py index 1c362776ff..54833d0ccd 100644 --- a/sentry_sdk/integrations/django/views.py +++ b/sentry_sdk/integrations/django/views.py @@ -21,7 +21,7 @@ def patch_views() -> None: old_render = SimpleTemplateResponse.render def sentry_patched_render(self: "SimpleTemplateResponse") -> "Any": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_render(self) with sentry_sdk.start_span( @@ -62,7 +62,7 @@ def _wrap_sync_view(callback: "Any") -> "Any": def sentry_wrapped_callback(request: "Any", *args: "Any", **kwargs: "Any") -> "Any": client = sentry_sdk.get_client() - current_span = sentry_sdk.traces.get_current_span() + current_span = sentry_sdk.get_current_span() if type(current_span) is Span: segment = current_span._segment segment._update_active_thread() @@ -71,7 +71,7 @@ def sentry_wrapped_callback(request: "Any", *args: "Any", **kwargs: "Any") -> "A if not integration or not integration.middleware_spans: return callback(request, *args, **kwargs) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return callback(request, *args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/dramatiq.py b/sentry_sdk/integrations/dramatiq.py index 9147d871d0..2ac023bb63 100644 --- a/sentry_sdk/integrations/dramatiq.py +++ b/sentry_sdk/integrations/dramatiq.py @@ -138,7 +138,7 @@ def before_process_message(self, broker: "Broker", message: "Message[R]") -> Non scope.set_transaction_name(message.actor_name, source=SegmentNameSource.TASK) - sentry_sdk.traces.continue_trace(sentry_headers) + sentry_sdk.continue_trace(sentry_headers) span = sentry_sdk.start_span( name=message.actor_name, attributes={ diff --git a/sentry_sdk/integrations/fastapi.py b/sentry_sdk/integrations/fastapi.py index cdae8b8ac3..064776d268 100644 --- a/sentry_sdk/integrations/fastapi.py +++ b/sentry_sdk/integrations/fastapi.py @@ -207,7 +207,7 @@ def _sentry_get_request_handler(*args: "Any", **kwargs: "Any") -> "Any": @wraps(old_call) def _sentry_call(*args: "Any", **kwargs: "Any") -> "Any": - current_span = sentry_sdk.traces.get_current_span() + current_span = sentry_sdk.get_current_span() if type(current_span) is Span: segment = current_span._segment diff --git a/sentry_sdk/integrations/gcp.py b/sentry_sdk/integrations/gcp.py index c6504116c8..1b53889a25 100644 --- a/sentry_sdk/integrations/gcp.py +++ b/sentry_sdk/integrations/gcp.py @@ -137,7 +137,7 @@ def sentry_func( if environ.get("ENTRY_POINT"): additional_attributes["faas.entry_point"] = environ.get("ENTRY_POINT") - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) Scope.set_custom_sampling_context(sampling_context) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/graphene.py b/sentry_sdk/integrations/graphene.py index c5b9d84fc0..54a2f4baa3 100644 --- a/sentry_sdk/integrations/graphene.py +++ b/sentry_sdk/integrations/graphene.py @@ -154,7 +154,7 @@ def graphql_span( client_options = sentry_sdk.get_client().options - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: yield return diff --git a/sentry_sdk/integrations/grpc/aio/client.py b/sentry_sdk/integrations/grpc/aio/client.py index b4d79dd985..67f85ef167 100644 --- a/sentry_sdk/integrations/grpc/aio/client.py +++ b/sentry_sdk/integrations/grpc/aio/client.py @@ -49,7 +49,7 @@ async def intercept_unary_unary( ) -> "Union[UnaryUnaryCall, Message]": method = client_call_details.method - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details ) @@ -86,7 +86,7 @@ async def intercept_unary_stream( ) -> "Union[AsyncIterable[Any], UnaryStreamCall]": method = client_call_details.method - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details ) diff --git a/sentry_sdk/integrations/grpc/aio/server.py b/sentry_sdk/integrations/grpc/aio/server.py index 069960f280..153430bd31 100644 --- a/sentry_sdk/integrations/grpc/aio/server.py +++ b/sentry_sdk/integrations/grpc/aio/server.py @@ -53,9 +53,7 @@ async def wrapped(request: "Any", context: "ServicerContext") -> "Any": return await handler(request, context) # What if the headers are empty? - sentry_sdk.traces.continue_trace( - dict(context.invocation_metadata()) - ) + sentry_sdk.continue_trace(dict(context.invocation_metadata())) with sentry_sdk.start_span( name=name, diff --git a/sentry_sdk/integrations/grpc/client.py b/sentry_sdk/integrations/grpc/client.py index 8ce529456c..82e2190f40 100644 --- a/sentry_sdk/integrations/grpc/client.py +++ b/sentry_sdk/integrations/grpc/client.py @@ -30,7 +30,7 @@ def intercept_unary_unary( ) -> "_UnaryOutcome": method = client_call_details.method - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details ) @@ -60,7 +60,7 @@ def intercept_unary_stream( ) -> "Union[Iterator[Message], Call]": method = client_call_details.method - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details ) diff --git a/sentry_sdk/integrations/grpc/server.py b/sentry_sdk/integrations/grpc/server.py index 7bef1da1cd..79b05cb275 100644 --- a/sentry_sdk/integrations/grpc/server.py +++ b/sentry_sdk/integrations/grpc/server.py @@ -46,7 +46,7 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message": if name: metadata = dict(context.invocation_metadata()) - sentry_sdk.traces.continue_trace(metadata) + sentry_sdk.continue_trace(metadata) with sentry_sdk.start_span( name=name, diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index 16781ca1c1..a3a79a67d5 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -61,7 +61,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response": url_attributes = get_url_attributes(client, parsed_url) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: span_ctx = nullcontext() else: span_ctx = sentry_sdk.start_span( @@ -132,7 +132,7 @@ async def send( with capture_internal_exceptions(): parsed_url = parse_url(str(request.url), sanitize=False) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: span_ctx = nullcontext() else: span_ctx = sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/httpx2.py b/sentry_sdk/integrations/httpx2.py index 6f8625a33c..2f382601a3 100644 --- a/sentry_sdk/integrations/httpx2.py +++ b/sentry_sdk/integrations/httpx2.py @@ -61,7 +61,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response": url_attributes = get_url_attributes(client, parsed_url) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: span_ctx = nullcontext() else: span_ctx = sentry_sdk.start_span( @@ -132,7 +132,7 @@ async def send( with capture_internal_exceptions(): parsed_url = parse_url(str(request.url), sanitize=False) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: span_ctx = nullcontext() else: span_ctx = sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index 7693c830c8..7cfbcc2022 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -85,7 +85,7 @@ def _sentry_enqueue( t for t in [HueyGroup, HueyChord] if t is not None ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: if not isinstance(item, no_headers_types): item.kwargs["sentry_headers"] = { BAGGAGE_HEADER_NAME: get_baggage(), @@ -198,7 +198,7 @@ def _sentry_execute( sentry_headers = task.kwargs.pop("sentry_headers", None) headers = sentry_headers or {} - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) span_ctx = sentry_sdk.start_span( name=task.name, attributes={ diff --git a/sentry_sdk/integrations/litestar.py b/sentry_sdk/integrations/litestar.py index 156a489ec1..99e99c1188 100644 --- a/sentry_sdk/integrations/litestar.py +++ b/sentry_sdk/integrations/litestar.py @@ -168,7 +168,7 @@ async def _create_span_call( return await old_call(self, scope, receive, send) middleware_name = self.__class__.__name__ - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await old_call(self, scope, receive, send) with sentry_sdk.start_span( name=middleware_name, @@ -185,7 +185,7 @@ async def _sentry_receive( ) -> "Union[HTTPReceiveMessage, WebSocketReceiveMessage]": if client.get_integration(LitestarIntegration) is None: return await receive(*args, **kwargs) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await receive(*args, **kwargs) with sentry_sdk.start_span( name=getattr(receive, "__qualname__", str(receive)), @@ -205,7 +205,7 @@ async def _sentry_receive( async def _sentry_send(message: "Message") -> None: if client.get_integration(LitestarIntegration) is None: return await send(message) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await send(message) with sentry_sdk.start_span( name=getattr(send, "__qualname__", str(send)), diff --git a/sentry_sdk/integrations/mistral.py b/sentry_sdk/integrations/mistral.py index ba0249046e..a7e6c5a2a2 100644 --- a/sentry_sdk/integrations/mistral.py +++ b/sentry_sdk/integrations/mistral.py @@ -230,7 +230,7 @@ def wrap_complete(self: "Chat", *args: "Any", **kwargs: "Any") -> "Any": model = kwargs.get("model") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"chat {model}" if model is not None else "chat", attributes={ "sentry.op": OP.GEN_AI_CHAT, @@ -358,7 +358,7 @@ async def wrap_complete_async(self: "Chat", *args: "Any", **kwargs: "Any") -> "A model = kwargs.get("model") - with sentry_sdk.traces.start_span( + with sentry_sdk.start_span( name=f"chat {model}" if model is not None else "chat", attributes={ "sentry.op": OP.GEN_AI_CHAT, diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index dd396fec32..2cc9d2663b 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -166,7 +166,7 @@ def started(self, event: "CommandStartedEvent") -> None: data=data, ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return span = sentry_sdk.start_span(name=query, attributes=data) diff --git a/sentry_sdk/integrations/pyreqwest.py b/sentry_sdk/integrations/pyreqwest.py index 9ce47d37ae..4c90414095 100644 --- a/sentry_sdk/integrations/pyreqwest.py +++ b/sentry_sdk/integrations/pyreqwest.py @@ -116,7 +116,7 @@ def _sentry_pyreqwest_span( with capture_internal_exceptions(): parsed_url = parse_url(str(request.url), sanitize=False) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: propagate_trace_headers(client=sentry_sdk.get_client(), request=request) yield None return diff --git a/sentry_sdk/integrations/ray.py b/sentry_sdk/integrations/ray.py index ad201a632f..b7029685c3 100644 --- a/sentry_sdk/integrations/ray.py +++ b/sentry_sdk/integrations/ray.py @@ -89,7 +89,7 @@ def new_func( ) -> "Any": _check_sentry_initialized() - sentry_sdk.traces.continue_trace(_sentry_tracing or {}) + sentry_sdk.continue_trace(_sentry_tracing or {}) function_name = qualname_from_function(user_f) with sentry_sdk.start_span( @@ -126,7 +126,7 @@ def _remote_method_with_header_propagation( """ function_name = qualname_from_function(user_f) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: tracing = { k: v for k, v in sentry_sdk.get_current_scope().iter_trace_propagation_headers() diff --git a/sentry_sdk/integrations/redis/_async_common.py b/sentry_sdk/integrations/redis/_async_common.py index ce6a107b0d..5a70d6a449 100644 --- a/sentry_sdk/integrations/redis/_async_common.py +++ b/sentry_sdk/integrations/redis/_async_common.py @@ -52,7 +52,7 @@ async def _sentry_execute(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": }, ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await old_execute(self, *args, **kwargs) span = sentry_sdk.start_span( @@ -107,7 +107,7 @@ async def _sentry_execute_command( data=breadcrumb_data, ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await old_execute_command(self, name, *args, **kwargs) cache_properties = _compile_cache_span_properties( diff --git a/sentry_sdk/integrations/redis/_sync_common.py b/sentry_sdk/integrations/redis/_sync_common.py index 8f42606f05..2503098661 100644 --- a/sentry_sdk/integrations/redis/_sync_common.py +++ b/sentry_sdk/integrations/redis/_sync_common.py @@ -49,7 +49,7 @@ def sentry_patched_execute(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": }, ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_execute(self, *args, **kwargs) span = sentry_sdk.start_span( @@ -108,7 +108,7 @@ def sentry_patched_execute_command( data=breadcrumb_data, ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_execute_command(self, name, *args, **kwargs) cache_properties = _compile_cache_span_properties( diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index 7e869d0e2c..5098026293 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -73,9 +73,7 @@ def sentry_patched_perform_job( scope.clear_breadcrumbs() scope.add_event_processor(_make_event_processor(weakref.ref(job))) - sentry_sdk.traces.continue_trace( - job.meta.get("_sentry_trace_headers") or {} - ) + sentry_sdk.continue_trace(job.meta.get("_sentry_trace_headers") or {}) Scope.set_custom_sampling_context({"rq_job": job}) diff --git a/sentry_sdk/integrations/rust_tracing.py b/sentry_sdk/integrations/rust_tracing.py index 2018353943..70f8422e2c 100644 --- a/sentry_sdk/integrations/rust_tracing.py +++ b/sentry_sdk/integrations/rust_tracing.py @@ -204,7 +204,7 @@ def on_new_span(self, attrs: str, span_id: str) -> "Optional[Span]": else: sentry_span_name = "" - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return None sentry_span = sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/sanic.py b/sentry_sdk/integrations/sanic.py index bd3968cb85..be536b2a4f 100644 --- a/sentry_sdk/integrations/sanic.py +++ b/sentry_sdk/integrations/sanic.py @@ -132,7 +132,7 @@ async def _context_enter(request: "Request") -> None: scope.clear_breadcrumbs() scope.add_event_processor(_make_request_processor(weak_request)) - sentry_sdk.traces.continue_trace(dict(request.headers)) + sentry_sdk.continue_trace(dict(request.headers)) scope.set_custom_sampling_context({"sanic_request": request}) if request.remote_addr: diff --git a/sentry_sdk/integrations/socket.py b/sentry_sdk/integrations/socket.py index 4c54a32a14..76bce59d4b 100644 --- a/sentry_sdk/integrations/socket.py +++ b/sentry_sdk/integrations/socket.py @@ -55,7 +55,7 @@ def create_connection( if integration is None: return real_create_connection(address, timeout, source_address) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_create_connection(address, timeout, source_address) with sentry_sdk.start_span( @@ -92,7 +92,7 @@ def getaddrinfo( if integration is None: return real_getaddrinfo(host, port, family, type, proto, flags) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return real_getaddrinfo(host, port, family, type, proto, flags) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index 26dd9e22bc..a3ae8d5653 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -179,7 +179,7 @@ async def _create_span_call( middleware_name = app.__class__.__name__ def _start_middleware_span(op: str, name: str) -> "Any": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return nullcontext() return sentry_sdk.start_span( @@ -562,7 +562,7 @@ def event_processor(event: "Event", hint: "Dict[str, Any]") -> "Event": try: return await handler(*args, **kwargs) finally: - current_span = sentry_sdk.traces.get_current_span() + current_span = sentry_sdk.get_current_span() if type(current_span) is Span: attach_request_data = True @@ -607,7 +607,7 @@ def _sentry_sync_func(*args: "Any", **kwargs: "Any") -> "Any": if integration is None: return old_func(*args, **kwargs) - current_span = sentry_sdk.traces.get_current_span() + current_span = sentry_sdk.get_current_span() if type(current_span) is Span: current_span._segment._update_active_thread() diff --git a/sentry_sdk/integrations/starlite.py b/sentry_sdk/integrations/starlite.py index 93cce64aa3..cc5fad4158 100644 --- a/sentry_sdk/integrations/starlite.py +++ b/sentry_sdk/integrations/starlite.py @@ -154,7 +154,7 @@ async def _create_span_call( middleware_name = self.__class__.__name__ def _start_middleware_span(op: str, name: str) -> "Any": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return nullcontext() return sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 45643071ee..fdd544a94d 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -279,7 +279,7 @@ def putrequest( breadcrumb[SPANDATA.HTTP_REQUEST_METHOD] = method breadcrumb.update(url_attributes) - if sentry_sdk.traces.get_current_span() is not None: + if sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span( name="%s %s" % ( @@ -488,7 +488,7 @@ def sentry_patched_popen_init( data={"subprocess.cwd": cwd} if cwd else {}, ) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_popen_init(self, *a, **kw) with sentry_sdk.start_span( @@ -525,7 +525,7 @@ def sentry_patched_popen_init( def sentry_patched_popen_wait( self: "subprocess.Popen[Any]", *a: "Any", **kw: "Any" ) -> "Any": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_popen_wait(self, *a, **kw) with sentry_sdk.start_span( name=OP.SUBPROCESS_WAIT, @@ -545,7 +545,7 @@ def sentry_patched_popen_wait( def sentry_patched_popen_communicate( self: "subprocess.Popen[Any]", *a: "Any", **kw: "Any" ) -> "Any": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return old_popen_communicate(self, *a, **kw) with sentry_sdk.start_span( name=OP.SUBPROCESS_COMMUNICATE, diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index c97d347d1a..da3e2f0b63 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -163,7 +163,7 @@ def on_operation(self) -> "Generator[None, None, None]": client = sentry_sdk.get_client() - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: yield return @@ -201,7 +201,7 @@ def on_operation(self) -> "Generator[None, None, None]": graphql_span.end() def on_validate(self) -> "Generator[None, None, None]": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: yield return @@ -220,7 +220,7 @@ def on_validate(self) -> "Generator[None, None, None]": validation_span.end() def on_parse(self) -> "Generator[None, None, None]": - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: yield return @@ -273,7 +273,7 @@ async def resolve( field_path = "{}.{}".format(info.parent_type, info.field_name) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return await self._resolve(_next, root, info, *args, **kwargs) with sentry_sdk.start_span( @@ -300,7 +300,7 @@ def resolve( field_path = "{}.{}".format(info.parent_type, info.field_name) - if sentry_sdk.traces.get_current_span() is None: + if sentry_sdk.get_current_span() is None: return _next(root, info, *args, **kwargs) with sentry_sdk.start_span( diff --git a/sentry_sdk/integrations/tornado.py b/sentry_sdk/integrations/tornado.py index 020b0d9cdf..0dba1f8e46 100644 --- a/sentry_sdk/integrations/tornado.py +++ b/sentry_sdk/integrations/tornado.py @@ -95,7 +95,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None] processor = _make_event_processor(weak_handler) scope.add_event_processor(processor) - sentry_sdk.traces.continue_trace(dict(headers)) + sentry_sdk.continue_trace(dict(headers)) scope.set_custom_sampling_context({"tornado_request": self.request}) if self.request.remote_ip: diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index a2a9104f89..a4df7d1dc2 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -129,7 +129,7 @@ def __call__( span_ctx: "ContextManager[Union[Span, None]]" = nullcontext() if method in self.http_methods_to_capture: - sentry_sdk.traces.continue_trace(dict(_get_headers(environ))) + sentry_sdk.continue_trace(dict(_get_headers(environ))) Scope.set_custom_sampling_context({"wsgi_environ": environ}) if has_data_collection_enabled(client.options): diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index cd1f3d9063..176b770e65 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -629,7 +629,7 @@ def test_sentry_propagate_traces_override(init_celery): @celery.task(name="dummy_task", bind=True) def dummy_task(self, message): - trace_id = sentry_sdk.traces.get_current_span().trace_id + trace_id = sentry_sdk.get_current_span().trace_id return trace_id with sentry_sdk.start_span(name="parent") as span: diff --git a/tests/integrations/httpx/test_httpx.py b/tests/integrations/httpx/test_httpx.py index a18114729f..9c585fe8fe 100644 --- a/tests/integrations/httpx/test_httpx.py +++ b/tests/integrations/httpx/test_httpx.py @@ -619,7 +619,7 @@ def test_outgoing_trace_headers_no_current_span(sentry_init, httpx_mock): httpx_client = httpx.Client() - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None response = httpx_client.get(url) @@ -655,7 +655,7 @@ async def test_outgoing_trace_headers_no_current_span_async(sentry_init, httpx_m httpx_client = httpx.AsyncClient() - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None response = await httpx_client.get(url) diff --git a/tests/integrations/httpx2/test_httpx2.py b/tests/integrations/httpx2/test_httpx2.py index 191bf61775..2008145bd0 100644 --- a/tests/integrations/httpx2/test_httpx2.py +++ b/tests/integrations/httpx2/test_httpx2.py @@ -619,7 +619,7 @@ def test_outgoing_trace_headers_no_current_span(sentry_init, httpx2_mock): httpx2_client = httpx2.Client() - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None response = httpx2_client.get(url) @@ -655,7 +655,7 @@ async def test_outgoing_trace_headers_no_current_span_async(sentry_init, httpx2_ httpx2_client = httpx2.AsyncClient() - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None response = await httpx2_client.get(url) diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py index a8129c555a..1634b35065 100644 --- a/tests/integrations/openai_agents/test_openai_agents.py +++ b/tests/integrations/openai_agents/test_openai_agents.py @@ -2645,7 +2645,7 @@ async def test_hosted_mcp_tool_propagation_header_streamed( ) as create, mock.patch( "sentry_sdk.tracing_utils.Random.randrange", return_value=500000 ): - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( {"sentry-trace": "01234567890123456789012345678901-0000000000000000"} ) @@ -2747,7 +2747,7 @@ async def test_hosted_mcp_tool_propagation_headers( ) as send, mock.patch( "sentry_sdk.tracing_utils.Random.randrange", return_value=500000 ): - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( {"sentry-trace": "01234567890123456789012345678901-0000000000000000"} ) diff --git a/tests/integrations/rust_tracing/test_rust_tracing.py b/tests/integrations/rust_tracing/test_rust_tracing.py index ff010a241c..a7ecb4cdb8 100644 --- a/tests/integrations/rust_tracing/test_rust_tracing.py +++ b/tests/integrations/rust_tracing/test_rust_tracing.py @@ -81,13 +81,13 @@ def test_on_new_span_on_close( with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) - sentry_first_rust_span = sentry_sdk.traces.get_current_span() + sentry_first_rust_span = sentry_sdk.get_current_span() rust_first_rust_span = rust_tracing.spans[3] assert sentry_first_rust_span == rust_first_rust_span rust_tracing.close_span(3) - assert sentry_sdk.traces.get_current_span() != sentry_first_rust_span + assert sentry_sdk.get_current_span() != sentry_first_rust_span sentry_sdk.flush() spans = [item.payload for item in items] @@ -129,16 +129,16 @@ def test_nested_on_new_span_on_close( ) items = capture_items("span") with sentry_sdk.start_span(name="custom parent"): - original_sentry_span = sentry_sdk.traces.get_current_span() + original_sentry_span = sentry_sdk.get_current_span() rust_tracing.new_span(RustTracingLevel.Info, 3, index_arg=10) - sentry_first_rust_span = sentry_sdk.traces.get_current_span() + sentry_first_rust_span = sentry_sdk.get_current_span() rust_first_rust_span = rust_tracing.spans[3] # Use a different `index_arg` value for the inner span to help # distinguish the two at the end of the test rust_tracing.new_span(RustTracingLevel.Info, 5, index_arg=9) - sentry_second_rust_span = sentry_sdk.traces.get_current_span() + sentry_second_rust_span = sentry_sdk.get_current_span() rust_second_rust_span = rust_tracing.spans[5] assert rust_second_rust_span == sentry_second_rust_span @@ -146,13 +146,13 @@ def test_nested_on_new_span_on_close( rust_tracing.close_span(5) # Ensure the current sentry span was moved back to the parent - sentry_span_after_close = sentry_sdk.traces.get_current_span() + sentry_span_after_close = sentry_sdk.get_current_span() assert sentry_span_after_close == sentry_first_rust_span assert sentry_span_after_close == rust_first_rust_span rust_tracing.close_span(3) - assert sentry_sdk.traces.get_current_span() == original_sentry_span + assert sentry_sdk.get_current_span() == original_sentry_span sentry_sdk.flush() spans = [item.payload for item in items] @@ -201,12 +201,12 @@ def test_on_new_span_without_active_span(sentry_init): traces_sample_rate=1.0, ) - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None # In streaming mode we do not create an orphan root segment when there # is no active span rust_tracing.new_span(RustTracingLevel.Info, 3) - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None def test_on_event_exception( @@ -381,22 +381,22 @@ def span_filter(metadata: Dict[str, object]) -> bool: ) items = capture_items("span") with sentry_sdk.start_span(name="custom parent"): - original_sentry_span = sentry_sdk.traces.get_current_span() + original_sentry_span = sentry_sdk.get_current_span() # Span is not ignored rust_tracing.new_span(RustTracingLevel.Info, 3, index_arg=10) - info_span = sentry_sdk.traces.get_current_span() + info_span = sentry_sdk.get_current_span() # Span is ignored, current span should remain the same rust_tracing.new_span(RustTracingLevel.Trace, 5, index_arg=9) - assert sentry_sdk.traces.get_current_span() == info_span + assert sentry_sdk.get_current_span() == info_span # Closing the filtered span should leave the current span alone rust_tracing.close_span(5) - assert sentry_sdk.traces.get_current_span() == info_span + assert sentry_sdk.get_current_span() == info_span rust_tracing.close_span(3) - assert sentry_sdk.traces.get_current_span() == original_sentry_span + assert sentry_sdk.get_current_span() == original_sentry_span sentry_sdk.flush() spans = [item.payload for item in items] @@ -421,12 +421,12 @@ def test_record( with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) - span_before_record = sentry_sdk.traces.get_current_span()._to_json() + span_before_record = sentry_sdk.get_current_span()._to_json() assert span_before_record["attributes"]["version"] == "None" rust_tracing.record(3) - span_after_record = sentry_sdk.traces.get_current_span()._to_json() + span_after_record = sentry_sdk.get_current_span()._to_json() assert span_after_record["attributes"]["version"] == "memoized" @@ -451,14 +451,14 @@ def span_filter(metadata: Dict[str, object]) -> bool: with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) - span_before_record = sentry_sdk.traces.get_current_span()._to_json() + span_before_record = sentry_sdk.get_current_span()._to_json() assert span_before_record["attributes"]["version"] == "None" rust_tracing.new_span(RustTracingLevel.Trace, 5) rust_tracing.record(5) # `on_record()` should not do anything to the current Sentry span if the associated Rust span was ignored - span_after_record = sentry_sdk.traces.get_current_span()._to_json() + span_after_record = sentry_sdk.get_current_span()._to_json() assert span_after_record["attributes"]["version"] == "None" @@ -494,7 +494,7 @@ def test_include_tracing_fields( with sentry_sdk.start_span(name="custom parent"): rust_tracing.new_span(RustTracingLevel.Info, 3) - span_before_record = sentry_sdk.traces.get_current_span()._to_json() + span_before_record = sentry_sdk.get_current_span()._to_json() if tracing_fields_expected: assert span_before_record["attributes"]["version"] == "None" else: @@ -502,7 +502,7 @@ def test_include_tracing_fields( rust_tracing.record(3) - span_after_record = sentry_sdk.traces.get_current_span()._to_json() + span_after_record = sentry_sdk.get_current_span()._to_json() if tracing_fields_expected: assert span_after_record["attributes"]["sentry.op"] == "function" diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index a6ca2e243a..1951d429c7 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -311,7 +311,7 @@ def getresponse(self, *args, **kwargs): ), } items = capture_items("span") - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", @@ -374,7 +374,7 @@ def getresponse(self, *args, **kwargs): items = capture_items("span") - sentry_sdk.traces.continue_trace({}) + sentry_sdk.continue_trace({}) with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000): with sentry_sdk.start_span(name="Head SDK tx"): @@ -445,8 +445,8 @@ def getresponse(self, *args, **kwargs): } # Seed the scope's propagation context, but do NOT start a span. - sentry_sdk.traces.continue_trace(headers) - assert sentry_sdk.traces.get_current_span() is None + sentry_sdk.continue_trace(headers) + assert sentry_sdk.get_current_span() is None connection = HTTPSConnectionRecordingRequestHeaders("localhost", port=PORT) connection.request("GET", "/top-chasers") @@ -568,7 +568,7 @@ def getresponse(self, *args, **kwargs): "sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, " ) } - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) with sentry_sdk.start_span( name="/interactions/other-dogs/new-dog", diff --git a/tests/test_api.py b/tests/test_api.py index 3225233de4..473eb3b6a5 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -31,31 +31,31 @@ def test_get_current_span(): def test_get_current_span_via_traces(): fake_scope = mock.MagicMock() fake_scope.span = mock.MagicMock() - assert sentry_sdk.traces.get_current_span(fake_scope) == fake_scope.span + assert sentry_sdk.get_current_span(fake_scope) == fake_scope.span fake_scope.span = None - assert sentry_sdk.traces.get_current_span(fake_scope) is None + assert sentry_sdk.get_current_span(fake_scope) is None def test_get_current_span_current_scope_via_traces(sentry_init): sentry_init() - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None scope = get_current_scope() fake_span = Span(name="abc", scope=scope) assert scope.span == fake_span - assert sentry_sdk.traces.get_current_span() == fake_span + assert sentry_sdk.get_current_span() == fake_span def test_get_current_span_with_segment(sentry_init): sentry_init() - assert sentry_sdk.traces.get_current_span() is None + assert sentry_sdk.get_current_span() is None with sentry_sdk.start_span(name="segment") as new_segment: - assert sentry_sdk.traces.get_current_span() == new_segment + assert sentry_sdk.get_current_span() == new_segment def test_traceparent_with_tracing_enabled(sentry_init): @@ -125,7 +125,7 @@ def test_continue_trace(sentry_init): trace_id = "471a43a4192642f0b136d5159a501701" parent_span_id = "6e8f22c393e68f19" parent_sampled = 1 - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": "{}-{}-{}".format(trace_id, parent_span_id, parent_sampled), "baggage": "sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-sample_rand=0.123456", diff --git a/tests/test_dsc.py b/tests/test_dsc.py index 303fef5ecd..76b922fd1d 100644 --- a/tests/test_dsc.py +++ b/tests/test_dsc.py @@ -137,7 +137,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes): } # We continue the incoming trace and start a new segment - sentry_sdk.traces.continue_trace(incoming_http_headers) + sentry_sdk.continue_trace(incoming_http_headers) with sentry_sdk.start_span(name="foo"): pass @@ -218,7 +218,7 @@ def my_traces_sampler(sampling_context): # We continue the incoming trace and start a new segment with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=125000): - sentry_sdk.traces.continue_trace(incoming_http_headers) + sentry_sdk.continue_trace(incoming_http_headers) with sentry_sdk.start_span(name="foo"): pass @@ -416,7 +416,7 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate): # We continue the trace (meaning: saving the incoming trace information on the scope) # but in this test, we do not start a segment. - sentry_sdk.traces.continue_trace(incoming_http_headers) + sentry_sdk.continue_trace(incoming_http_headers) # No segment is started, just an error is captured try: diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index 6ad316c36d..4b9d107845 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -20,7 +20,7 @@ def test_trace_decorator(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace + @sentry_sdk.trace def traced_function(): return "ok" @@ -47,7 +47,7 @@ def test_trace_decorator_arguments(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace(name="traced", attributes={"traced.attribute": 123}) + @sentry_sdk.trace(name="traced", attributes={"traced.attribute": 123}) def traced_function(): return "ok" @@ -73,7 +73,7 @@ def test_trace_decorator_inactive(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace(name="outer", active=False) + @sentry_sdk.trace(name="outer", active=False) def traced_function(): with sentry_sdk.start_span(name="inner"): return "ok" @@ -101,7 +101,7 @@ async def test_trace_decorator_async(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace + @sentry_sdk.trace async def traced_function(): return "ok" @@ -130,7 +130,7 @@ async def test_trace_decorator_async_arguments(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace(name="traced", attributes={"traced.attribute": 123}) + @sentry_sdk.trace(name="traced", attributes={"traced.attribute": 123}) async def traced_function(): return "ok" @@ -157,7 +157,7 @@ async def test_trace_decorator_async_inactive(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace(name="outer", active=False) + @sentry_sdk.trace(name="outer", active=False) async def traced_function(): with sentry_sdk.start_span(name="inner"): return "ok" @@ -185,7 +185,7 @@ def test_trace_decorator_child(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace + @sentry_sdk.trace def _some_function_traced_stream(a, b, c): return True @@ -217,7 +217,7 @@ async def test_trace_decorator_async_child(sentry_init, capture_items): items = capture_items("span") - @sentry_sdk.traces.trace + @sentry_sdk.trace async def _some_function_traced_stream(a, b, c): return True @@ -248,7 +248,7 @@ def test_functions_to_trace_signature_unchanged_sync(sentry_init): def _some_function(a, b, c): pass - @sentry_sdk.traces.trace + @sentry_sdk.trace def _some_function_traced_stream(a, b, c): pass @@ -266,7 +266,7 @@ async def test_functions_to_trace_signature_unchanged_async(sentry_init): async def _some_function(a, b, c): pass - @sentry_sdk.traces.trace + @sentry_sdk.trace async def _some_function_traced_stream(a, b, c): pass diff --git a/tests/tracing/test_integration_tests.py b/tests/tracing/test_integration_tests.py index 2e727953d0..555ce40c29 100644 --- a/tests/tracing/test_integration_tests.py +++ b/tests/tracing/test_integration_tests.py @@ -103,7 +103,7 @@ def test_continue_trace(sentry_init, capture_items, parent_sampled, sample_rate) ), } - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) # child segment, to prove that we can read 'sentry-trace' header data correctly with sentry_sdk.start_span(name="WRONG") as child_segment: @@ -198,7 +198,7 @@ def test_dynamic_sampling_head_sdk_creates_dsc( # make sure segment is sampled for both cases with mock.patch("sentry_sdk.tracing_utils.Random.randrange", return_value=250000): - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.start_span(name="Head SDK segment") as segment: baggage = segment._baggage assert baggage is None @@ -328,7 +328,7 @@ def test_trace_propagation_meta_head_sdk(sentry_init): release="foo", ) - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() meta = None span = None @@ -438,7 +438,7 @@ def test_continue_trace_strict_trace_continuation( ), } - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) with sentry_sdk.start_span(name="strict trace") as segment: headers = sentry_sdk.get_current_scope().iter_trace_propagation_headers(segment) @@ -461,11 +461,11 @@ def test_continue_trace_forces_new_traces_when_no_propagation( sentry_init(traces_sample_rate=1.0) - sentry_sdk.traces.continue_trace({}) + sentry_sdk.continue_trace({}) with sentry_sdk.start_span(name="segment1") as segment1: pass - sentry_sdk.traces.continue_trace({}) + sentry_sdk.continue_trace({}) with sentry_sdk.start_span(name="segment2") as segment2: pass @@ -477,11 +477,11 @@ def test_continue_trace_forces_new_traces_when_no_propagation_with_new_trace( ): sentry_init(traces_sample_rate=1.0) - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.start_span(name="segment1") as segment1: pass - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.start_span(name="segment2") as segment2: pass diff --git a/tests/tracing/test_sample_rand.py b/tests/tracing/test_sample_rand.py index 62c6bd4c26..baec6b033e 100644 --- a/tests/tracing/test_sample_rand.py +++ b/tests/tracing/test_sample_rand.py @@ -58,7 +58,7 @@ def test_segment_uses_incoming_sample_rand( ) items = capture_items("span") - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": "0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331", "baggage": f"sentry-sample_rand={sample_rand:.6f}", diff --git a/tests/tracing/test_sample_rand_propagation.py b/tests/tracing/test_sample_rand_propagation.py index 792ff0e3dd..7eda59cf6c 100644 --- a/tests/tracing/test_sample_rand_propagation.py +++ b/tests/tracing/test_sample_rand_propagation.py @@ -23,7 +23,7 @@ def test_continue_trace_with_sample_rand(sentry_init): "baggage": "sentry-sample_rand=0.100000,sentry-sample_rate=0.5", } - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) with sentry_sdk.start_span(name="span") as segment: assert segment._get_baggage().sentry_items["sample_rand"] == "0.100000" @@ -43,6 +43,6 @@ def test_continue_trace_missing_sample_rand(sentry_init): with mock.patch( "sentry_sdk.tracing_utils.Random.randrange", Mock(return_value=500000) ): - sentry_sdk.traces.continue_trace(headers) + sentry_sdk.continue_trace(headers) with sentry_sdk.start_span(name="span") as span: assert span._get_baggage().sentry_items["sample_rand"] == "0.500000" diff --git a/tests/tracing/test_sampling.py b/tests/tracing/test_sampling.py index d0de184476..2754e07e68 100644 --- a/tests/tracing/test_sampling.py +++ b/tests/tracing/test_sampling.py @@ -44,7 +44,7 @@ def test_get_span_from_scope_regardless_of_sampling_decision( ): sentry_init(traces_sample_rate=1.0) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-{int(sampling_decision)}" } @@ -75,7 +75,7 @@ def test_uses_traces_sample_rate_correctly( traces_sample_rate=traces_sample_rate, ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": "0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331", "baggage": "sentry-sample_rand=0.500000", @@ -99,7 +99,7 @@ def test_uses_traces_sampler_return_value_correctly( traces_sampler=mock.Mock(return_value=traces_sampler_return_value), ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": "0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331", "baggage": "sentry-sample_rand=0.500000", @@ -133,7 +133,7 @@ def test_traces_sampler_raising_falls_back_to_parent_sampling_decision( traces_sample_rate=0.0 if parent_sampling_decision else 1.0, ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-{int(parent_sampling_decision)}" } @@ -157,7 +157,7 @@ def test_traces_sampler_raising_falls_back_to_traces_sample_rate( traces_sample_rate=traces_sample_rate, ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": "0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331", "baggage": "sentry-sample_rand=0.500000", @@ -254,7 +254,7 @@ def test_ignores_inherited_sample_decision_when_traces_sampler_defined( traces_sampler=traces_sampler, ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-{parent_sampling_decision}" } @@ -271,7 +271,7 @@ def test_inherits_parent_sampling_decision_when_traces_sampler_undefined( traces_sample_rate=0.5, ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-{parent_sampling_decision}" } @@ -325,14 +325,14 @@ def traces_sampler(sampling_context): traces_sampler=traces_sampler, ) - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() sentry_sdk.get_current_scope().set_custom_sampling_context({"custom_value": 1}) with sentry_sdk.start_span(name="span", attributes={"first": True}): ... - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() sentry_sdk.get_current_scope().set_custom_sampling_context({"custom_value": 2}) diff --git a/tests/tracing/test_span_batcher.py b/tests/tracing/test_span_batcher.py index e3901ccfc6..c4fe6b376a 100644 --- a/tests/tracing/test_span_batcher.py +++ b/tests/tracing/test_span_batcher.py @@ -18,7 +18,7 @@ def test_envelope_by_trace_id(sentry_init, capture_envelopes, monkeypatch): envelopes = capture_envelopes() with sentry_sdk.new_scope(): - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() # Keep parent open as its bucket in the batcher would be emptied when it is finished. parent_a = sentry_sdk.start_span(name="parent a") with sentry_sdk.start_span(name="span 1a", parent_span=parent_a) as span1: @@ -27,7 +27,7 @@ def test_envelope_by_trace_id(sentry_init, capture_envelopes, monkeypatch): pass with sentry_sdk.new_scope(): - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() parent_b = sentry_sdk.start_span(name="parent b") # Keep parent open as its bucket in the batcher would be emptied when it is finished. with sentry_sdk.start_span(name="span 2a", parent_span=parent_b) as span2: @@ -153,7 +153,7 @@ def test_drop_isolated_per_bucket( pass with sentry_sdk.new_scope(): - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() # Keep parent open as its bucket in the batcher would be emptied when it is finished. parent_b = sentry_sdk.start_span(name="parent b") with sentry_sdk.start_span(name="b1", parent_span=parent_b) as span_b: @@ -274,7 +274,7 @@ def test_bucket_recreated_after_flush(sentry_init, capture_envelopes, monkeypatc envelopes = capture_envelopes() - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.start_span(name="custom parent"): with sentry_sdk.start_span(name="span 1") as span1: @@ -348,7 +348,7 @@ def test_quiet_buckets_flushed_with_busy_neighbors( envelopes = capture_envelopes() - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.new_scope(): # Keep parent open as its bucket in the batcher would be emptied when it is finished. @@ -357,7 +357,7 @@ def test_quiet_buckets_flushed_with_busy_neighbors( trace_id1 = span1.trace_id with sentry_sdk.new_scope(): - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() # Keep parent open as its bucket in the batcher would be emptied when it is finished. parent_b = sentry_sdk.start_span(name="parent b") with sentry_sdk.start_span(name="span 2", parent_span=parent_b) as span2: diff --git a/tests/tracing/test_span_streaming.py b/tests/tracing/test_span_streaming.py index 76837bc9d2..1aeaf27785 100644 --- a/tests/tracing/test_span_streaming.py +++ b/tests/tracing/test_span_streaming.py @@ -607,7 +607,7 @@ def test_sibling_segments_new_trace(sentry_init, capture_items): with sentry_sdk.start_span(name="segment1"): ... - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.start_span(name="segment2"): ... @@ -643,7 +643,7 @@ def test_continue_trace_sampled(sentry_init, capture_items): sample_rand = "0.222222" sampled = "1" - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}-{sampled}", "baggage": f"sentry-trace_id={trace_id},sentry-sample_rate=0.5,sentry-sample_rand={sample_rand}", @@ -682,7 +682,7 @@ def test_continue_trace_unsampled(sentry_init, capture_items): sample_rand = "0.999999" sampled = "0" - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}-{sampled}", "baggage": f"sentry-trace_id={trace_id},sentry-sample_rate=0.5,sentry-sample_rand={sample_rand}", @@ -735,7 +735,7 @@ def test_backpressure_outcome( trace_id = "0af7651916cd43dd8448eb211c80319c" parent_span_id = "b7ad6b7169203331" - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}", "baggage": f"sentry-trace_id={trace_id},sentry-sample_rand={sample_rand}", @@ -777,7 +777,7 @@ def test_continue_trace_no_sample_rand(sentry_init, capture_items): parent_span_id = "b7ad6b7169203331" sampled = "1" - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}-{sampled}", "baggage": f"sentry-trace_id={trace_id},sentry-sample_rate=0.5", @@ -825,7 +825,7 @@ def test_outgoing_traceparent_and_baggage_head_sdk(sentry_init, traces_sample_ra traces_sample_rate=traces_sample_rate, ) - sentry_sdk.traces.new_trace() + sentry_sdk.new_trace() with sentry_sdk.start_span(name="span") as span: assert span.sampled is expected_sampled @@ -917,7 +917,7 @@ def test_outgoing_traceparent_and_baggage_incoming_trace( } ) - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": incoming_sentry_trace, "baggage": ",".join( @@ -983,7 +983,7 @@ def test_outgoing_traceparent_and_baggage_inconsistent_incoming_trace( "sentry-sampled": "true", } - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": incoming_sentry_trace, "baggage": ",".join( @@ -1039,7 +1039,7 @@ def test_outgoing_traceparent_and_baggage_incoming_trace_deferred( incoming_baggage = {"sentry-trace_id": trace_id, "sentry-sample_rand": "0.500000"} - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}-", "baggage": ",".join( @@ -1095,7 +1095,7 @@ def test_outgoing_traceparent_and_baggage_ignored_segment(sentry_init): "sentry-sample_rate": "1.0", } - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}-1", "baggage": ",".join( @@ -1132,7 +1132,7 @@ def test_outgoing_traceparent_and_baggage_ignored_child_span(sentry_init): "sentry-sample_rate": "1.0", } - sentry_sdk.traces.continue_trace( + sentry_sdk.continue_trace( { "sentry-trace": f"{trace_id}-{parent_span_id}-1", "baggage": ",".join( From 84ea6626b4d24be5262826d2bf6c63f7ee273766 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 22 Sep 2026 13:29:01 +0200 Subject: [PATCH 3/3] mypy --- sentry_sdk/integrations/clickhouse_driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/clickhouse_driver.py b/sentry_sdk/integrations/clickhouse_driver.py index edbe19850d..9a1018f52e 100644 --- a/sentry_sdk/integrations/clickhouse_driver.py +++ b/sentry_sdk/integrations/clickhouse_driver.py @@ -82,7 +82,7 @@ def _inner(*args: "P.args", **kwargs: "P.kwargs") -> "T": span = None if sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span( - name=query, # type: ignore + name=query, attributes={ "sentry.op": OP.DB, "sentry.origin": ClickhouseDriverIntegration.origin,