root: replace django-silk with Spotlight (#7828)

* root: replace django-silk with Spotlight

https://spotlightjs.com/
Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* use containerized spotlight

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix lock

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* update spotlight version

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* remove platform

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix lint

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2024-01-11 12:33:31 +01:00 committed by GitHub
parent 7ea3830e56
commit 38e1ad5ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 48 additions and 70 deletions

View File

@ -35,6 +35,7 @@ updates:
sentry: sentry:
patterns: patterns:
- "@sentry/*" - "@sentry/*"
- "@spotlightjs/*"
babel: babel:
patterns: patterns:
- "@babel/*" - "@babel/*"
@ -66,6 +67,7 @@ updates:
sentry: sentry:
patterns: patterns:
- "@sentry/*" - "@sentry/*"
- "@spotlightjs/*"
babel: babel:
patterns: patterns:
- "@babel/*" - "@babel/*"

View File

@ -61,9 +61,6 @@ IGNORED_MODELS = (
def should_log_model(model: Model) -> bool: def should_log_model(model: Model) -> bool:
"""Return true if operation on `model` should be logged""" """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 return model.__class__ not in IGNORED_MODELS

View File

@ -94,7 +94,6 @@ def get_logger_config():
"kubernetes": "INFO", "kubernetes": "INFO",
"asyncio": "WARNING", "asyncio": "WARNING",
"redis": "WARNING", "redis": "WARNING",
"silk": "INFO",
"fsevents": "WARNING", "fsevents": "WARNING",
"uvicorn": "WARNING", "uvicorn": "WARNING",
"gunicorn": "INFO", "gunicorn": "INFO",

View File

@ -60,6 +60,8 @@ def sentry_init(**sentry_init_kwargs):
}, },
} }
kwargs.update(**sentry_init_kwargs) kwargs.update(**sentry_init_kwargs)
if settings.DEBUG:
kwargs["spotlight"] = True
# pylint: disable=abstract-class-instantiated # pylint: disable=abstract-class-instantiated
sentry_sdk_init( sentry_sdk_init(
dsn=CONFIG.get("error_reporting.sentry_dsn"), dsn=CONFIG.get("error_reporting.sentry_dsn"),

View File

@ -415,8 +415,6 @@ _update_settings("data.user_settings")
if DEBUG: if DEBUG:
CELERY["task_always_eager"] = True CELERY["task_always_eager"] = True
os.environ[ENV_GIT_HASH_KEY] = "dev" os.environ[ENV_GIT_HASH_KEY] = "dev"
INSTALLED_APPS.append("silk")
MIDDLEWARE = ["silk.middleware.SilkyMiddleware"] + MIDDLEWARE
REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"].append( REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"].append(
"rest_framework.renderers.BrowsableAPIRenderer" "rest_framework.renderers.BrowsableAPIRenderer"
) )

View File

@ -1,5 +1,4 @@
"""authentik URL Configuration""" """authentik URL Configuration"""
from django.conf import settings
from django.urls import include, path from django.urls import include, path
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
@ -48,8 +47,3 @@ urlpatterns += [
path("-/health/live/", LiveView.as_view(), name="health-live"), path("-/health/live/", LiveView.as_view(), name="health-live"),
path("-/health/ready/", ReadyView.as_view(), name="health-ready"), path("-/health/ready/", ReadyView.as_view(), name="health-ready"),
] ]
if settings.DEBUG:
urlpatterns += [
path("debug/silk/", include("silk.urls", namespace="silk")),
]

55
poetry.lock generated
View File

@ -326,20 +326,6 @@ six = "*"
[package.extras] [package.extras]
visualize = ["Twisted (>=16.1.1)", "graphviz (>0.5.1)"] 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]] [[package]]
name = "bandit" name = "bandit"
version = "1.7.6" version = "1.7.6"
@ -1201,23 +1187,6 @@ redis = ">=3,<4.0.0 || >4.0.0,<4.0.1 || >4.0.1"
[package.extras] [package.extras]
hiredis = ["redis[hiredis] (>=3,!=4.0.0,!=4.0.1)"] 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]] [[package]]
name = "djangorestframework" name = "djangorestframework"
version = "3.14.0" version = "3.14.0"
@ -1585,17 +1554,6 @@ pyopenssl = ["cryptography (>=38.0.3)", "pyopenssl (>=20.0.0)"]
reauth = ["pyu2f (>=0.1.5)"] reauth = ["pyu2f (>=0.1.5)"]
requests = ["requests (>=2.20.0,<3.0.0.dev0)"] 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]] [[package]]
name = "gunicorn" name = "gunicorn"
version = "21.2.0" version = "21.2.0"
@ -2719,17 +2677,6 @@ files = [
[package.dependencies] [package.dependencies]
pyasn1 = ">=0.4.6,<0.6.0" 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]] [[package]]
name = "pycparser" name = "pycparser"
version = "2.21" version = "2.21"
@ -4542,4 +4489,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "~3.12" python-versions = "~3.12"
content-hash = "9d28b9e79139895839ffcba88e2eaad0f842a15888f3f6f8c0ac8879616ac850" content-hash = "6dcbc2c6d02643a72285e075528ec0841b9c8fda244632386ec19efb7350d4cd"

View File

@ -185,7 +185,6 @@ bump2version = "*"
colorama = "*" colorama = "*"
coverage = { extras = ["toml"], version = "*" } coverage = { extras = ["toml"], version = "*" }
debugpy = "*" debugpy = "*"
django-silk = "*"
drf-jsonschema-serializer = "*" drf-jsonschema-serializer = "*"
freezegun = "*" freezegun = "*"
importlib-metadata = "*" importlib-metadata = "*"

View File

@ -18,6 +18,11 @@ services:
ports: ports:
- 127.0.0.1:6379:6379 - 127.0.0.1:6379:6379
restart: always restart: always
spotlight:
image: ghcr.io/getsentry/spotlight
ports:
- 127.0.0.1:8969:8969
restart: always
volumes: volumes:
db-data: db-data:

29
web/package-lock.json generated
View File

@ -62,6 +62,7 @@
"@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6", "@rollup/plugin-typescript": "^11.1.6",
"@spotlightjs/spotlight": "^1.2.6",
"@storybook/addon-essentials": "^7.6.7", "@storybook/addon-essentials": "^7.6.7",
"@storybook/addon-links": "^7.6.7", "@storybook/addon-links": "^7.6.7",
"@storybook/api": "^7.6.7", "@storybook/api": "^7.6.7",
@ -4853,6 +4854,34 @@
"integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==",
"dev": true "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": { "node_modules/@storybook/addon-actions": {
"version": "7.6.7", "version": "7.6.7",
"resolved": "https://registry.npmjs.org/@storybook/addon-actions/-/addon-actions-7.6.7.tgz", "resolved": "https://registry.npmjs.org/@storybook/addon-actions/-/addon-actions-7.6.7.tgz",

View File

@ -87,13 +87,14 @@
"@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6", "@rollup/plugin-typescript": "^11.1.6",
"@spotlightjs/spotlight": "^1.2.6",
"@storybook/addon-essentials": "^7.6.7", "@storybook/addon-essentials": "^7.6.7",
"@storybook/addon-links": "^7.6.7", "@storybook/addon-links": "^7.6.7",
"@storybook/api": "^7.6.7", "@storybook/api": "^7.6.7",
"@storybook/blocks": "^7.6.4", "@storybook/blocks": "^7.6.4",
"@storybook/manager-api": "^7.6.7", "@storybook/manager-api": "^7.6.7",
"@storybook/web-components": "^7.6.7",
"@storybook/web-components-vite": "^7.6.7", "@storybook/web-components-vite": "^7.6.7",
"@storybook/web-components": "^7.6.7",
"@trivago/prettier-plugin-sort-imports": "^4.3.0", "@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/chart.js": "^2.9.41", "@types/chart.js": "^2.9.41",
"@types/codemirror": "5.60.15", "@types/codemirror": "5.60.15",
@ -104,12 +105,12 @@
"babel-plugin-macros": "^3.1.0", "babel-plugin-macros": "^3.1.0",
"babel-plugin-tsconfig-paths": "^1.0.3", "babel-plugin-tsconfig-paths": "^1.0.3",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^8.56.0",
"eslint-config-google": "^0.14.0", "eslint-config-google": "^0.14.0",
"eslint-plugin-custom-elements": "0.0.8", "eslint-plugin-custom-elements": "0.0.8",
"eslint-plugin-lit": "^1.11.0", "eslint-plugin-lit": "^1.11.0",
"eslint-plugin-sonarjs": "^0.23.0", "eslint-plugin-sonarjs": "^0.23.0",
"eslint-plugin-storybook": "^0.6.15", "eslint-plugin-storybook": "^0.6.15",
"eslint": "^8.56.0",
"lit-analyzer": "^2.0.3", "lit-analyzer": "^2.0.3",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^3.1.1", "prettier": "^3.1.1",

View File

@ -5,7 +5,7 @@ import { me } from "@goauthentik/common/users";
import * as Sentry from "@sentry/browser"; import * as Sentry from "@sentry/browser";
import { Integrations } from "@sentry/tracing"; 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_COMPONENT = "authentik.component";
export const TAG_SENTRY_CAPABILITIES = "authentik.capabilities"; export const TAG_SENTRY_CAPABILITIES = "authentik.capabilities";
@ -60,6 +60,11 @@ export async function configureSentry(canDoPpi = false): Promise<Config> {
scope.setTransactionName(`authentik.web.if.${currentInterface()}`), 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) { if (cfg.errorReporting.sendPii && canDoPpi) {
me().then((user) => { me().then((user) => {
Sentry.setUser({ email: user.user.email }); Sentry.setUser({ email: user.user.email });