Skip to content

Commit 9d3ed1b

Browse files
condense span streaming checks
1 parent 42bacce commit 9d3ed1b

8 files changed

Lines changed: 13 additions & 33 deletions

File tree

sentry_sdk/integrations/django/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,7 @@ def connect(self: "BaseDatabaseWrapper") -> None:
681681
with capture_internal_exceptions():
682682
sentry_sdk.add_breadcrumb(message="connect", category="query")
683683

684-
client = sentry_sdk.get_client()
685-
span_streaming = has_span_streaming_enabled(client.options)
686-
684+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
687685
if span_streaming:
688686
with sentry_sdk.traces.start_span(
689687
name="connect",
@@ -709,9 +707,7 @@ def _commit(self: "BaseDatabaseWrapper") -> None:
709707
if integration is None or not integration.db_transaction_spans:
710708
return real_commit(self)
711709

712-
client = sentry_sdk.get_client()
713-
span_streaming = has_span_streaming_enabled(client.options)
714-
710+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
715711
if span_streaming:
716712
with sentry_sdk.traces.start_span(
717713
name=SPANNAME.DB_COMMIT,
@@ -737,9 +733,7 @@ def _rollback(self: "BaseDatabaseWrapper") -> None:
737733
if integration is None or not integration.db_transaction_spans:
738734
return real_rollback(self)
739735

740-
client = sentry_sdk.get_client()
741-
span_streaming = has_span_streaming_enabled(client.options)
742-
736+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
743737
if span_streaming:
744738
with sentry_sdk.traces.start_span(
745739
name=SPANNAME.DB_ROLLBACK,

sentry_sdk/integrations/django/asgi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ async def sentry_wrapped_callback(
183183
if not integration or not integration.middleware_spans:
184184
return await callback(request, *args, **kwargs)
185185

186-
client = sentry_sdk.get_client()
187-
span_streaming = has_span_streaming_enabled(client.options)
188-
186+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
189187
if span_streaming:
190188
with sentry_sdk.traces.start_span(
191189
name=request.resolver_match.view_name,

sentry_sdk/integrations/django/caching.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def _instrument_call(
6262
op = OP.CACHE_PUT if is_set_operation else OP.CACHE_GET
6363
description = _get_span_description(method_name, args, kwargs)
6464

65-
client = sentry_sdk.get_client()
66-
span_streaming = has_span_streaming_enabled(client.options)
67-
65+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
6866
if span_streaming:
6967
with sentry_sdk.traces.start_span(
7068
name=description,

sentry_sdk/integrations/django/middleware.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ def _check_middleware_span(
8585
if function_basename:
8686
description = "{}.{}".format(description, function_basename)
8787

88-
client = sentry_sdk.get_client()
89-
span_streaming = has_span_streaming_enabled(client.options)
90-
88+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
9189
middleware_span: "Union[Span, StreamedSpan]"
9290
if span_streaming:
9391
middleware_span = sentry_sdk.traces.start_span(

sentry_sdk/integrations/django/signals_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def sentry_sync_receiver_wrapper(
6565
def wrapper(*args: "Any", **kwargs: "Any") -> "Any":
6666
signal_name = _get_receiver_name(receiver)
6767

68-
client = sentry_sdk.get_client()
69-
span_streaming = has_span_streaming_enabled(client.options)
70-
68+
span_streaming = has_span_streaming_enabled(
69+
sentry_sdk.get_client().options
70+
)
7171
if span_streaming:
7272
with sentry_sdk.traces.start_span(
7373
name=signal_name,

sentry_sdk/integrations/django/tasks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def _sentry_enqueue(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
3333

3434
name = qualname_from_function(self.func) or "<unknown Django task>"
3535

36-
client = sentry_sdk.get_client()
37-
span_streaming = has_span_streaming_enabled(client.options)
38-
36+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
3937
if span_streaming:
4038
with sentry_sdk.traces.start_span(
4139
name=name,

sentry_sdk/integrations/django/templates.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def patch_templates() -> None:
6666
@property # type: ignore
6767
@ensure_integration_enabled(DjangoIntegration, real_rendered_content.fget)
6868
def rendered_content(self: "SimpleTemplateResponse") -> str:
69-
client = sentry_sdk.get_client()
70-
span_streaming = has_span_streaming_enabled(client.options)
71-
69+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
7270
if span_streaming:
7371
with sentry_sdk.traces.start_span(
7472
name=_get_template_name_description(self.template_name),

sentry_sdk/integrations/django/views.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def patch_views() -> None:
3131
old_render = SimpleTemplateResponse.render
3232

3333
def sentry_patched_render(self: "SimpleTemplateResponse") -> "Any":
34-
client = sentry_sdk.get_client()
35-
span_streaming = has_span_streaming_enabled(client.options)
36-
34+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
3735
if span_streaming:
3836
with sentry_sdk.traces.start_span(
3937
name="serialize response",
@@ -100,9 +98,7 @@ def sentry_wrapped_callback(request: "Any", *args: "Any", **kwargs: "Any") -> "A
10098
if not integration or not integration.middleware_spans:
10199
return callback(request, *args, **kwargs)
102100

103-
client = sentry_sdk.get_client()
104-
span_streaming = has_span_streaming_enabled(client.options)
105-
101+
span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options)
106102
if span_streaming:
107103
with sentry_sdk.traces.start_span(
108104
name=request.resolver_match.view_name,

0 commit comments

Comments
 (0)