Skip to content

Commit

Permalink
fix wip
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Jan 16, 2025
1 parent 90e90bf commit 45a3ca7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
18 changes: 15 additions & 3 deletions lib/datadog/di/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def receivers(telemetry)
# TODO test exception capture
probe_manager.add_probe(probe)
content.applied
rescue DI::Error::DITargetNotInRegistry => exc
component.telemetry&.report(exc, description: "Line probe is targeting a loaded file that is not in code tracker")

# If a probe fails to install, we will mark the content
# as errored. On subsequent remote configuration application
# attemps, probe manager will raise the "previously errored"
# exception and we'll rescue it here, again marking the
# content as errored but with a somewhat different exception
# message.
# TODO assert content state (errored for this example)
content.errored("Error applying dynamic instrumentation configuration: #{exc.class.name} #{exc.message}")
rescue => exc
raise if component.settings.dynamic_instrumentation.internal.propagate_all_exceptions

Expand All @@ -69,8 +80,8 @@ def receivers(telemetry)
# exception and we'll rescue it here, again marking the
# content as errored but with a somewhat different exception
# message.
# TODO stack trace must be redacted or not sent at all
content.errored("Error applying dynamic instrumentation configuration: #{exc.class.name} #{exc.message}: #{Array(exc.backtrace).join("\n")}")
# TODO assert content state (errored for this example)
content.errored("Error applying dynamic instrumentation configuration: #{exc.class.name} #{exc.message}")
end

# Important: even if processing fails for this probe config,
Expand All @@ -84,7 +95,8 @@ def receivers(telemetry)
component.logger.debug { "di: unhandled exception handling probe in DI remote receiver: #{exc.class}: #{exc}" }
component.telemetry&.report(exc, description: "Unhandled exception handling probe in DI remote receiver")

content.errored("Error applying dynamic instrumentation configuration: #{exc.class.name} #{exc.message}: #{Array(exc.backtrace).join("\n")}")
# TODO assert content state (errored for this example)
content.errored("Error applying dynamic instrumentation configuration: #{exc.class.name} #{exc.message}")
end
end
end
Expand Down
33 changes: 22 additions & 11 deletions spec/datadog/di/integration/everything_from_remote_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,29 @@ def do_rc
end
end

context 'method probe received matching a loaded class' do
def assert_received_and_installed
expect(payloads).to be_a(Array)
expect(payloads.length).to eq 2
def assert_received_and_installed
expect(payloads).to be_a(Array)
expect(payloads.length).to eq 2

received_payload = payloads.shift
expect(received_payload).to match(expected_received_payload)
received_payload = payloads.shift
expect(received_payload).to match(expected_received_payload)

installed_payload = payloads.shift
expect(installed_payload).to match(expected_installed_payload)
end
installed_payload = payloads.shift
expect(installed_payload).to match(expected_installed_payload)
end

def assert_received_and_errored
expect(payloads).to be_a(Array)
expect(payloads.length).to eq 2

received_payload = payloads.shift
expect(received_payload).to match(expected_received_payload)

installed_payload = payloads.shift
expect(installed_payload).to match(expected_errored_payload)
end

context 'method probe received matching a loaded class' do
let(:probe_spec) do
{id: '11', name: 'bar', type: 'LOG_PROBE', where: {typeName: 'EverythingFromRemoteConfigSpecTestClass', methodName: 'target_method'}}
end
Expand Down Expand Up @@ -368,9 +379,9 @@ def assert_received_and_installed
)

do_rc
assert_received_and_installed
assert_received_and_errored

expect(probe_manager.installed_probes.length).to eq 1
expect(probe_manager.installed_probes.length).to eq 0
end
end
end
Expand Down

0 comments on commit 45a3ca7

Please sign in to comment.