From d9f42b420f3a7c4ef50ba5cc2c5a6113210ef508 Mon Sep 17 00:00:00 2001 From: Tony Drake Date: Mon, 16 Mar 2026 14:16:23 -0400 Subject: [PATCH] Add release detection from Kamal deployment Kamal provides a KAMAL_VERSION environment variable in the containers it builds and deploys. It's the SHA of the commit the release is based on. - Added a path to use the environment variable in ReleaseDetector if set. It's done after looking for SENTRY_RELEASE, but before looking for a git repo. - Added spec for coverage. --- sentry-ruby/lib/sentry/release_detector.rb | 5 +++++ sentry-ruby/spec/sentry_spec.rb | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/sentry-ruby/lib/sentry/release_detector.rb b/sentry-ruby/lib/sentry/release_detector.rb index 00d77fa8d..506e8e135 100644 --- a/sentry-ruby/lib/sentry/release_detector.rb +++ b/sentry-ruby/lib/sentry/release_detector.rb @@ -6,6 +6,7 @@ class ReleaseDetector class << self def detect_release(project_root:, running_on_heroku:) detect_release_from_env || + detect_release_from_kamal || detect_release_from_git || detect_release_from_capistrano(project_root) || detect_release_from_heroku(running_on_heroku) @@ -31,6 +32,10 @@ def detect_release_from_git Sentry.sys_command("git rev-parse HEAD") if File.directory?(".git") end + def detect_release_from_kamal + ENV["KAMAL_VERSION"] + end + def detect_release_from_env ENV["SENTRY_RELEASE"] end diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index 0d9389416..df222aa01 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -1235,6 +1235,15 @@ end end + it 'uses `KAMAL_VERSION` env variable' do + ENV['KAMAL_VERSION'] = 'GIT_SHA' + + described_class.init + expect(described_class.configuration.release).to eq('GIT_SHA') + + ENV.delete('KAMAL_VERSION') + end + context "when git is available" do before do allow(File).to receive(:directory?).and_return(false)