diff --git a/lib/degica_datadog/config.rb b/lib/degica_datadog/config.rb index ee12064..8d3d15c 100644 --- a/lib/degica_datadog/config.rb +++ b/lib/degica_datadog/config.rb @@ -30,7 +30,11 @@ def service end def version - @version || ENV.fetch("_GIT_REVISION", "unknown") + return @version if @version + + platform = ENV.fetch("PLATFORM", "") + git_revision = ENV.fetch("_GIT_REVISION", "unknown") + platform.empty? ? git_revision : "#{git_revision}-#{platform}" end def environment diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 4be4661..caaadd7 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -43,6 +43,7 @@ described_class.init allow(ENV).to receive(:fetch).with("SERVICE_NAME", "unknown").and_return(service_name) + allow(ENV).to receive(:fetch).with("PLATFORM", "").and_return("") allow(ENV).to receive(:fetch).with("_GIT_REVISION", "unknown").and_return(version) allow(ENV).to receive(:fetch).with("RAILS_ENV", "unknown").and_return(environment) end @@ -63,6 +64,22 @@ expect(described_class.repository_url).to eq("github.com/degica/#{service_name}") end end + + context "fetches from env on codepipeline" do + let(:version) { "mocked_version" } + let(:platform) { "cpp" } # codepipeline prefix + + before do + described_class.init + + allow(ENV).to receive(:fetch).with("PLATFORM", "").and_return(platform) + allow(ENV).to receive(:fetch).with("_GIT_REVISION", "unknown").and_return(version) + end + + it "sets version correctly" do + expect(described_class.version).to eq("#{version}-#{platform}") + end + end end describe ".enabled?" do