feat: Sentry in the API, the worker, the Site and the Kanban (off until the DSNs are set)

app/observability.py starts sentry-sdk for the API and the worker when
SENTRY_DSN_API is set, with send_default_pii off and a scrub that strips
cookies, tokens, bodies, CPF/CNPJ and e-mails. The browser loads the
official Sentry bundle from our own origin (web/vendor, provenance in its
README) and starts with SENTRY_DSN_WEB from /api/session or
/api/operator/me; every failed API answer the customer or the team gets is
reported with its path, status and message, never the request body. The
CSP allows Blyzer's Sentry ingest host.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 14:48:01 -03:00
parent 07515abbd8
commit 457ed4cbdf
23 changed files with 457 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ changes it in "Minha senha". The superadmin is the system's own account, set fro
administrators manage everyone else. Nobody can remove, disable or demote
themselves, so the last administrator cannot lock the team out by accident.
"""
import os
import re
from decimal import Decimal
from typing import Literal
@@ -18,7 +19,7 @@ from ..core import db
from ..core.auth import (CAPABILITIES, MACHINE_QUESTION, audit, can, may_move, may_reorder, password_hash,
password_matches, signed_in)
from ..core.models import StrictModel
from ..runtime import BACK, STATES, TRANSITIONS
from ..runtime import BACK, ENVIRONMENT, STATES, TRANSITIONS
router = APIRouter()
@@ -68,6 +69,10 @@ def me(request: Request):
moves = [[a, b] for a, nexts in TRANSITIONS.items() for b in nexts if may_move(role, a, b)]
moves += [[a, b] for a, b in BACK.items() if may_move(role, a, b, back=True)]
return {'email': account['email'], 'name': account['name'], 'role': role,
# Public by design: the Kanban browser initialises Sentry with these.
'sentry_dsn_web': os.environ.get('SENTRY_DSN_WEB', '').strip(),
'sentry_environment': os.environ.get('SENTRY_ENVIRONMENT') or ENVIRONMENT,
'sentry_release': os.environ.get('IMAGE_TAG', ''),
# The machine this session is on, and whether to ask (item 12).
'machine': account['machine'], 'machine_question': MACHINE_QUESTION.get(role),
'machine_answered': account['machine_answered'],