Skip to content

Commit e7f379e

Browse files
authored
ref: Use top-level API throughout the SDK (#7578)
Boost the likelihood that agents learn the correct API when exploring our SDK code.
1 parent 35f70d2 commit e7f379e

139 files changed

Lines changed: 886 additions & 907 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎sentry_sdk/feature_flags.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def add_feature_flag(flag: str, result: bool) -> None:
6161
flags = sentry_sdk.get_isolation_scope().flags
6262
flags.set(flag, result)
6363

64-
span = sentry_sdk.traces.get_current_span()
64+
span = sentry_sdk.get_current_span()
6565
if span is not None:
6666
span.set_attribute(f"flag.evaluation.{flag}", result)

‎sentry_sdk/integrations/aiohttp.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async def sentry_app_handle(
130130

131131
headers = dict(request.headers)
132132

133-
sentry_sdk.traces.continue_trace(headers)
133+
sentry_sdk.continue_trace(headers)
134134
Scope.set_custom_sampling_context({"aiohttp_request": request})
135135

136136
header_attributes: "dict[str, Any]" = {}
@@ -197,7 +197,7 @@ async def sentry_app_handle(
197197
SPANDATA.USER_IP_ADDRESS, request.remote
198198
)
199199

200-
span = sentry_sdk.traces.start_span(
200+
span = sentry_sdk.start_span(
201201
# If this name makes it to the UI, AIOHTTP's URL
202202
# resolver did not find a route or died trying.
203203
name="generic AIOHTTP request",
@@ -385,8 +385,8 @@ async def on_request_start(
385385
attributes["url.full"] = url_full
386386
breadcrumb["url"] = url_full
387387

388-
if sentry_sdk.traces.get_current_span() is not None:
389-
span = sentry_sdk.traces.start_span(name=span_name, attributes=attributes)
388+
if sentry_sdk.get_current_span() is not None:
389+
span = sentry_sdk.start_span(name=span_name, attributes=attributes)
390390

391391
if should_propagate_trace(client, str(params.url)):
392392
# existing `sentry-trace`: skip so it is not duplicated.

‎sentry_sdk/integrations/aiomysql.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ async def _inner(self: "Connection") -> T:
193193
message="connect", category="query", data=breadcrumb_data
194194
)
195195

196-
if sentry_sdk.traces.get_current_span() is None:
196+
if sentry_sdk.get_current_span() is None:
197197
return await f(self)
198198

199199
span_attributes: dict[str, Any] = {
200200
"sentry.op": OP.DB,
201201
"sentry.origin": AioMySQLIntegration.origin,
202202
} | breadcrumb_data
203203

204-
with sentry_sdk.traces.start_span(name="connect", attributes=span_attributes):
204+
with sentry_sdk.start_span(name="connect", attributes=span_attributes):
205205
return await f(self)
206206

207207
return _inner

‎sentry_sdk/integrations/anthropic.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def _sentry_patched_create_sync(f: "Any", *args: "Any", **kwargs: "Any") -> "Any
722722

723723
model = kwargs.get("model", "")
724724

725-
span = sentry_sdk.traces.start_span(
725+
span = sentry_sdk.start_span(
726726
name=f"chat {model}".strip(),
727727
attributes={
728728
"sentry.op": OP.GEN_AI_CHAT,
@@ -812,7 +812,7 @@ async def _sentry_patched_create_async(
812812

813813
model = kwargs.get("model", "")
814814

815-
span = sentry_sdk.traces.start_span(
815+
span = sentry_sdk.start_span(
816816
name=f"chat {model}".strip(),
817817
attributes={
818818
"sentry.op": OP.GEN_AI_CHAT,
@@ -1053,7 +1053,7 @@ def _sentry_patched_enter(self: "MessageStreamManager") -> "MessageStream":
10531053
except TypeError:
10541054
return f(self)
10551055

1056-
span = sentry_sdk.traces.start_span(
1056+
span = sentry_sdk.start_span(
10571057
name="chat"
10581058
if patched_self._model is None
10591059
else f"chat {patched_self._model}".strip(),
@@ -1157,7 +1157,7 @@ async def _sentry_patched_aenter(
11571157
except TypeError:
11581158
return await f(self)
11591159

1160-
span = sentry_sdk.traces.start_span(
1160+
span = sentry_sdk.start_span(
11611161
name="chat"
11621162
if patched_self._model is None
11631163
else f"chat {patched_self._model}".strip(),

‎sentry_sdk/integrations/arq.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ async def _sentry_enqueue_job(
7777
if client.get_integration(ArqIntegration) is None:
7878
return await old_enqueue_job(self, function, *args, **kwargs)
7979

80-
if sentry_sdk.traces.get_current_span() is None:
80+
if sentry_sdk.get_current_span() is None:
8181
return await old_enqueue_job(self, function, *args, **kwargs)
8282

83-
with sentry_sdk.traces.start_span(
83+
with sentry_sdk.start_span(
8484
name=function,
8585
attributes={
8686
"sentry.op": OP.QUEUE_SUBMIT_ARQ,
@@ -105,7 +105,7 @@ async def _sentry_run_job(self: "Worker", job_id: str, score: int) -> None:
105105
scope._name = "arq"
106106
scope.clear_breadcrumbs()
107107

108-
with sentry_sdk.traces.start_span(
108+
with sentry_sdk.start_span(
109109
name="unknown arq task",
110110
attributes={
111111
"sentry.op": OP.QUEUE_TASK_ARQ,

‎sentry_sdk/integrations/asgi.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,24 @@ async def _run_app(
235235

236236
if ty in ("http", "websocket"):
237237
if ty == "websocket" or method in self.http_methods_to_capture:
238-
sentry_sdk.traces.continue_trace(_get_headers(scope))
238+
sentry_sdk.continue_trace(_get_headers(scope))
239239

240240
Scope.set_custom_sampling_context({"asgi_scope": scope})
241241

242242
attributes["sentry.op"] = f"{ty}.server"
243-
span = sentry_sdk.traces.start_span(
243+
span = sentry_sdk.start_span(
244244
name=transaction_name,
245245
attributes=attributes,
246246
parent_span=None,
247247
)
248248
sentry_scope.get_current_scope()._server_segment_span = span
249249
else:
250-
sentry_sdk.traces.new_trace()
250+
sentry_sdk.new_trace()
251251

252252
Scope.set_custom_sampling_context({"asgi_scope": scope})
253253

254254
attributes["sentry.op"] = OP.HTTP_SERVER
255-
span = sentry_sdk.traces.start_span(
255+
span = sentry_sdk.start_span(
256256
name=transaction_name,
257257
attributes=attributes,
258258
parent_span=None,

‎sentry_sdk/integrations/asyncio.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ async def _task_with_sentry_span_creation() -> "Any":
148148

149149
with sentry_sdk.isolation_scope():
150150
span_ctx = nullcontext()
151-
if task_spans and sentry_sdk.traces.get_current_span() is not None:
152-
span_ctx = sentry_sdk.traces.start_span(
151+
if task_spans and sentry_sdk.get_current_span() is not None:
152+
span_ctx = sentry_sdk.start_span(
153153
name=get_name(coro),
154154
attributes={
155155
"sentry.op": OP.FUNCTION,

‎sentry_sdk/integrations/asyncpg.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T":
222222
message="connect", category="query", data=span_attributes
223223
)
224224

225-
if sentry_sdk.traces.get_current_span() is None:
225+
if sentry_sdk.get_current_span() is None:
226226
return await f(*args, **kwargs)
227227

228-
with sentry_sdk.traces.start_span(name="connect", attributes=span_attributes):
228+
with sentry_sdk.start_span(name="connect", attributes=span_attributes):
229229
return await f(*args, **kwargs)
230230

231231
return _inner

‎sentry_sdk/integrations/aws_lambda.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ def sentry_handler(
213213

214214
function_name = aws_context.function_name
215215

216-
sentry_sdk.traces.continue_trace(headers)
216+
sentry_sdk.continue_trace(headers)
217217
Scope.set_custom_sampling_context(sampling_context)
218218

219-
with sentry_sdk.traces.start_span(
219+
with sentry_sdk.start_span(
220220
name=function_name,
221221
parent_span=None,
222222
attributes={

‎sentry_sdk/integrations/boto3.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def _sentry_request_created(
8585
if request.method is not None:
8686
breadcrumb[SPANDATA.HTTP_REQUEST_METHOD] = request.method
8787

88-
if sentry_sdk.traces.get_current_span() is not None:
89-
span = sentry_sdk.traces.start_span(
88+
if sentry_sdk.get_current_span() is not None:
89+
span = sentry_sdk.start_span(
9090
name=description,
9191
attributes={
9292
"sentry.op": OP.HTTP_CLIENT,
@@ -176,7 +176,7 @@ def _sentry_after_call(
176176
if not isinstance(body, StreamingBody):
177177
return
178178

179-
streaming_span = sentry_sdk.traces.start_span(
179+
streaming_span = sentry_sdk.start_span(
180180
name=span.name,
181181
parent_span=span,
182182
attributes={

0 commit comments

Comments
 (0)