Skip to content

Commit

Permalink
feat: sentry mode (#80342)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarli authored Nov 12, 2024
1 parent 1b84fa6 commit bd027df
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from sentry.conf.types.logging_config import LoggingConfig
from sentry.conf.types.role_dict import RoleDict
from sentry.conf.types.sdk_config import ServerSdkConfig
from sentry.conf.types.sentry_config import SentryMode
from sentry.utils import json # NOQA (used in getsentry config)
from sentry.utils.celery import crontab_with_minute_jitter, make_split_task_queues
from sentry.utils.types import Type, type_from_value
Expand Down Expand Up @@ -672,6 +673,10 @@ def SOCIAL_AUTH_DEFAULT_USERNAME() -> str:
# Which silo this instance runs as (CONTROL|REGION|MONOLITH|None) are the expected values
SILO_MODE = os.environ.get("SENTRY_SILO_MODE", None)

# This supersedes SENTRY_SINGLE_TENANT and SENTRY_SELF_HOSTED.
# An enum is better because there shouldn't be multiple "modes".
SENTRY_MODE = SentryMode.SELF_HOSTED

# If this instance is a region silo, which region is it running in?
SENTRY_REGION = os.environ.get("SENTRY_REGION", None)

Expand Down Expand Up @@ -1464,6 +1469,7 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
}

CRISPY_TEMPLATE_PACK = "bootstrap3"

# Sentry and internal client configuration

SENTRY_EARLY_FEATURES = {
Expand Down Expand Up @@ -2480,7 +2486,9 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
STATUS_PAGE_ID: str | None = None
STATUS_PAGE_API_HOST = "statuspage.io"

SENTRY_SELF_HOSTED = True
# For compatibility only. Prefer using SENTRY_MODE.
SENTRY_SELF_HOSTED = SENTRY_MODE == SentryMode.SELF_HOSTED

SENTRY_SELF_HOSTED_ERRORS_ONLY = False
# only referenced in getsentry to provide the stable beacon version
# updated with scripts/bump-version.sh
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/conf/types/sentry_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from enum import StrEnum

SentryMode = StrEnum("SentryMode", ("SELF_HOSTED", "SINGLE_TENANT", "SAAS"))
3 changes: 3 additions & 0 deletions src/sentry/web/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ def get_context(self) -> Mapping[str, Any]:
"isOnPremise": is_self_hosted(),
"isSelfHosted": is_self_hosted(),
"isSelfHostedErrorsOnly": is_self_hosted_errors_only(),
# sentryMode intends to supersede isSelfHosted,
# so we can differentiate between "SELF_HOSTED", "SINGLE_TENANT", and "SAAS".
"sentryMode": settings.SENTRY_MODE.name,
"shouldPreloadData": self.should_preload_data,
"shouldShowBeaconConsentPrompt": not self.needs_upgrade
and should_show_beacon_consent_prompt(),
Expand Down
3 changes: 3 additions & 0 deletions static/app/types/system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ export interface Config {
environment?: string;
profilesSampleRate?: number;
};
// sentryMode intends to supersede isSelfHosted,
// so we can differentiate between "SELF_HOSTED", "SINGLE_TENANT", and "SAAS".
sentryMode: 'SELF_HOSTED' | 'SINGLE_TENANT' | 'SAAS';
shouldPreloadData: boolean;
singleOrganization: boolean;
superUserCookieDomain: string | null;
Expand Down
1 change: 1 addition & 0 deletions tests/js/fixtures/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function ConfigFixture(params: Partial<Config> = {}): Config {
isOnPremise: false,
isSelfHosted: false,
isSelfHostedErrorsOnly: false,
sentryMode: 'SAAS',
lastOrganization: null,
gravatarBaseUrl: 'https://gravatar.com',
initialTrace: {
Expand Down
7 changes: 7 additions & 0 deletions tests/sentry/web/test_client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ def clear_env_request():
)


@no_silo_test
@django_db_all
def test_client_config_default():
cfg = get_client_config()
assert cfg["sentryMode"] == "SELF_HOSTED"


@multiregion_client_config_test
@pytest.mark.parametrize(
"request_factory",
Expand Down

0 comments on commit bd027df

Please sign in to comment.