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:
Cauê Faleiros
2026-11-11 15:59:27 -03:00
parent f2fa2b7748
commit 55419d8364
4 changed files with 14 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ import httpx
from fastapi import APIRouter, HTTPException, Request, Response
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.limits import upload_limit_bytes
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.
'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', ''),
'sentry_release': observability.release() or '',
# 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 '',
# The delivery options the cart quotes, or none: pickup only.

View File

@@ -14,7 +14,7 @@ from uuid import UUID, uuid4
from fastapi import APIRouter, Depends, HTTPException, Request
from pydantic import Field, field_validator
from .. import machines, mail
from .. import machines, mail, observability
from ..core import db
from ..core.auth import (CAPABILITIES, MACHINE_QUESTION, audit, can, may_move, may_reorder, password_hash,
password_matches, signed_in)
@@ -72,7 +72,7 @@ def me(request: Request):
# 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', ''),
'sentry_release': observability.release() or '',
# 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'],

View File

@@ -117,6 +117,13 @@ def _traces_rate():
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):
"""Start Sentry for this process; False (and no imports) without a DSN."""
dsn = os.environ.get('SENTRY_DSN_API', '').strip()
@@ -130,7 +137,7 @@ def init(component):
sentry_sdk.init(
dsn=dsn,
environment=environment,
release=os.environ.get('IMAGE_TAG') or None,
release=release(),
send_default_pii=False,
traces_sample_rate=_traces_rate(),
before_send=scrub,

View File

@@ -6,6 +6,8 @@ ARG PYTHON_BASE_IMAGE=python:3.12-slim@sha256:2f17fc044b579bab302c2e8054d3a686e2
FROM ${PYTHON_BASE_IMAGE}
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" \
org.opencontainers.image.revision="$VCS_REF" \
org.opencontainers.image.source="DTF System repository"