Skip to content

Dogfood Python SDK 3.0.0 alpha #91614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements-base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--index-url https://pypi.devinfra.sentry.io/simple

anton-testing-deleteme-123==3.0.0a1
beautifulsoup4>=4.7.1
boto3>=1.34.128
botocore>=1.34.8
Expand Down
7 changes: 7 additions & 0 deletions requirements-dev-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--index-url https://pypi.devinfra.sentry.io/simple

amqp==5.3.1
anton-testing-deleteme-123==3.0.0a1
anyio==3.7.1
asgiref==3.8.1
attrs==24.2.0
Expand Down Expand Up @@ -37,6 +38,7 @@ cryptography==44.0.1
cssselect==1.0.3
cssutils==2.9.0
datadog==0.49.1
deprecated==1.2.18
devservices==1.1.5
distlib==0.3.8
distro==1.8.0
Expand Down Expand Up @@ -82,6 +84,7 @@ httpx==0.25.2
hyperframe==6.1.0
identify==2.6.1
idna==3.7
importlib-metadata==8.6.1
inflection==0.5.1
iniconfig==1.1.1
iso3166==2.1.1
Expand Down Expand Up @@ -114,6 +117,9 @@ openapi-core==0.18.2
openapi-pydantic==0.4.0
openapi-schema-validator==0.6.2
openapi-spec-validator==0.7.1
opentelemetry-api==1.33.1
opentelemetry-sdk==1.33.1
opentelemetry-semantic-conventions==0.54b1
orjson==3.10.10
outcome==1.2.0
packaging==24.1
Expand Down Expand Up @@ -248,6 +254,7 @@ wheel==0.38.4
wrapt==1.17.0
wsproto==1.1.0
xmlsec==1.3.14
zipp==3.21.0
zstandard==0.18.0

# The following packages are considered to be unsafe in a requirements file:
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--index-url https://pypi.devinfra.sentry.io/simple

anton-testing-deleteme-123==3.0.0a1
sentry-devenv>=1.20
devservices>=1.1.5

Expand Down
8 changes: 8 additions & 0 deletions requirements-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--index-url https://pypi.devinfra.sentry.io/simple

amqp==5.3.1
anton-testing-deleteme-123==3.0.0a1
anyio==3.7.1
asgiref==3.8.1
attrs==24.2.0
Expand All @@ -32,6 +33,7 @@ cryptography==44.0.1
cssselect==1.0.3
cssutils==2.9.0
datadog==0.49.1
deprecated==1.2.18
distro==1.8.0
django==5.2.1
django-crispy-forms==1.14.0
Expand Down Expand Up @@ -67,6 +69,7 @@ httpcore==1.0.2
httpx==0.25.2
hyperframe==6.1.0
idna==3.7
importlib-metadata==8.6.1
inflection==0.5.1
iso3166==2.1.1
isodate==0.6.1
Expand All @@ -82,6 +85,9 @@ mmh3==4.0.0
msgpack==1.1.0
oauthlib==3.1.0
openai==1.3.5
opentelemetry-api==1.33.1
opentelemetry-sdk==1.33.1
opentelemetry-semantic-conventions==0.54b1
orjson==3.10.10
packaging==24.1
parsimonious==0.10.0
Expand Down Expand Up @@ -156,7 +162,9 @@ urllib3==2.2.2
vine==5.1.0
vroomrs==0.1.4
wcwidth==0.2.10
wrapt==1.17.2
xmlsec==1.3.14
zipp==3.21.0
zstandard==0.18.0

# The following packages are considered to be unsafe in a requirements file:
Expand Down
22 changes: 12 additions & 10 deletions src/sentry/api/endpoints/warmup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import django.contrib.messages.storage.fallback
import django.contrib.sessions.serializers
import django.db.models.sql.compiler # NOQA
import logging

import sentry_sdk
from django.conf import settings
from django.urls import reverse
from django.utils import translation
from rest_framework.request import Request
from rest_framework.response import Response
from sentry_sdk.consts import VERSION as SDK_VERSION

import sentry.identity.services.identity.impl # NOQA
import sentry.integrations.services.integration.impl # NOQA
import sentry.middleware.integrations.parsers.plugin # NOQA
import sentry.notifications.services.impl # NOQA
import sentry.sentry_apps.services.app.impl # NOQA
import sentry.users.services.user.impl # NOQA
import sentry.users.services.user_option.impl # NOQA
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import Endpoint, all_silo_endpoint
from sentry.ratelimits.config import RateLimitConfig

