fix: suppress E2E test sessions from log-based analytics
Add E2E_TEST_USER_ID setting (opt-in via env); session bootstrap logs at DEBUG instead of INFO for the known test user so test runs don't inflate session counts. Still visible with DEBUG=true.
This commit is contained in:
parent
22a3da61c3
commit
8fd77bd1f2
2 changed files with 11 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ import logging
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
|
|
||||||
from app.cloud_session import CloudUser, _auth_label, get_session
|
from app.cloud_session import CloudUser, _auth_label, get_session
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
@ -22,8 +23,13 @@ def session_bootstrap(session: CloudUser = Depends(get_session)) -> dict:
|
||||||
Expected log output:
|
Expected log output:
|
||||||
INFO:app.api.endpoints.session: session auth=authed tier=paid
|
INFO:app.api.endpoints.session: session auth=authed tier=paid
|
||||||
INFO:app.api.endpoints.session: session auth=anon tier=free
|
INFO:app.api.endpoints.session: session auth=anon tier=free
|
||||||
|
|
||||||
|
E2E test sessions (E2E_TEST_USER_ID) are logged at DEBUG so they don't
|
||||||
|
pollute analytics counts while still being visible when DEBUG=true.
|
||||||
"""
|
"""
|
||||||
log.info("session auth=%s tier=%s", _auth_label(session.user_id), session.tier)
|
is_test = bool(settings.E2E_TEST_USER_ID and session.user_id == settings.E2E_TEST_USER_ID)
|
||||||
|
logger = log.debug if is_test else log.info
|
||||||
|
logger("session auth=%s tier=%s%s", _auth_label(session.user_id), session.tier, " e2e=true" if is_test else "")
|
||||||
return {
|
return {
|
||||||
"auth": _auth_label(session.user_id),
|
"auth": _auth_label(session.user_id),
|
||||||
"tier": session.tier,
|
"tier": session.tier,
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,10 @@ class Settings:
|
||||||
# CFOrchClient reads CF_LICENSE_KEY automatically; exposed here for startup validation.
|
# CFOrchClient reads CF_LICENSE_KEY automatically; exposed here for startup validation.
|
||||||
CF_LICENSE_KEY: str | None = os.environ.get("CF_LICENSE_KEY")
|
CF_LICENSE_KEY: str | None = os.environ.get("CF_LICENSE_KEY")
|
||||||
|
|
||||||
|
# E2E test account — analytics logging is suppressed for this user_id so test
|
||||||
|
# runs don't pollute session counts. Set to the Directus UUID of the test user.
|
||||||
|
E2E_TEST_USER_ID: str | None = os.environ.get("E2E_TEST_USER_ID") or None
|
||||||
|
|
||||||
# Feature flags
|
# Feature flags
|
||||||
ENABLE_OCR: bool = os.environ.get("ENABLE_OCR", "false").lower() in ("1", "true", "yes")
|
ENABLE_OCR: bool = os.environ.get("ENABLE_OCR", "false").lower() in ("1", "true", "yes")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue