feat: each error in Sentry names the commit it came from
The API image keeps the commit it was built from (RELEASE, from VCS_REF); the API, the worker and the browser report it as the Sentry release unless the stack sets IMAGE_TAG. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import httpx
|
|||||||
from fastapi import APIRouter, HTTPException, Request, Response
|
from fastapi import APIRouter, HTTPException, Request, Response
|
||||||
|
|
||||||
from ..core import db
|
from ..core import db
|
||||||
from .. import catalog, grade_rules, mail
|
from .. import catalog, grade_rules, mail, observability
|
||||||
from ..core.auth import client_ip, owner, new_session, rate_limit
|
from ..core.auth import client_ip, owner, new_session, rate_limit
|
||||||
from ..core.limits import upload_limit_bytes
|
from ..core.limits import upload_limit_bytes
|
||||||
from ..core.pricing import manual_extra_cents
|
from ..core.pricing import manual_extra_cents
|
||||||
@@ -66,7 +66,7 @@ def session(request: Request, response: Response):
|
|||||||
# Public by design: the browser initialises Sentry with these; empty is off.
|
# Public by design: the browser initialises Sentry with these; empty is off.
|
||||||
'sentry_dsn_web': os.environ.get('SENTRY_DSN_WEB', '').strip(),
|
'sentry_dsn_web': os.environ.get('SENTRY_DSN_WEB', '').strip(),
|
||||||
'sentry_environment': os.environ.get('SENTRY_ENVIRONMENT') or ENVIRONMENT,
|
'sentry_environment': os.environ.get('SENTRY_ENVIRONMENT') or ENVIRONMENT,
|
||||||
'sentry_release': os.environ.get('IMAGE_TAG', ''),
|
'sentry_release': observability.release() or '',
|
||||||
# Public by design: Mercado Pago's card form needs it in the browser.
|
# Public by design: Mercado Pago's card form needs it in the browser.
|
||||||
'payment_public_key': os.environ.get('MP_PUBLIC_KEY', '') if payment.name == 'mercadopago' else '',
|
'payment_public_key': os.environ.get('MP_PUBLIC_KEY', '') if payment.name == 'mercadopago' else '',
|
||||||
# The delivery options the cart quotes, or none: pickup only.
|
# The delivery options the cart quotes, or none: pickup only.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from uuid import UUID, uuid4
|
|||||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||||
from pydantic import Field, field_validator
|
from pydantic import Field, field_validator
|
||||||
|
|
||||||
from .. import machines, mail
|
from .. import machines, mail, observability
|
||||||
from ..core import db
|
from ..core import db
|
||||||
from ..core.auth import (CAPABILITIES, MACHINE_QUESTION, audit, can, may_move, may_reorder, password_hash,
|
from ..core.auth import (CAPABILITIES, MACHINE_QUESTION, audit, can, may_move, may_reorder, password_hash,
|
||||||
password_matches, signed_in)
|
password_matches, signed_in)
|
||||||
@@ -72,7 +72,7 @@ def me(request: Request):
|
|||||||
# Public by design: the Kanban browser initialises Sentry with these.
|
# Public by design: the Kanban browser initialises Sentry with these.
|
||||||
'sentry_dsn_web': os.environ.get('SENTRY_DSN_WEB', '').strip(),
|
'sentry_dsn_web': os.environ.get('SENTRY_DSN_WEB', '').strip(),
|
||||||
'sentry_environment': os.environ.get('SENTRY_ENVIRONMENT') or ENVIRONMENT,
|
'sentry_environment': os.environ.get('SENTRY_ENVIRONMENT') or ENVIRONMENT,
|
||||||
'sentry_release': os.environ.get('IMAGE_TAG', ''),
|
'sentry_release': observability.release() or '',
|
||||||
# The machine this session is on, and whether to ask (item 12).
|
# The machine this session is on, and whether to ask (item 12).
|
||||||
'machine': account['machine'], 'machine_question': MACHINE_QUESTION.get(role),
|
'machine': account['machine'], 'machine_question': MACHINE_QUESTION.get(role),
|
||||||
'machine_answered': account['machine_answered'],
|
'machine_answered': account['machine_answered'],
|
||||||
|
|||||||
@@ -117,6 +117,13 @@ def _traces_rate():
|
|||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def release():
|
||||||
|
"""The deploy this process runs: IMAGE_TAG when the stack sets one, else the
|
||||||
|
commit the image was built from (RELEASE, from deploy/Dockerfile.api)."""
|
||||||
|
value = os.environ.get('IMAGE_TAG') or os.environ.get('RELEASE') or ''
|
||||||
|
return None if value in ('', 'unknown', 'latest') else value
|
||||||
|
|
||||||
|
|
||||||
def init(component):
|
def init(component):
|
||||||
"""Start Sentry for this process; False (and no imports) without a DSN."""
|
"""Start Sentry for this process; False (and no imports) without a DSN."""
|
||||||
dsn = os.environ.get('SENTRY_DSN_API', '').strip()
|
dsn = os.environ.get('SENTRY_DSN_API', '').strip()
|
||||||
@@ -130,7 +137,7 @@ def init(component):
|
|||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
dsn=dsn,
|
dsn=dsn,
|
||||||
environment=environment,
|
environment=environment,
|
||||||
release=os.environ.get('IMAGE_TAG') or None,
|
release=release(),
|
||||||
send_default_pii=False,
|
send_default_pii=False,
|
||||||
traces_sample_rate=_traces_rate(),
|
traces_sample_rate=_traces_rate(),
|
||||||
before_send=scrub,
|
before_send=scrub,
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ ARG PYTHON_BASE_IMAGE=python:3.12-slim@sha256:2f17fc044b579bab302c2e8054d3a686e2
|
|||||||
FROM ${PYTHON_BASE_IMAGE}
|
FROM ${PYTHON_BASE_IMAGE}
|
||||||
|
|
||||||
ARG VCS_REF=unknown
|
ARG VCS_REF=unknown
|
||||||
|
# The commit this image was built from, as the Sentry release (app/observability.py).
|
||||||
|
ENV RELEASE=$VCS_REF
|
||||||
LABEL org.opencontainers.image.title="DTF Portal/API" \
|
LABEL org.opencontainers.image.title="DTF Portal/API" \
|
||||||
org.opencontainers.image.revision="$VCS_REF" \
|
org.opencontainers.image.revision="$VCS_REF" \
|
||||||
org.opencontainers.image.source="DTF System repository"
|
org.opencontainers.image.source="DTF System repository"
|
||||||
|
|||||||
Reference in New Issue
Block a user