Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion lib/datadog/di/probe_notification_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def build_snapshot_base(context, evaluation_errors: [], captures: nil, message:
format_caller_locations(caller_locations)
end

{
payload = {
service: settings.service,
debugger: {
type: 'snapshot',
Expand Down Expand Up @@ -189,6 +189,10 @@ def build_snapshot_base(context, evaluation_errors: [], captures: nil, message:
message: message,
timestamp: timestamp,
}

tag_process_tags!(payload, settings)

payload
end

def build_status(probe, message:, status:)
Expand Down Expand Up @@ -236,6 +240,15 @@ def evaluate_template(template_segments, context)
[message, evaluation_errors]
end

def tag_process_tags!(payload, settings)
return unless settings.experimental_propagate_process_tags_enabled

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

payload[:process_tags] = process_tags
end

def timestamp_now
(Core::Utils::Time.now.to_f * MILLISECONDS).to_i
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/di/probe_notification_builder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module Datadog

def evaluate_template: (untyped template, Context context) -> [String, Array[String]]

def tag_process_tags!: (Hash[Symbol | String, untyped] payload, Core::Configuration::Settings settings) -> void

def timestamp_now: () -> Integer

def get_local_variables: (TracePoint trace_point) -> Hash[Symbol,untyped]
Expand Down
36 changes: 36 additions & 0 deletions spec/datadog/di/probe_notification_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
allow(settings).to receive(:env).and_return('test env')
allow(settings).to receive(:version).and_return('test version')
allow(settings).to receive(:tags).and_return({})
allow(settings).to receive(:experimental_propagate_process_tags_enabled).and_return(false)
end
end

Expand Down Expand Up @@ -384,4 +385,39 @@
end
end
end

describe 'process tags' do
let(:probe) do
Datadog::DI::Probe.new(id: '123', type: :log, file: 'X', line_no: 1)
end

let(:context) do
Datadog::DI::Context.new(
settings: settings, serializer: serializer,
probe: probe
)
end

context 'when process tags propagation is enabled' do
before do
allow(settings).to receive(:experimental_propagate_process_tags_enabled).and_return(true)
end

it 'includes process tags in the payload' do
payload = builder.build_executed(context)
expect(payload[:process_tags]).to eq(Datadog::Core::Environment::Process.serialized)
expect(payload[:process_tags]).to include('entrypoint.workdir')
expect(payload[:process_tags]).to include('entrypoint.name')
expect(payload[:process_tags]).to include('entrypoint.basedir')
expect(payload[:process_tags]).to include('entrypoint.type')
end
end

context 'when process tags propagation is not enabled' do
it 'excludes process tags in the payload' do
payload = builder.build_executed(context)
expect(payload).not_to include(:process_tags)
end
end
end
end
Loading