Skip to content

Commit 8f80c90

Browse files
reapply some changes
1 parent 1fd9ed0 commit 8f80c90

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

sentry_sdk/integrations/bottle.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import functools
2+
13
import sentry_sdk
24
from sentry_sdk.tracing import SOURCE_FOR_STYLE
35
from sentry_sdk.utils import (
@@ -81,10 +83,12 @@ def sentry_patched_wsgi_app(self, environ, start_response):
8183

8284
old_handle = Bottle._handle
8385

84-
@ensure_integration_enabled(BottleIntegration, old_handle)
86+
@functools.wraps(old_handle)
8587
def _patched_handle(self, environ):
8688
# type: (Bottle, Dict[str, Any]) -> Any
8789
integration = sentry_sdk.get_client().get_integration(BottleIntegration)
90+
if integration is None:
91+
return old_handle(self, environ)
8892

8993
scope = sentry_sdk.get_isolation_scope()
9094
scope._name = "bottle"

sentry_sdk/integrations/celery/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,15 @@ def __exit__(self, exc_type, exc_value, traceback):
248248
def _wrap_task_run(f):
249249
# type: (F) -> F
250250
@wraps(f)
251-
@ensure_integration_enabled(CeleryIntegration, f)
252251
def apply_async(*args, **kwargs):
253252
# type: (*Any, **Any) -> Any
254253
# Note: kwargs can contain headers=None, so no setdefault!
255254
# Unsure which backend though.
256-
kwarg_headers = kwargs.get("headers") or {}
257255
integration = sentry_sdk.get_client().get_integration(CeleryIntegration)
256+
if integration is None:
257+
return f(*args, **kwargs)
258+
259+
kwarg_headers = kwargs.get("headers") or {}
258260
propagate_traces = kwarg_headers.pop(
259261
"sentry-propagate-traces", integration.propagate_traces
260262
)

sentry_sdk/integrations/cohere.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
import sentry_sdk
1515
from sentry_sdk.scope import should_send_default_pii
1616
from sentry_sdk.integrations import DidNotEnable, Integration
17-
from sentry_sdk.utils import (
18-
capture_internal_exceptions,
19-
event_from_exception,
20-
ensure_integration_enabled,
21-
)
17+
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
2218

2319
try:
2420
from cohere.client import Client
@@ -134,13 +130,15 @@ def collect_chat_response_fields(span, res, include_pii):
134130
set_data_normalized(span, "ai.warnings", res.meta.warnings)
135131

136132
@wraps(f)
137-
@ensure_integration_enabled(CohereIntegration, f)
138133
def new_chat(*args, **kwargs):
139134
# type: (*Any, **Any) -> Any
140-
if "message" not in kwargs:
141-
return f(*args, **kwargs)
135+
integration = sentry_sdk.get_client().get_integration(CohereIntegration)
142136

143-
if not isinstance(kwargs.get("message"), str):
137+
if (
138+
integration is None
139+
or "message" not in kwargs
140+
or not isinstance(kwargs.get("message"), str)
141+
):
144142
return f(*args, **kwargs)
145143

146144
message = kwargs.get("message")
@@ -158,8 +156,6 @@ def new_chat(*args, **kwargs):
158156
span.__exit__(None, None, None)
159157
raise e from None
160158

161-
integration = sentry_sdk.get_client().get_integration(CohereIntegration)
162-
163159
with capture_internal_exceptions():
164160
if should_send_default_pii() and integration.include_prompts:
165161
set_data_normalized(
@@ -227,15 +223,17 @@ def _wrap_embed(f):
227223
# type: (Callable[..., Any]) -> Callable[..., Any]
228224

229225
@wraps(f)
230-
@ensure_integration_enabled(CohereIntegration, f)
231226
def new_embed(*args, **kwargs):
232227
# type: (*Any, **Any) -> Any
228+
integration = sentry_sdk.get_client().get_integration(CohereIntegration)
229+
if integration is None:
230+
return f(*args, **kwargs)
231+
233232
with sentry_sdk.start_span(
234233
op=consts.OP.COHERE_EMBEDDINGS_CREATE,
235234
name="Cohere Embedding Creation",
236235
origin=CohereIntegration.origin,
237236
) as span:
238-
integration = sentry_sdk.get_client().get_integration(CohereIntegration)
239237
if "texts" in kwargs and (
240238
should_send_default_pii() and integration.include_prompts
241239
):

sentry_sdk/integrations/django/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,11 @@ def _set_transaction_name_and_source(scope, transaction_style, request):
411411
pass
412412

413413

414-
@ensure_integration_enabled(DjangoIntegration)
415414
def _before_get_response(request):
416415
# type: (WSGIRequest) -> None
417416
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
417+
if integration is None:
418+
return
418419

419420
_patch_drf()
420421

@@ -440,11 +441,10 @@ def _attempt_resolve_again(request, scope, transaction_style):
440441
_set_transaction_name_and_source(scope, transaction_style, request)
441442

442443

443-
@ensure_integration_enabled(DjangoIntegration)
444444
def _after_get_response(request):
445445
# type: (WSGIRequest) -> None
446446
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
447-
if integration.transaction_style != "url":
447+
if integration is None or integration.transaction_style != "url":
448448
return
449449

450450
scope = sentry_sdk.get_current_scope()
@@ -510,11 +510,12 @@ def wsgi_request_event_processor(event, hint):
510510
return wsgi_request_event_processor
511511

512512

513-
@ensure_integration_enabled(DjangoIntegration)
514513
def _got_request_exception(request=None, **kwargs):
515514
# type: (WSGIRequest, **Any) -> None
516515
client = sentry_sdk.get_client()
517516
integration = client.get_integration(DjangoIntegration)
517+
if integration is None:
518+
return
518519

519520
if request is not None and integration.transaction_style == "url":
520521
scope = sentry_sdk.get_current_scope()

0 commit comments

Comments
 (0)