def _get_options(*args, **kwargs): # type: (*Optional[str], **Any) -> Dict[str, Any] if args and (isinstance(args[0], (text_type, bytes, str)) or args[0] is None): dsn = args[0] # type: Optional[str] args = args[1:] else: dsn = None rv = dict(DEFAULT_OPTIONS) options = dict(*args, **kwargs) if dsn is not None and options.get("dsn") is None: options["dsn"] = dsn for key, value in iteritems(options): if key not in rv: raise TypeError("Unknown option %r" % (key, )) rv[key] = value if rv["dsn"] is None: rv["dsn"] = os.environ.get("SENTRY_DSN") if rv["release"] is None: rv["release"] = get_default_release() if rv["environment"] is None: rv["environment"] = os.environ.get( "SENTRY_ENVIRONMENT") or "production" if rv["server_name"] is None and hasattr(socket, "gethostname"): rv["server_name"] = socket.gethostname() return rv
import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.utils import get_default_release sentry_kwargs = { "dsn": env["SENTRY_DSN"], "integrations": [DjangoIntegration()], } # There's a chooser to toggle between environments at the top right corner on sentry.io # Values are typically 'staging' or 'production' but can be set to anything else if needed. if "SENTRY_ENVIRONMENT" in env: sentry_kwargs.update({"environment": env["SENTRY_ENVIRONMENT"]}) release = get_default_release() if release is None: try: # But if it's not, we assume that the commit hash is available in # the GIT_REV environment variable. release = env["GIT_REV"] except KeyError: release = None sentry_kwargs.update({"release": release}) sentry_sdk.init(**sentry_kwargs) # Front-end cache # This configuration is used to allow purging pages from cache when they are # published. # These settings are usually used only on the production sites.