Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/datadog/core/telemetry/request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative '../environment/platform'
require_relative '../environment/process'
require_relative '../utils/hash'

module Datadog
Expand Down Expand Up @@ -43,7 +44,7 @@ def application
tracer_version = "#{tracer_version}-ci-#{::Datadog::CI::VERSION::STRING}"
end

{
app = {
env: config.env,
language_name: Core::Environment::Ext::LANG,
language_version: Core::Environment::Ext::LANG_VERSION,
Expand All @@ -53,6 +54,10 @@ def application
service_version: config.version,
tracer_version: tracer_version
}

tag_process_tags!(app)

app
end

def host
Expand All @@ -64,6 +69,15 @@ def host
kernel_version: Core::Environment::Platform.kernel_version
}
end

def tag_process_tags!(app)
return unless Datadog.configuration.experimental_propagate_process_tags_enabled

process_tags = Core::Environment::Process.serialized
return if process_tags.empty?

app[:process_tags] = process_tags
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/core/telemetry/request.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Datadog

def self.application: -> ::Hash[Symbol, untyped]
def self.host: -> ::Hash[Symbol, untyped]
def self.tag_process_tags!: (Hash[Symbol, untyped] app) -> void
end
end
end
Expand Down
53 changes: 53 additions & 0 deletions spec/datadog/core/telemetry/integration/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,59 @@
)
end
end

describe 'process tags' do
include_context 'disable profiling'

before do
settings.telemetry.dependency_collection = true
end

context 'when process tags propagation is enabled' do
let(:expected_application_hash) do
super().merge('process_tags' => String)
end

it 'includes process tags in the payload when the process tags have values' do
allow(Datadog.configuration).to receive(:experimental_propagate_process_tags_enabled).and_return(true)

component.start(false, components: Datadog.send(:components))
component.flush
expect(sent_payloads.length).to eq 2

payload = sent_payloads[0]
expect(payload.fetch(:payload)).to match(
'api_version' => 'v2',
'application' => expected_application_hash,
'debug' => false,
'host' => expected_host_hash,
'payload' => Hash,
'request_type' => 'app-started',
'runtime_id' => String,
'seq_id' => Integer,
'tracer_time' => Integer,
)

expect(payload.dig(:payload, 'application', 'process_tags')).to include('entrypoint.workdir')
expect(payload.dig(:payload, 'application', 'process_tags')).to include('entrypoint.basedir')
expect(payload.dig(:payload, 'application', 'process_tags')).to include('entrypoint.type')
expect(payload.dig(:payload, 'application', 'process_tags')).to include('entrypoint.name')
end
end

context 'when process tags propagation is disabled' do
it 'does not include process_tags in the payload' do
allow(Datadog.configuration).to receive(:experimental_propagate_process_tags_enabled).and_return(false)

component.start(false, components: Datadog.send(:components))
component.flush
expect(sent_payloads.length).to eq 2

payload = sent_payloads[0]
expect(payload.dig(:payload, 'application')).not_to have_key('process_tags')
end
end
end
end

let(:handler_proc) do
Expand Down
Loading