Skip to content

Commit

Permalink
DEBUG-2334 Set duration to 0 for DI line probes
Browse files Browse the repository at this point in the history
Line probes do not have a meaningful duration, however
schema validation in system tests demands an integer value.

Follow the behavior of other tracers and send 0.
  • Loading branch information
p committed Nov 20, 2024
1 parent 9b97769 commit 821b191
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/di/probe_notification_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def build_snapshot(probe, rv: nil, snapshot: nil, path: nil,
},
# In python tracer duration is under debugger.snapshot,
# but UI appears to expect it here at top level.
duration: duration ? (duration * 10**9).to_i : nil,
duration: duration ? (duration * 10**9).to_i : 0,
host: nil,
logger: {
name: probe.file,
Expand All @@ -139,7 +139,7 @@ def build_snapshot(probe, rv: nil, snapshot: nil, path: nil,
"dd.span_id": Datadog::Tracing.active_span&.id&.to_s,
ddsource: 'dd_debugger',
message: probe.template && evaluate_template(probe.template,
duration: duration ? duration * 1000 : nil),
duration: duration ? duration * 1000 : 0),
timestamp: timestamp,
}
end
Expand Down
254 changes: 241 additions & 13 deletions spec/datadog/di/probe_notification_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,144 @@
end

describe '#build_received' do
it 'returns a hash' do
expect(builder.build_received(probe)).to be_a(Hash)

let(:payload) do
builder.build_received(probe)
end

let(:expected) do
{
ddsource: 'dd_debugger',
debugger: {
diagnostics: {
parentId: nil,
probeId: '123',
probeVersion: 0,
runtimeId: String,
status: 'RECEIVED',
},
},
message: "Probe 123 has been received correctly",
service: 'test service',
timestamp: Integer,
}
end

it 'returns a hash with expected contents' do
expect(payload).to be_a(Hash)
expect(payload).to match(expected)
end
end

describe '#build_installed' do
it 'returns a hash' do
expect(builder.build_installed(probe)).to be_a(Hash)

let(:payload) do
builder.build_installed(probe)
end

let(:expected) do
{
ddsource: 'dd_debugger',
debugger: {
diagnostics: {
parentId: nil,
probeId: '123',
probeVersion: 0,
runtimeId: String,
status: 'INSTALLED',
},
},
message: "Probe 123 has been instrumented correctly",
service: 'test service',
timestamp: Integer,
}
end

it 'returns a hash with expected contents' do
expect(payload).to be_a(Hash)
expect(payload).to match(expected)
end
end

describe '#build_emitting' do
it 'returns a hash' do
expect(builder.build_emitting(probe)).to be_a(Hash)

let(:payload) do
builder.build_emitting(probe)
end

let(:expected) do
{
ddsource: 'dd_debugger',
debugger: {
diagnostics: {
parentId: nil,
probeId: '123',
probeVersion: 0,
runtimeId: String,
status: 'EMITTING',
},
},
message: "Probe 123 is emitting",
service: 'test service',
timestamp: Integer,
}
end

it 'returns a hash with expected contents' do
expect(payload).to be_a(Hash)
expect(payload).to match(expected)
end
end

describe '#build_executed' do

let(:payload) { builder.build_executed(probe) }

context 'with template' do
let(:probe) do
Datadog::DI::Probe.new(id: '123', type: :log, file: 'X', line_no: 1,
template: 'hello world')
end

it 'returns a hash' do
expect(builder.build_executed(probe)).to be_a(Hash)
let(:expected) do
{
ddsource: 'dd_debugger',
'dd.span_id': nil,
'dd.trace_id': nil,
'debugger.snapshot': {
captures: nil,
evaluationErrors: [],
id: String,
language: 'ruby',
probe: {
id: '123',
location: {
file: nil,
lines: [1],
},
version: 0,
},
stack: nil,
timestamp: Integer,
},
message: "hello world",
service: 'test service',
timestamp: Integer,
logger: {
method: 'no_method',
name: 'X',
thread_id: nil,
thread_name: 'Thread.main',
version: 2,
},
duration: 0,
host: nil,
}
end

it 'returns a hash with expected contents' do
expect(payload).to be_a(Hash)
expect(payload).to match(expected)
end
end

Expand All @@ -77,8 +189,45 @@
capture_snapshot: false)
end

it 'returns a hash' do
expect(builder.build_executed(probe)).to be_a(Hash)
let(:expected) do
{
ddsource: 'dd_debugger',
'dd.span_id': nil,
'dd.trace_id': nil,
'debugger.snapshot': {
captures: nil,
evaluationErrors: [],
id: String,
language: 'ruby',
probe: {
id: '123',
location: {
file: nil,
lines: [1],
},
version: 0,
},
stack: nil,
timestamp: Integer,
},
message: nil,
service: 'test service',
timestamp: Integer,
logger: {
method: 'no_method',
name: 'X',
thread_id: nil,
thread_name: 'Thread.main',
version: 2,
},
duration: 0,
host: nil,
}
end

it 'returns a hash with expected contents' do
expect(payload).to be_a(Hash)
expect(payload).to match(expected)
end
end

Expand All @@ -91,13 +240,92 @@
let(:trace_point) do
instance_double(TracePoint).tap do |tp|
# Returns an empty binding
expect(tp).to receive(:binding).and_return(binding)
expect(tp).to receive(:binding).and_return(get_binding)
expect(tp).to receive(:path).and_return('/foo.rb')
end
end

it 'returns a hash' do
expect(builder.build_executed(probe, trace_point: trace_point)).to be_a(Hash)
let(:get_binding) do
x = 1
binding
end

let(:payload) do
builder.build_executed(probe, trace_point: trace_point)
end

let(:expected) do
{
ddsource: 'dd_debugger',
'dd.span_id': nil,
'dd.trace_id': nil,
'debugger.snapshot': {
captures: {
lines: {
1 => {
locals: local_captures,
},
},
},
evaluationErrors: [],
id: String,
language: 'ruby',
probe: {
id: '123',
location: {
file: '/foo.rb',
lines: [1],
},
version: 0,
},
stack: nil,
timestamp: Integer,
},
message: nil,
service: 'test service',
timestamp: Integer,
logger: {
method: 'no_method',
name: 'X',
thread_id: nil,
thread_name: 'Thread.main',
version: 2,
},
duration: 0,
host: nil,
}
end

shared_examples 'returns a hash with expected contents' do
it 'returns a hash with expected contents' do
expect(payload).to be_a(Hash)
expect(payload).to match(expected)
end
end

context 'when binding is empty' do
let(:get_binding) do
binding
end

let(:local_captures) do
{}
end

include_examples 'returns a hash with expected contents'
end

context 'when binding is not empty' do
let(:get_binding) do
x = 1
binding
end

let(:local_captures) do
{x: {type: 'Integer', value: '1'}}
end

include_examples 'returns a hash with expected contents'
end
end
end
Expand Down

0 comments on commit 821b191

Please sign in to comment.