From 810b06faaec89023fd7ff501004bceac7ec17e56 Mon Sep 17 00:00:00 2001 From: Hector Date: Thu, 14 Aug 2025 21:11:32 +0100 Subject: [PATCH] Tweak Sentry SDK setup Make two changes to what we report to Sentry for crashes: 1. Set 'environment' to SENTRY_REGION / SENTRY_ENVIRONMENT so rather than being 'production' or 'development' it's 'us', 'de', etc. 2. Set 'release' to the git sha we are building at. --- Dockerfile | 3 +++ cloudbuild.ci.yaml | 1 + cloudbuild.yaml | 1 + src/launchpad/sentry_sdk_init.py | 11 +++++------ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b953884..910a1bbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -109,5 +109,8 @@ USER app # Expose ports EXPOSE 2218 +ARG LAUNCHPAD_VERSION_SHA +ENV LAUNCHPAD_VERSION_SHA=$LAUNCHPAD_VERSION_SHA + # Default command CMD ["launchpad", "serve", "--verbose"] diff --git a/cloudbuild.ci.yaml b/cloudbuild.ci.yaml index ce349fee..2dc17e7a 100644 --- a/cloudbuild.ci.yaml +++ b/cloudbuild.ci.yaml @@ -15,6 +15,7 @@ steps: set -euxo pipefail docker buildx build \ --platform linux/amd64,linux/arm64 \ + --build-arg LAUNCHPAD_VERSION_SHA=$COMMIT_SHA \ -t $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/image:$COMMIT_SHA \ --label org.opencontainers.image.revision=$COMMIT_SHA \ --label org.opencontainers.image.version=$COMMIT_SHA \ diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 04805747..6bbef7f5 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -25,6 +25,7 @@ steps: docker buildx build \ --push \ --platform linux/amd64 \ + --build-arg LAUNCHPAD_VERSION_SHA=$COMMIT_SHA \ -t $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/image:$COMMIT_SHA \ -t $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/image:$SHORT_SHA \ -t $LOCATION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/image:nightly \ diff --git a/src/launchpad/sentry_sdk_init.py b/src/launchpad/sentry_sdk_init.py index 33e22752..0b01f8f8 100644 --- a/src/launchpad/sentry_sdk_init.py +++ b/src/launchpad/sentry_sdk_init.py @@ -46,13 +46,12 @@ def initialize_sentry_sdk() -> None: dsn=config["dsn"], integrations=integrations, send_default_pii=True, + # Release is the git sha release=config.get("release"), - environment=config.get("environment"), + # Convention is to set the Sentry environment to the region (us, de, etc). + environment=config["region"], ) - if config.get("region"): - sentry_sdk.set_tag("sentry_region", config["region"]) - logger.info(f"Sentry SDK initialized for environment: {config.get('environment')}") @@ -65,6 +64,6 @@ def get_sentry_config() -> Dict[str, Any]: return { "dsn": os.getenv("SENTRY_DSN"), "environment": environment.lower(), - "release": os.getenv("LAUNCHPAD_VERSION_SHA", "unknown"), # TODO: auto fetch latest git commit hash - "region": os.getenv("SENTRY_REGION"), + "release": os.getenv("LAUNCHPAD_VERSION_SHA", "unknown"), + "region": os.getenv("SENTRY_REGION", "unknown"), }