Skip to content

Commit de8652b

Browse files
authored
ref: Enforce minimum version in integrations (#7015)
- Add `_check_minimum_version` calls to all integrations that had entries in `_MIN_VERSIONS` but were not enforcing them at runtime - Add new `_MIN_VERSIONS` entries for integrations that were missing them - Use package-provided version if possible; fallback to `package_version` only if not available
1 parent f885be9 commit de8652b

37 files changed

Lines changed: 210 additions & 104 deletions

scripts/populate_tox/releases.jsonl

Lines changed: 5 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sentry_sdk/integrations/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ def iter_default_integrations(
146146
"grpc": (1, 32, 0), # grpcio
147147
"httpx": (0, 16, 0),
148148
"httpx2": (2, 0, 0),
149+
"huey": (2, 0),
149150
"huggingface_hub": (0, 24, 7),
150151
"langchain": (0, 1, 0),
151152
"langgraph": (0, 6, 6),
152153
"launchdarkly": (9, 8, 0),
154+
"litestar": (2, 0, 0),
153155
"litellm": (1, 77, 5),
154156
"loguru": (0, 7, 0),
155157
"mcp": (1, 15, 0),
@@ -158,18 +160,22 @@ def iter_default_integrations(
158160
"openfeature": (0, 7, 1),
159161
"pydantic_ai": (1, 0, 0),
160162
"pymongo": (3, 5, 0),
163+
"pyramid": (1, 8),
161164
"pyreqwest": (0, 11, 6),
162165
"quart": (0, 16, 0),
163166
"ray": (2, 7, 0),
167+
"redis": (2, 10, 0),
164168
"requests": (2, 30, 0),
165169
"rq": (0, 6),
166170
"sanic": (0, 8),
171+
"spark": (3, 0), # pyspark
167172
"sqlalchemy": (1, 2),
168173
"starlette": (0, 16),
169174
"starlite": (1, 48),
170175
"statsig": (0, 55, 3),
171176
"strawberry": (0, 209, 5),
172177
"tornado": (6, 0),
178+
"trytond": (4, 6),
173179
"typer": (0, 15),
174180
"unleash": (6, 0, 1),
175181
}

sentry_sdk/integrations/anthropic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from sentry_sdk.utils import (
2727
capture_internal_exceptions,
2828
event_from_exception,
29-
package_version,
29+
parse_version,
3030
reraise,
3131
safe_serialize,
3232
)
@@ -43,6 +43,7 @@
4343
Omit = None
4444

4545
from anthropic import AsyncStream, Stream
46+
from anthropic import __version__ as ANTHROPIC_VERSION
4647
from anthropic.lib.streaming import (
4748
AsyncMessageStream,
4849
AsyncMessageStreamManager,
@@ -151,7 +152,7 @@ def __init__(self: "AnthropicIntegration", include_prompts: bool = True) -> None
151152

152153
@staticmethod
153154
def setup_once() -> None:
154-
version = package_version("anthropic")
155+
version = parse_version(ANTHROPIC_VERSION)
155156
_check_minimum_version(AnthropicIntegration, version)
156157

157158
"""

sentry_sdk/integrations/beam.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from typing import TYPE_CHECKING
55

66
import sentry_sdk
7-
from sentry_sdk.integrations import Integration
7+
from sentry_sdk.integrations import Integration, _check_minimum_version
88
from sentry_sdk.integrations.logging import ignore_logger
99
from sentry_sdk.utils import (
1010
capture_internal_exceptions,
1111
ensure_integration_enabled,
1212
event_from_exception,
13+
parse_version,
1314
reraise,
1415
)
1516

@@ -32,8 +33,12 @@ class BeamIntegration(Integration):
3233

3334
@staticmethod
3435
def setup_once() -> None:
36+
from apache_beam import __version__ as BEAM_VERSION # type: ignore
3537
from apache_beam.transforms.core import DoFn, ParDo # type: ignore
3638

39+
version = parse_version(BEAM_VERSION)
40+
_check_minimum_version(BeamIntegration, version)
41+
3742
ignore_logger("root")
3843
ignore_logger("bundle_processor.create")
3944

sentry_sdk/integrations/chalice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import wraps
33

44
import sentry_sdk
5-
from sentry_sdk.integrations import DidNotEnable, Integration
5+
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
66
from sentry_sdk.integrations._wsgi_common import _filter_headers
77
from sentry_sdk.integrations.aws_lambda import _make_request_event_processor
88
from sentry_sdk.traces import (
@@ -156,9 +156,9 @@ class ChaliceIntegration(Integration):
156156
@staticmethod
157157
def setup_once() -> None:
158158
version = parse_version(CHALICE_VERSION)
159-
159+
_check_minimum_version(ChaliceIntegration, version)
160160
if version is None:
161-
raise DidNotEnable("Unparsable Chalice version: {}".format(CHALICE_VERSION))
161+
return
162162

163163
if version < (1, 20):
164164
old_get_view_function_response = Chalice._get_view_function_response

sentry_sdk/integrations/cohere.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@
1515
from sentry_sdk.tracing import Span
1616

1717
import sentry_sdk
18-
from sentry_sdk.integrations import DidNotEnable, Integration
18+
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
1919
from sentry_sdk.scope import should_send_default_pii
20-
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception, reraise
20+
from sentry_sdk.utils import (
21+
capture_internal_exceptions,
22+
event_from_exception,
23+
parse_version,
24+
reraise,
25+
)
2126

2227
try:
2328
from cohere import (
2429
ChatStreamEndEvent,
2530
NonStreamedChatResponse,
2631
)
32+
from cohere import (
33+
__version__ as COHERE_VERSION,
34+
)
2735
from cohere.base_client import BaseCohere
2836
from cohere.client import Client
2937

@@ -78,6 +86,9 @@ def __init__(self: "CohereIntegration", include_prompts: bool = True) -> None:
7886

7987
@staticmethod
8088
def setup_once() -> None:
89+
version = parse_version(COHERE_VERSION)
90+
_check_minimum_version(CohereIntegration, version)
91+
8192
BaseCohere.chat = _wrap_chat(BaseCohere.chat, streaming=False)
8293
Client.embed = _wrap_embed(Client.embed)
8394
BaseCohere.chat_stream = _wrap_chat(BaseCohere.chat_stream, streaming=True)

sentry_sdk/integrations/dramatiq.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sentry_sdk
55
from sentry_sdk.api import continue_trace, get_baggage, get_traceparent
66
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
7-
from sentry_sdk.integrations import DidNotEnable, Integration
7+
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
88
from sentry_sdk.integrations._wsgi_common import request_body_within_bounds
99
from sentry_sdk.traces import SegmentNameSource
1010
from sentry_sdk.tracing import (
@@ -17,11 +17,13 @@
1717
AnnotatedValue,
1818
capture_internal_exceptions,
1919
event_from_exception,
20+
parse_version,
2021
)
2122

2223
R = TypeVar("R")
2324

2425
try:
26+
from dramatiq import __version__ as DRAMATIQ_VERSION
2527
from dramatiq.broker import Broker
2628
from dramatiq.errors import Retry
2729
from dramatiq.message import Message
@@ -54,6 +56,9 @@ class DramatiqIntegration(Integration):
5456

5557
@staticmethod
5658
def setup_once() -> None:
59+
version = parse_version(DRAMATIQ_VERSION)
60+
_check_minimum_version(DramatiqIntegration, version)
61+
5762
_patch_dramatiq_broker()
5863

5964

sentry_sdk/integrations/fastapi.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import sentry_sdk
77
from sentry_sdk.consts import SPANDATA
8-
from sentry_sdk.integrations import DidNotEnable
8+
from sentry_sdk.integrations import DidNotEnable, _check_minimum_version
99
from sentry_sdk.traces import StreamedSpan, get_current_span
1010
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
1111
from sentry_sdk.tracing_utils import has_span_streaming_enabled
12-
from sentry_sdk.utils import transaction_from_function
12+
from sentry_sdk.utils import parse_version, transaction_from_function
1313

1414
if TYPE_CHECKING:
1515
from typing import Any, Awaitable, Callable, Dict
@@ -27,6 +27,7 @@
2727

2828
try:
2929
import fastapi # type: ignore
30+
from fastapi import __version__ as FASTAPI_VERSION
3031
except ImportError:
3132
raise DidNotEnable("FastAPI is not installed")
3233

@@ -46,6 +47,9 @@ class FastApiIntegration(StarletteIntegration):
4647

4748
@staticmethod
4849
def setup_once() -> None:
50+
version = parse_version(FASTAPI_VERSION)
51+
_check_minimum_version(FastApiIntegration, version)
52+
4953
patch_get_request_handler()
5054

5155

sentry_sdk/integrations/google_genai/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
import sentry_sdk
1111
from sentry_sdk.ai.utils import get_start_span_function
1212
from sentry_sdk.consts import OP, SPANDATA
13-
from sentry_sdk.integrations import DidNotEnable, Integration
13+
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
1414
from sentry_sdk.traces import SpanStatus, StreamedSpan
1515
from sentry_sdk.tracing import SPANSTATUS
1616
from sentry_sdk.tracing_utils import has_span_streaming_enabled
17+
from sentry_sdk.utils import parse_version
1718

1819
try:
20+
from google.genai import __version__ as GOOGLE_GENAI_VERSION
1921
from google.genai.models import AsyncModels, Models
2022
except ImportError:
2123
raise DidNotEnable("google-genai not installed")
@@ -46,6 +48,9 @@ def __init__(self: "GoogleGenAIIntegration", include_prompts: bool = True) -> No
4648

4749
@staticmethod
4850
def setup_once() -> None:
51+
version = parse_version(GOOGLE_GENAI_VERSION)
52+
_check_minimum_version(GoogleGenAIIntegration, version)
53+
4954
# Patch sync methods
5055
Models.generate_content = _wrap_generate_content(Models.generate_content)
5156
Models.generate_content_stream = _wrap_generate_content_stream(

sentry_sdk/integrations/graphene.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
ensure_integration_enabled,
1111
event_from_exception,
1212
has_data_collection_enabled,
13-
package_version,
13+
parse_version,
1414
)
1515

1616
try:
17+
from graphene import __version__ as GRAPHENE_VERSION # type: ignore
1718
from graphene.types import schema as graphene_schema # type: ignore
1819
except ImportError:
1920
raise DidNotEnable("graphene is not installed")
@@ -36,7 +37,7 @@ class GrapheneIntegration(Integration):
3637

3738
@staticmethod
3839
def setup_once() -> None:
39-
version = package_version("graphene")
40+
version = parse_version(GRAPHENE_VERSION)
4041
_check_minimum_version(GrapheneIntegration, version)
4142

4243
_patch_graphql()

0 commit comments

Comments
 (0)