logger = logging.getLogger(__name__)


@all_silo_endpoint
class WarmupEndpoint(Endpoint):
Expand All @@ -30,6 +26,12 @@ class WarmupEndpoint(Endpoint):
rate_limits = RateLimitConfig(group="INTERNAL")

def get(self, request: Request) -> Response:
logger.warning("xxxxxxxxxxxxxxxxxx")
logger.warning(sentry_sdk)
logger.warning("yyyyyyyyyyyyyyyyyy")
logger.warning(SDK_VERSION)
logger.warning("zzzzzzzzzzzzzzzz")

languages = [lang for lang, _ in settings.LANGUAGES]
languages.append(settings.LANGUAGE_CODE)

Expand Down
4 changes: 4 additions & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,10 @@
default=False,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)
# Gradually roll out Python SDK alpha version for dogfooding
register(
"sentry-sdk.use-python-sdk-alpha", default=1.0, type=Float, flags=FLAG_AUTOMATOR_MODIFIABLE
)

register(
# Lists the shared resource ids we want to account usage for.
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/runner/commands/devserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import NoReturn

import click
import sentry_sdk

from sentry.runner.commands.devservices import get_docker_client
from sentry.runner.decorators import configuration, log_options
Expand Down Expand Up @@ -174,6 +173,8 @@ def devserver(
taskworker_scheduler: bool,
) -> NoReturn:
"Starts a lightweight web server for development."
import sentry_sdk

sentry_sdk.init(
dsn=os.environ.get("SENTRY_DEVSERVICES_DSN", ""),
traces_sample_rate=1.0,
Expand Down
45 changes: 45 additions & 0 deletions src/sentry/runner/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import click
from django.conf import settings

from sentry.options.rollout import in_random_rollout
from sentry.silo.patches.silo_aware_transaction_patch import patch_silo_aware_atomic
from sentry.utils import warnings
from sentry.utils.sdk import configure_sdk
Expand Down Expand Up @@ -373,6 +374,8 @@ def initialize_app(config: dict[str, Any], skip_service_validation: bool = False

bind_cache_to_option_store()

redirect_imports_for_sentry_sdk_alpha()

register_plugins(settings)

initialize_receivers()
Expand Down Expand Up @@ -701,3 +704,45 @@ def import_grouptype() -> None:
from sentry.issues.grouptype import import_grouptype

import_grouptype()


def redirect_imports_for_sentry_sdk_alpha():
"""
Patch the Python import system to redirect imports of sentry_sdk to sentry_sdk_alpha based on a Sentry option.
This allows us to gradually roll out the alpha version of the SDK to a subset of users.
"""

class ImportRedirector(importlib.abc.MetaPathFinder, importlib.abc.Loader):
def __init__(self, original_module, target_module):
self.original_module = original_module
self.target_module = target_module

def find_spec(self, fullname, path, target=None):
if fullname == self.original_module:
# Create a spec for the target module
spec = importlib.machinery.ModuleSpec(
fullname,
self,
origin=f"redirected from {self.original_module} to {self.target_module}",
)
return spec
return None

def create_module(self, spec):
return importlib.import_module(self.target_module)

def exec_module(self, module):
pass

def redirect_import(original_module, target_module):
redirector = ImportRedirector(original_module, target_module)
sys.meta_path.insert(0, redirector)
# TODO: Not sure the original module should be deleted....
# iterating over a copy to be able to delete from the original
for cached_module in sys.modules.copy():
if cached_module.startswith(original_module):
# cleaning up cache if the module is already imported
del sys.modules[cached_module]

if in_random_rollout("sentry-sdk.use-python-sdk-alpha"):
redirect_import("sentry_sdk", "sentry_sdk_alpha")
Comment on lines +747 to +748
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options can't / shouldn't be used at import time (as they require a database call)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not to mention they won't be reflected upon update -- as they will be read exactly once during startup and then never again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, noted. I will try something.

4 changes: 3 additions & 1 deletion src/sentry/utils/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ def configure_sdk():
"""
Setup and initialize the Sentry SDK.
"""
import sentry_sdk

sdk_options, dsns = _get_sdk_options()
if settings.SPOTLIGHT:
sdk_options["spotlight"] = (
Expand Down Expand Up @@ -486,7 +488,7 @@ def flush(
LoggingIntegration(event_level=None, sentry_logs_level=logging.INFO),
RustInfoIntegration(),
RedisIntegration(),
ThreadingIntegration(propagate_hub=True),
ThreadingIntegration(),
],
**sdk_options,
)
Expand Down
Loading