Example #1
0
    def ready(self):
        posthoganalytics.api_key = "sTMFPsFhdP1Ssg"
        posthoganalytics.personal_api_key = os.environ.get(
            "POSTHOG_PERSONAL_API_KEY")

        if settings.TEST or os.environ.get("OPT_OUT_CAPTURE", False):
            posthoganalytics.disabled = True
        elif settings.DEBUG:
            # log development server launch to posthog
            if os.getenv("RUN_MAIN") == "true":
                # Sync all organization.available_features once on launch, in case plans changed
                from posthog.celery import sync_all_organization_available_features

                sync_all_organization_available_features()

                posthoganalytics.capture(
                    get_machine_id(),
                    "development server launched",
                    {
                        "posthog_version": VERSION,
                        "git_rev": get_git_commit(),
                        "git_branch": get_git_branch(),
                    },
                )

            if SELF_CAPTURE:
                posthoganalytics.api_key = get_self_capture_api_token(None)
            else:
                posthoganalytics.disabled = True

        if not settings.SKIP_SERVICE_VERSION_REQUIREMENTS:
            for service_version_requirement in settings.SERVICE_VERSION_REQUIREMENTS:
                in_range, version = service_version_requirement.is_service_in_accepted_version(
                )
                if not in_range:
                    print(
                        f"\033[91mService {service_version_requirement.service} is in version {version}. Expected range: {str(service_version_requirement.supported_version)}. PostHog may not work correctly with the current version. To continue anyway, add SKIP_SERVICE_VERSION_REQUIREMENTS=1 as an environment variable\033[0m",
                    )
                    exit(1)

        from posthog.async_migrations.setup import setup_async_migrations

        if SKIP_ASYNC_MIGRATIONS_SETUP:
            print_warning([
                "Skipping async migrations setup. This is unsafe in production!"
            ])
        else:
            setup_async_migrations()
Example #2
0
    return [item.strip() for item in text.split(",")]


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = get_from_env("DEBUG", False, type_cast=str_to_bool)
TEST = (
    "test" in sys.argv or sys.argv[0].endswith("pytest") or get_from_env("TEST", False, type_cast=str_to_bool)
)  # type: bool
E2E_TESTING = get_from_env(
    "E2E_TESTING", False, type_cast=str_to_bool,
)  # whether the app is currently running for E2E tests
if E2E_TESTING:
    print_warning(
        ("️WARNING! E2E_TESTING is set to `True`. This is a security vulnerability unless you are running tests.")
    )

SELF_CAPTURE = get_from_env("SELF_CAPTURE", DEBUG, type_cast=str_to_bool)
SHELL_PLUS_PRINT_SQL = get_from_env("PRINT_SQL", False, type_cast=str_to_bool)
USE_PRECALCULATED_CH_COHORT_PEOPLE = not TEST

SITE_URL = os.getenv("SITE_URL", "http://localhost:8000").rstrip("/")

if DEBUG:
    JS_URL = os.getenv("JS_URL", "http://localhost:8234/")
else:
    JS_URL = os.getenv("JS_URL", "")

DISABLE_MMDB = get_from_env(
    "DISABLE_MMDB", TEST, type_cast=str_to_bool