diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5aacf8ef6..400300236 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -35,6 +35,7 @@ updates: sentry: patterns: - "@sentry/*" + - "@spotlightjs/*" babel: patterns: - "@babel/*" @@ -66,6 +67,7 @@ updates: sentry: patterns: - "@sentry/*" + - "@spotlightjs/*" babel: patterns: - "@babel/*" diff --git a/authentik/events/middleware.py b/authentik/events/middleware.py index ea7e6001f..9843402ab 100644 --- a/authentik/events/middleware.py +++ b/authentik/events/middleware.py @@ -61,9 +61,6 @@ IGNORED_MODELS = ( def should_log_model(model: Model) -> bool: """Return true if operation on `model` should be logged""" - # Check for silk by string so this comparison doesn't fail when silk isn't installed - if model.__module__.startswith("silk"): - return False return model.__class__ not in IGNORED_MODELS diff --git a/authentik/lib/logging.py b/authentik/lib/logging.py index 682475230..174db6828 100644 --- a/authentik/lib/logging.py +++ b/authentik/lib/logging.py @@ -94,7 +94,6 @@ def get_logger_config(): "kubernetes": "INFO", "asyncio": "WARNING", "redis": "WARNING", - "silk": "INFO", "fsevents": "WARNING", "uvicorn": "WARNING", "gunicorn": "INFO", diff --git a/authentik/lib/sentry.py b/authentik/lib/sentry.py index 6ea34625e..e760173ce 100644 --- a/authentik/lib/sentry.py +++ b/authentik/lib/sentry.py @@ -60,6 +60,8 @@ def sentry_init(**sentry_init_kwargs): }, } kwargs.update(**sentry_init_kwargs) + if settings.DEBUG: + kwargs["spotlight"] = True # pylint: disable=abstract-class-instantiated sentry_sdk_init( dsn=CONFIG.get("error_reporting.sentry_dsn"), diff --git a/authentik/root/settings.py b/authentik/root/settings.py index 87d4bde9f..038d6af8f 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -415,8 +415,6 @@ _update_settings("data.user_settings") if DEBUG: CELERY["task_always_eager"] = True os.environ[ENV_GIT_HASH_KEY] = "dev" - INSTALLED_APPS.append("silk") - MIDDLEWARE = ["silk.middleware.SilkyMiddleware"] + MIDDLEWARE REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"].append( "rest_framework.renderers.BrowsableAPIRenderer" ) diff --git a/authentik/root/urls.py b/authentik/root/urls.py index e1874a041..b3913090a 100644 --- a/authentik/root/urls.py +++ b/authentik/root/urls.py @@ -1,5 +1,4 @@ """authentik URL Configuration""" -from django.conf import settings from django.urls import include, path from structlog.stdlib import get_logger @@ -48,8 +47,3 @@ urlpatterns += [ path("-/health/live/", LiveView.as_view(), name="health-live"), path("-/health/ready/", ReadyView.as_view(), name="health-ready"), ] - -if settings.DEBUG: - urlpatterns += [ - path("debug/silk/", include("silk.urls", namespace="silk")), - ] diff --git a/poetry.lock b/poetry.lock index 36d7986d7..de004f161 100644 --- a/poetry.lock +++ b/poetry.lock @@ -326,20 +326,6 @@ six = "*" [package.extras] visualize = ["Twisted (>=16.1.1)", "graphviz (>0.5.1)"] -[[package]] -name = "autopep8" -version = "2.0.4" -description = "A tool that automatically formats Python code to conform to the PEP 8 style guide" -optional = false -python-versions = ">=3.6" -files = [ - {file = "autopep8-2.0.4-py2.py3-none-any.whl", hash = "sha256:067959ca4a07b24dbd5345efa8325f5f58da4298dab0dde0443d5ed765de80cb"}, - {file = "autopep8-2.0.4.tar.gz", hash = "sha256:2913064abd97b3419d1cc83ea71f042cb821f87e45b9c88cad5ad3c4ea87fe0c"}, -] - -[package.dependencies] -pycodestyle = ">=2.10.0" - [[package]] name = "bandit" version = "1.7.6" @@ -1201,23 +1187,6 @@ redis = ">=3,<4.0.0 || >4.0.0,<4.0.1 || >4.0.1" [package.extras] hiredis = ["redis[hiredis] (>=3,!=4.0.0,!=4.0.1)"] -[[package]] -name = "django-silk" -version = "5.0.4" -description = "Silky smooth profiling for the Django Framework" -optional = false -python-versions = ">=3.8" -files = [ - {file = "django-silk-5.0.4.tar.gz", hash = "sha256:8cbfbc647d182527726d8d52d3fcfa193f4d250f21406c3fb1062efa6fb95c63"}, - {file = "django_silk-5.0.4-py3-none-any.whl", hash = "sha256:b345d3973d1d382e09735eb525eaf3eebd3edee9a69d1003eb9b01badb2438db"}, -] - -[package.dependencies] -autopep8 = "*" -Django = ">=3.2" -gprof2dot = ">=2017.09.19" -sqlparse = "*" - [[package]] name = "djangorestframework" version = "3.14.0" @@ -1585,17 +1554,6 @@ pyopenssl = ["cryptography (>=38.0.3)", "pyopenssl (>=20.0.0)"] reauth = ["pyu2f (>=0.1.5)"] requests = ["requests (>=2.20.0,<3.0.0.dev0)"] -[[package]] -name = "gprof2dot" -version = "2022.7.29" -description = "Generate a dot graph from the output of several profilers." -optional = false -python-versions = ">=2.7" -files = [ - {file = "gprof2dot-2022.7.29-py2.py3-none-any.whl", hash = "sha256:f165b3851d3c52ee4915eb1bd6cca571e5759823c2cd0f71a79bda93c2dc85d6"}, - {file = "gprof2dot-2022.7.29.tar.gz", hash = "sha256:45b4d298bd36608fccf9511c3fd88a773f7a1abc04d6cd39445b11ba43133ec5"}, -] - [[package]] name = "gunicorn" version = "21.2.0" @@ -2719,17 +2677,6 @@ files = [ [package.dependencies] pyasn1 = ">=0.4.6,<0.6.0" -[[package]] -name = "pycodestyle" -version = "2.11.1" -description = "Python style guide checker" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pycodestyle-2.11.1-py2.py3-none-any.whl", hash = "sha256:44fe31000b2d866f2e41841b18528a505fbd7fef9017b04eff4e2648a0fadc67"}, - {file = "pycodestyle-2.11.1.tar.gz", hash = "sha256:41ba0e7afc9752dfb53ced5489e89f8186be00e599e712660695b7a75ff2663f"}, -] - [[package]] name = "pycparser" version = "2.21" @@ -4542,4 +4489,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "~3.12" -content-hash = "9d28b9e79139895839ffcba88e2eaad0f842a15888f3f6f8c0ac8879616ac850" +content-hash = "6dcbc2c6d02643a72285e075528ec0841b9c8fda244632386ec19efb7350d4cd" diff --git a/pyproject.toml b/pyproject.toml index ec1610a09..e38b0bdbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -185,7 +185,6 @@ bump2version = "*" colorama = "*" coverage = { extras = ["toml"], version = "*" } debugpy = "*" -django-silk = "*" drf-jsonschema-serializer = "*" freezegun = "*" importlib-metadata = "*" diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml index 658d7a0db..cd25d145f 100644 --- a/scripts/docker-compose.yml +++ b/scripts/docker-compose.yml @@ -18,6 +18,11 @@ services: ports: - 127.0.0.1:6379:6379 restart: always + spotlight: + image: ghcr.io/getsentry/spotlight + ports: + - 127.0.0.1:8969:8969 + restart: always volumes: db-data: diff --git a/web/package-lock.json b/web/package-lock.json index 106c602dd..0129f0b05 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -62,6 +62,7 @@ "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^11.1.6", + "@spotlightjs/spotlight": "^1.2.6", "@storybook/addon-essentials": "^7.6.7", "@storybook/addon-links": "^7.6.7", "@storybook/api": "^7.6.7", @@ -4853,6 +4854,34 @@ "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", "dev": true }, + "node_modules/@spotlightjs/overlay": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@spotlightjs/overlay/-/overlay-1.2.3.tgz", + "integrity": "sha512-JypKrZCXGYp7PbLRTi6phBeMXvHP3ulaZVC829rpg+69tcaUXoGmgkjXDNxgrCfFE+xvi73fZk+bbus45b3C/w==", + "dev": true + }, + "node_modules/@spotlightjs/sidecar": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@spotlightjs/sidecar/-/sidecar-1.3.3.tgz", + "integrity": "sha512-bRxizHcAUQS8H2f2jD/qbCTZA9ftjkCC9mMRwG6YRIkAi/3VRxB6hnhYkP1LnkZK8BQC0YtHmnlr8N2GJfwLhA==", + "dev": true, + "bin": { + "spotlight-sidecar": "server.js" + } + }, + "node_modules/@spotlightjs/spotlight": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@spotlightjs/spotlight/-/spotlight-1.2.6.tgz", + "integrity": "sha512-MjRnzRFk5IZOAUDlkR/ENiB9uAbDlLAgLt4lIrCX0/v8WHwuS1zHMf65G3PjSYWYgjJ14cT98gMJErFVpCWx4g==", + "dev": true, + "dependencies": { + "@spotlightjs/overlay": "1.2.3", + "@spotlightjs/sidecar": "1.3.3" + }, + "bin": { + "spotlight-sidecar": "bin/run.js" + } + }, "node_modules/@storybook/addon-actions": { "version": "7.6.7", "resolved": "https://registry.npmjs.org/@storybook/addon-actions/-/addon-actions-7.6.7.tgz", diff --git a/web/package.json b/web/package.json index bf3c4a617..fc0e9fbfc 100644 --- a/web/package.json +++ b/web/package.json @@ -87,13 +87,14 @@ "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^11.1.6", + "@spotlightjs/spotlight": "^1.2.6", "@storybook/addon-essentials": "^7.6.7", "@storybook/addon-links": "^7.6.7", "@storybook/api": "^7.6.7", "@storybook/blocks": "^7.6.4", "@storybook/manager-api": "^7.6.7", - "@storybook/web-components": "^7.6.7", "@storybook/web-components-vite": "^7.6.7", + "@storybook/web-components": "^7.6.7", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/chart.js": "^2.9.41", "@types/codemirror": "5.60.15", @@ -104,12 +105,12 @@ "babel-plugin-macros": "^3.1.0", "babel-plugin-tsconfig-paths": "^1.0.3", "cross-env": "^7.0.3", - "eslint": "^8.56.0", "eslint-config-google": "^0.14.0", "eslint-plugin-custom-elements": "0.0.8", "eslint-plugin-lit": "^1.11.0", "eslint-plugin-sonarjs": "^0.23.0", "eslint-plugin-storybook": "^0.6.15", + "eslint": "^8.56.0", "lit-analyzer": "^2.0.3", "npm-run-all": "^4.1.5", "prettier": "^3.1.1", diff --git a/web/src/common/sentry.ts b/web/src/common/sentry.ts index f89a35f13..e3dfe3c2f 100644 --- a/web/src/common/sentry.ts +++ b/web/src/common/sentry.ts @@ -5,7 +5,7 @@ import { me } from "@goauthentik/common/users"; import * as Sentry from "@sentry/browser"; import { Integrations } from "@sentry/tracing"; -import { Config, ResponseError } from "@goauthentik/api"; +import { CapabilitiesEnum, Config, ResponseError } from "@goauthentik/api"; export const TAG_SENTRY_COMPONENT = "authentik.component"; export const TAG_SENTRY_CAPABILITIES = "authentik.capabilities"; @@ -60,6 +60,11 @@ export async function configureSentry(canDoPpi = false): Promise { scope.setTransactionName(`authentik.web.if.${currentInterface()}`), ); } + if (cfg.capabilities.includes(CapabilitiesEnum.CanDebug)) { + const Spotlight = await import("@spotlightjs/spotlight"); + + Spotlight.init({ injectImmediately: true }); + } if (cfg.errorReporting.sendPii && canDoPpi) { me().then((user) => { Sentry.setUser({ email: user.user.email });