Skip to content

Commit

Permalink
di serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Aug 26, 2024
1 parent 5b5e984 commit b7f051f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
11 changes: 5 additions & 6 deletions lib/datadog/di/probe_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ module ProbeNotifier
elsif probe.line?
{
lines: {
probe.line_no => {locals: snapshot},
probe.line_no => {locals: serializer.serialize_vars(snapshot)},
},
}
end

location = if probe.line?
actual_file = if probe.file
callers.detect do |caller|
# Normally callers should always be filled for a line probe
# but in the test suite we don't always provide all arguments.
callers&.detect do |caller|
File.basename(caller.sub(/:.*/, '')) == File.basename(probe.file)
end.sub(/:.*/, '')
end&.sub(/:.*/, '') || probe.file
end
{
file: actual_file,
Expand All @@ -91,9 +93,6 @@ module ProbeNotifier
stack = if callers
format_callers(callers)
end
if probe.line?
stack = [{fileName:actual_file,lineNumber:probe.line_no},{fileName:actual_file,lineNumber:probe.line_no}]+stack
end

timestamp = timestamp_now
payload = {
Expand Down
64 changes: 56 additions & 8 deletions spec/datadog/di/integration/probe_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

RSpec.describe Datadog::DI::ProbeNotifier do
describe 'log probe' do
let(:probe) do
Datadog::DI::Probe.new(id: '123', type: 'LOG_PROBE', type_name: 'X', method_name: 'y')
end

before do
allow(agent_settings).to receive(:hostname)
Expand Down Expand Up @@ -51,13 +48,64 @@
expect(Datadog::DI).to receive(:component).and_return(component)
end

context 'with snapshot' do
let(:vars) do
{hello: 42, hash: {hello: 42, password: 'redacted'}, array: [true]}
context 'line probe' do
let(:probe) do
Datadog::DI::Probe.new(id: '123', type: 'LOG_PROBE', file: 'X', line_nos: [1])
end

context 'with snapshot' do
let(:vars) do
{hello: 42, hash: {hello: 42, password: 'redacted'}, array: [true]}
end

let(:captures) do
{lines: {1 => {
locals: {
hello: {type: 'Integer', value: 42},
hash: {type: 'Hash', entries: [
[{type: 'Symbol', value: 'hello'}, {type: 'Integer', value: 42}],
[{type: 'Symbol', value: 'password'}, {type: 'String', notCapturedReason: 'redactedIdent'}],
]},
array: {type: 'Array', entries: [
{type: 'TrueClass', value: true},
]},
},
}}}
end

it 'notifies' do
payload = nil
expect(component.probe_notifier_worker).to receive(:add_snapshot) do |payload_|
payload = payload_
end
described_class.notify_snapshot(probe, snapshot: vars)
expect(payload).to be_a(Hash)
expect(payload.fetch(:'debugger.snapshot').fetch(:captures)).to eq(captures)
end
end
end

context 'method probe' do
let(:probe) do
Datadog::DI::Probe.new(id: '123', type: 'LOG_PROBE', type_name: 'X', method_name: 'y')
end

it 'notifies' do
described_class.notify_snapshot(probe, snapshot: vars)
context 'with snapshot' do
let(:vars) do
{hello: 42, hash: {hello: 42, password: 'redacted'}, array: [true]}
end

it 'notifies' do
pending

payload = nil
expect(component.probe_notifier_worker).to receive(:add_snapshot) do |payload_|
payload = payload_
end
described_class.notify_snapshot(probe, snapshot: vars)
expect(payload).to be_a(Hash)
expect(payload.fetch(:'debugger.snapshot')).to eq({})
end
end
end
end
Expand Down

0 comments on commit b7f051f

Please sign in to comment.