Skip to content

Commit 9c45209

Browse files
ericapisaniclaude
andauthored
fix(utils): Use HEROKU_BUILD_COMMIT env var for default release (#5499)
Add HEROKU_BUILD_COMMIT as the primary env var for detecting the release on Heroku, keeping HEROKU_SLUG_COMMIT as a fallback since it is deprecated by Heroku. - Fixes PY-2089 - Fixes #5496 Co-authored-by: Claude <noreply@anthropic.com>
1 parent e6f903a commit 9c45209

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

sentry_sdk/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def get_default_release() -> "Optional[str]":
155155
return release
156156

157157
for var in (
158-
"HEROKU_SLUG_COMMIT",
158+
"HEROKU_BUILD_COMMIT",
159+
"HEROKU_SLUG_COMMIT", # deprecated by Heroku, kept for backward compatibility
159160
"SOURCE_VERSION",
160161
"CODEBUILD_RESOLVED_SOURCE_VERSION",
161162
"CIRCLE_SHA1",

tests/test_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,36 @@ def test_get_default_release_other_release_env(monkeypatch):
721721
assert release == "other-env-release"
722722

723723

724+
def test_get_default_release_heroku_build_commit(monkeypatch):
725+
monkeypatch.setenv("HEROKU_BUILD_COMMIT", "heroku-build-commit-sha")
726+
727+
with mock.patch("sentry_sdk.utils.get_git_revision", return_value=""):
728+
release = get_default_release()
729+
730+
assert release == "heroku-build-commit-sha"
731+
732+
733+
def test_get_default_release_heroku_slug_commit_fallback(monkeypatch):
734+
# Although deprecated by Heroku, HEROKU_SLUG_COMMIT should still be used if HEROKU_BUILD_COMMIT is not set
735+
monkeypatch.setenv("HEROKU_SLUG_COMMIT", "heroku-slug-commit-sha")
736+
737+
with mock.patch("sentry_sdk.utils.get_git_revision", return_value=""):
738+
release = get_default_release()
739+
740+
assert release == "heroku-slug-commit-sha"
741+
742+
743+
def test_get_default_release_heroku_build_commit_takes_priority(monkeypatch):
744+
# HEROKU_BUILD_COMMIT should take priority over HEROKU_SLUG_COMMIT since it's the non-deprecated variable
745+
monkeypatch.setenv("HEROKU_BUILD_COMMIT", "heroku-build-commit-sha")
746+
monkeypatch.setenv("HEROKU_SLUG_COMMIT", "heroku-slug-commit-sha")
747+
748+
with mock.patch("sentry_sdk.utils.get_git_revision", return_value=""):
749+
release = get_default_release()
750+
751+
assert release == "heroku-build-commit-sha"
752+
753+
724754
def test_ensure_integration_enabled_integration_enabled(sentry_init):
725755
def original_function():
726756
return "original"

0 commit comments

Comments
 (0)