Skip to content

Commit

Permalink
Changed: Identity::tracer_version to ::gem_datadog_version
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Mar 18, 2024
1 parent 59a4e65 commit 2c69805
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 39 deletions.
6 changes: 3 additions & 3 deletions lib/datadog/core/environment/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def lang_version
end

# Returns datadog gem version, rubygems-style
def tracer_version
def gem_datadog_version
Core::Environment::Ext::GEM_DATADOG_VERSION
end

# Returns tracer version, comforming to https://semver.org/spec/v2.0.0.html
def tracer_version_semver2
major, minor, patch, rest = tracer_version.split('.', 4)
def gem_datadog_version_semver2
major, minor, patch, rest = gem_datadog_version.split('.', 4)

semver = "#{major}.#{minor}.#{patch}"

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/metrics/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Options
"#{Ext::TAG_LANG_VERSION}:#{Environment::Identity.lang_version}",
# TODO: Technically not accurate, if tracing version diverges from datadog gem version
# If we extract tracing to its own gem, this needs to be updated.
"#{Ext::TAG_TRACER_VERSION}:#{Environment::Identity.tracer_version}"
"#{Ext::TAG_TRACER_VERSION}:#{Environment::Identity.gem_datadog_version}"
].freeze
}.freeze

Expand Down
10 changes: 6 additions & 4 deletions lib/datadog/core/remote/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def payload # rubocop:disable Metrics/MethodLength
"platform:#{native_platform}", # native platform
# "asm.config.rules:#{}", # TODO: defined|undefined
# "asm.config.enabled:#{}", # TODO: true|false|undefined
"ruby.tracer.version:#{Core::Environment::Identity.tracer_version}",
# TODO: Inaccurate if tracing is extracted and version diverges from the datadog gem.
# Update this if this ever occurs.
"ruby.tracer.version:#{Core::Environment::Identity.gem_datadog_version}",
"ruby.runtime.platform:#{RUBY_PLATFORM}",
"ruby.runtime.version:#{RUBY_VERSION}",
"ruby.runtime.engine.name:#{RUBY_ENGINE}",
Expand All @@ -138,7 +140,7 @@ def payload # rubocop:disable Metrics/MethodLength
client_tracer = {
runtime_id: Core::Environment::Identity.id,
language: Core::Environment::Identity.lang,
tracer_version: tracer_version_semver2,
tracer_version: tracer_version,
service: service_name,
env: Datadog.configuration.env,
tags: client_tracer_tags,
Expand Down Expand Up @@ -174,8 +176,8 @@ def service_name
Datadog.configuration.remote.service || Datadog.configuration.service
end

def tracer_version_semver2
@tracer_version_semver2 ||= Core::Environment::Identity.tracer_version_semver2
def tracer_version
@tracer_version ||= Core::Environment::Identity.gem_datadog_version_semver2
end

def ruby_engine_version
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/telemetry/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def service_version
end

def library_version
Core::Environment::Identity.tracer_version
Core::Environment::Identity.gem_datadog_version
end

def products
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/profiling/collectors/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def collect_profiler_info(settings)
unless @profiler_info
lib_datadog_gem = ::Gem.loaded_specs['libdatadog']
@profiler_info = {
version: Datadog::Core::Environment::Identity.tracer_version,
# TODO: If profiling is extracted and its version diverges from the datadog gem, this is inaccurate.
# Update if this ever occurs.
version: Datadog::Core::Environment::Identity.gem_datadog_version,
libdatadog: "#{lib_datadog_gem.version}-#{lib_datadog_gem.platform}",
settings: collect_settings_recursively(settings.profiling),
}.freeze
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/profiling/tag_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def self.call(
host: Core::Environment::Socket.hostname,
language: Core::Environment::Identity.lang,
pid: Process.pid.to_s,
profiler_version: Core::Environment::Identity.tracer_version,
# TODO: If profiling is extracted and its version diverges from the datadog gem, this is inaccurate.
# Update if this ever occurs.
profiler_version: Core::Environment::Identity.gem_datadog_version,
runtime_engine: Core::Environment::Identity.lang_engine,
runtime_id: Core::Environment::Identity.id,
runtime_platform: Core::Environment::Identity.lang_platform,
Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/core/environment/identity.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ module Datadog

def self?.lang_version: () -> ::String

def self?.tracer_version: () -> ::String
def self?.gem_datadog_version: () -> ::String

def self?.tracer_version_semver2: () -> ::String
def self?.gem_datadog_version_semver2: () -> ::String
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/core/remote/client.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ module Datadog
@gem_specs: ::Hash[::String, ::Gem::Specification | untyped]
@native_platform: ::String
@ruby_engine_version: ::String
@tracer_version_semver2: ::String
@tracer_version: ::String

def payload: () -> ::Hash[Symbol, untyped]
def service_name: () -> ::String
def gem_spec: (::String) -> (::Gem::Specification | untyped)
def tracer_version_semver2: () -> ::String
def tracer_version: () -> ::String
def native_platform: () -> ::String
def ruby_engine_version: () -> ::String

Expand Down
18 changes: 10 additions & 8 deletions spec/datadog/core/environment/identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,44 @@
it { is_expected.to eq(Datadog::Core::Environment::Ext::LANG_VERSION) }
end

describe '::tracer_version' do
subject(:tracer_version) { described_class.tracer_version }
describe '::gem_datadog_version' do
subject(:gem_datadog_version) { described_class.gem_datadog_version }

it { is_expected.to eq(Datadog::Core::Environment::Ext::GEM_DATADOG_VERSION) }
end

describe '::tracer_version_semver2' do
subject(:tracer_version) { described_class.tracer_version_semver2 }
describe '::gem_datadog_version_semver2' do
subject(:gem_datadog_version) { described_class.gem_datadog_version_semver2 }

context 'when not prerelease' do
before do
expect(described_class).to receive(:tracer_version).and_return('10.20.30'.freeze)
expect(described_class).to receive(:gem_datadog_version).and_return('10.20.30'.freeze)
end

it { is_expected.to eq('10.20.30') }
end

context 'when prerelease' do
before do
expect(described_class).to receive(:tracer_version).and_return('10.20.30.beta40'.freeze)
expect(described_class).to receive(:gem_datadog_version).and_return('10.20.30.beta40'.freeze)
end

it { is_expected.to eq('10.20.30-beta40') }
end

context 'when development' do
before do
expect(described_class).to receive(:tracer_version).and_return('10.20.30.b3fe268.gha12345.ga1b2c3d4'.freeze)
expect(described_class).to receive(:gem_datadog_version)
.and_return('10.20.30.b3fe268.gha12345.ga1b2c3d4'.freeze)
end

it { is_expected.to eq('10.20.30+b3fe268.gha12345.ga1b2c3d4') }
end

context 'when prerelease and development' do
before do
expect(described_class).to receive(:tracer_version).and_return('10.20.30.beta40.b3fe268.gha12345.ga1b2c3d4'.freeze)
expect(described_class).to receive(:gem_datadog_version)
.and_return('10.20.30.beta40.b3fe268.gha12345.ga1b2c3d4'.freeze)
end

it { is_expected.to eq('10.20.30-beta40+b3fe268.gha12345.ga1b2c3d4') }
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/core/metrics/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"#{Datadog::Core::Metrics::Ext::TAG_LANG}:#{Datadog::Core::Environment::Identity.lang}",
"#{Datadog::Core::Metrics::Ext::TAG_LANG_INTERPRETER}:#{Datadog::Core::Environment::Identity.lang_interpreter}",
"#{Datadog::Core::Metrics::Ext::TAG_LANG_VERSION}:#{Datadog::Core::Environment::Identity.lang_version}",
"#{Datadog::Core::Metrics::Ext::TAG_TRACER_VERSION}:#{Datadog::Core::Environment::Identity.tracer_version}"
"#{Datadog::Core::Metrics::Ext::TAG_TRACER_VERSION}:#{Datadog::Core::Environment::Identity.gem_datadog_version}"
)
end

Expand Down
12 changes: 6 additions & 6 deletions spec/datadog/core/remote/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@

context 'client_tracer' do
context 'tags' do
let(:tracer_version) { '1.1.1' }
let(:gem_datadog_version) { '1.1.1' }
let(:ruby_platform) { 'ruby-platform' }
let(:ruby_version) { '2.2.2' }
let(:ruby_engine) { 'ruby_engine_name' }
Expand All @@ -546,7 +546,7 @@
stub_const('RUBY_ENGINE_VERSION', ruby_engine_version)

allow(Gem::Platform).to receive(:local).and_return(gem_platform_local)
allow(Datadog::Core::Environment::Identity).to receive(:tracer_version).and_return(tracer_version)
allow(Datadog::Core::Environment::Identity).to receive(:gem_datadog_version).and_return(gem_datadog_version)
allow(client).to receive(:ruby_engine_version).and_return(ruby_engine_version)
allow(client).to receive(:native_platform).and_return(native_platform)
allow(client).to receive(:gem_spec).with('libddwaf').and_return(libddwaf_gem_spec)
Expand All @@ -558,7 +558,7 @@

expected_client_tracer_tags = [
"platform:#{native_platform}",
"ruby.tracer.version:#{tracer_version}",
"ruby.tracer.version:#{gem_datadog_version}",
"ruby.runtime.platform:#{ruby_platform}",
"ruby.runtime.version:#{ruby_version}",
"ruby.runtime.engine.name:#{ruby_engine}",
Expand All @@ -581,7 +581,7 @@
expected_client_tracer = {
:runtime_id => Datadog::Core::Environment::Identity.id,
:language => Datadog::Core::Environment::Identity.lang,
:tracer_version => Datadog::Core::Environment::Identity.tracer_version_semver2,
:tracer_version => Datadog::Core::Environment::Identity.gem_datadog_version_semver2,
:service => Datadog.configuration.remote.service,
:env => Datadog.configuration.env,
}
Expand All @@ -597,7 +597,7 @@
expected_client_tracer = {
:runtime_id => Datadog::Core::Environment::Identity.id,
:language => Datadog::Core::Environment::Identity.lang,
:tracer_version => Datadog::Core::Environment::Identity.tracer_version_semver2,
:tracer_version => Datadog::Core::Environment::Identity.gem_datadog_version_semver2,
:service => Datadog.configuration.service,
:env => Datadog.configuration.env,
:app_version => Datadog.configuration.version,
Expand All @@ -614,7 +614,7 @@
expected_client_tracer = {
:runtime_id => Datadog::Core::Environment::Identity.id,
:language => Datadog::Core::Environment::Identity.lang,
:tracer_version => Datadog::Core::Environment::Identity.tracer_version_semver2,
:tracer_version => Datadog::Core::Environment::Identity.gem_datadog_version_semver2,
:service => Datadog.configuration.service,
:env => Datadog.configuration.env,
}
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/core/remote/transport/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
client_tracer: {
runtime_id: Datadog::Core::Environment::Identity.id,
language: Datadog::Core::Environment::Identity.lang,
tracer_version: Datadog::Core::Environment::Identity.tracer_version,
tracer_version: Datadog::Core::Environment::Identity.gem_datadog_version,
service: Datadog.configuration.service,
env: Datadog.configuration.env,
tags: [],
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/core/remote/transport/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
client_tracer: {
runtime_id: Datadog::Core::Environment::Identity.id,
language: Datadog::Core::Environment::Identity.lang,
tracer_version: Datadog::Core::Environment::Identity.tracer_version,
tracer_version: Datadog::Core::Environment::Identity.gem_datadog_version,
service: Datadog.configuration.service,
env: Datadog.configuration.env,
tags: [],
Expand Down
12 changes: 6 additions & 6 deletions spec/datadog/core/telemetry/v1/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
runtime_version: runtime_version,
service_name: service_name,
service_version: service_version,
tracer_version: tracer_version
tracer_version: gem_datadog_version
)
end

Expand All @@ -34,7 +34,7 @@
let(:runtime_version) { '3.2.1' }
let(:service_name) { 'myapp' }
let(:service_version) { '1.2.3' }
let(:tracer_version) { '1.0' }
let(:gem_datadog_version) { '1.0' }

it do
is_expected.to have_attributes(
Expand All @@ -47,7 +47,7 @@
runtime_version: runtime_version,
service_name: service_name,
service_version: service_version,
tracer_version: tracer_version
tracer_version: gem_datadog_version
)
end

Expand All @@ -65,7 +65,7 @@
end

context ':tracer_version' do
it_behaves_like 'a required string parameter', 'tracer_version'
it_behaves_like 'a required string parameter', 'gem_datadog_version'
end

context ':env' do
Expand Down Expand Up @@ -123,7 +123,7 @@
let(:runtime_version) { '3.2.1' }
let(:service_name) { 'myapp' }
let(:service_version) { '1.2.3' }
let(:tracer_version) { '1.0' }
let(:gem_datadog_version) { '1.0' }

it do
is_expected.to eq(
Expand All @@ -136,7 +136,7 @@
runtime_version: runtime_version,
service_name: service_name,
service_version: service_version,
tracer_version: tracer_version
tracer_version: gem_datadog_version
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/profiling/collectors/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
service: settings.service,
),
profiler: hash_including(
version: Datadog::Core::Environment::Identity.tracer_version,
version: Datadog::Core::Environment::Identity.gem_datadog_version,
),
}
)
Expand Down

0 comments on commit 2c69805

Please sign in to comment.