Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions 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 All @@ -23,6 +24,7 @@ def build_payload(event, seq_id, api_version: 'v2', debug: false)
seq_id: seq_id,
tracer_time: Core::Utils::Time.now.to_i,
}
tag_process_tags!(hash)
hash.compact!
hash
end
Expand Down Expand Up @@ -64,6 +66,15 @@ def host
kernel_version: Core::Environment::Platform.kernel_version
}
end

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

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

hash[: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] hash) -> void
end
end
end
Expand Down
50 changes: 50 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,56 @@
)
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
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 include('process_tags' => String)
expect(payload.dig(:payload, 'process_tags')).to include('entrypoint.workdir')
expect(payload.dig(:payload, 'process_tags')).to include('entrypoint.basedir')
expect(payload.dig(:payload, 'process_tags')).to include('entrypoint.type')
expect(payload.dig(:payload, 'process_tags')).to include('entrypoint.name')
end

it 'does not include process_tags when serialized value is empty' do
allow(Datadog.configuration).to receive(:experimental_propagate_process_tags_enabled).and_return(true)
allow(Datadog::Core::Environment::Process).to receive(:serialized).and_return('')

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

payload = sent_payloads[0]
expect(payload.fetch(:payload)).not_to have_key('process_tags')
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.fetch(:payload)).not_to have_key('process_tags')
end
end
end
end

let(:handler_proc) do
Expand Down
Loading