Skip to content

Commit

Permalink
Merge pull request #8 from degica/cpp-apm
Browse files Browse the repository at this point in the history
Add prefix to the version name
  • Loading branch information
showwin authored Aug 15, 2024
2 parents abfb642 + c2edd7e commit 7712b42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/degica_datadog/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7712b42

Please sign in to comment.