From 8b71df7cb6d2c7e654b1a2a4117b900cf6418dad Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Mon, 16 Sep 2024 15:24:56 +0200 Subject: [PATCH 1/4] Add SSI entry point --- lib-injection/host_inject.rb | 2 +- lib/datadog/single_step_instrument.rb | 12 +++++++++++ sig/datadog/single_step_instrument.rbs | 0 spec/datadog/single_step_instrument_spec.rb | 23 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/datadog/single_step_instrument.rb create mode 100644 sig/datadog/single_step_instrument.rbs create mode 100644 spec/datadog/single_step_instrument_spec.rb diff --git a/lib-injection/host_inject.rb b/lib-injection/host_inject.rb index 8baf5e18293..6583f8c4536 100644 --- a/lib-injection/host_inject.rb +++ b/lib-injection/host_inject.rb @@ -197,7 +197,7 @@ def bundler_supported? bundle_add_cmd = "bundle add #{gem} --skip-install --version #{gem_version_mapping[gem]} " bundle_add_cmd << ' --verbose ' if ENV['DD_TRACE_DEBUG'] == 'true' - bundle_add_cmd << '--require datadog/auto_instrument' if gem == 'datadog' + bundle_add_cmd << '--require datadog/single_step_instrument' if gem == 'datadog' utils.debug "Injection with `#{bundle_add_cmd}`" diff --git a/lib/datadog/single_step_instrument.rb b/lib/datadog/single_step_instrument.rb new file mode 100644 index 00000000000..c8d5e1218a4 --- /dev/null +++ b/lib/datadog/single_step_instrument.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# +# Entrypoint file for single step instrumentation. +# +# This file's path is private. Do not reference this file. +# +begin + require_relative 'auto_instrument' +rescue StandardError, LoadError => e + warn "Single step instrumentation failed: #{e.class}, #{e.message}" +end diff --git a/sig/datadog/single_step_instrument.rbs b/sig/datadog/single_step_instrument.rbs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spec/datadog/single_step_instrument_spec.rb b/spec/datadog/single_step_instrument_spec.rb new file mode 100644 index 00000000000..26cef7162d4 --- /dev/null +++ b/spec/datadog/single_step_instrument_spec.rb @@ -0,0 +1,23 @@ +RSpec.describe 'Single step instrument' do + it do + expect_in_fork do + expect_any_instance_of(Object) + .to receive(:require_relative).with('auto_instrument').and_raise(LoadError) + + expect do + load 'datadog/single_step_instrument.rb' + end.to output(/Single step instrumentation failed/).to_stderr + end + end + + it do + expect_in_fork do + expect_any_instance_of(Object) + .to receive(:require_relative).with('auto_instrument').and_raise(StandardError) + + expect do + load 'datadog/single_step_instrument.rb' + end.to output(/Single step instrumentation failed/).to_stderr + end + end +end From ac41fd7962abec12d1d94f323720ee359cab349b Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 20 Sep 2024 19:23:30 +0200 Subject: [PATCH 2/4] Add backtrace --- lib/datadog/single_step_instrument.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/single_step_instrument.rb b/lib/datadog/single_step_instrument.rb index c8d5e1218a4..91d75e1bc43 100644 --- a/lib/datadog/single_step_instrument.rb +++ b/lib/datadog/single_step_instrument.rb @@ -8,5 +8,5 @@ begin require_relative 'auto_instrument' rescue StandardError, LoadError => e - warn "Single step instrumentation failed: #{e.class}, #{e.message}" + warn "Single step instrumentation failed: #{e.class}:#{e.message}\n\tSource:\n\t#{Array(e.backtrace).join("\n\t")}" end From fe922cf30b7bfc7261390463c5ca9e35bb537dc7 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 20 Sep 2024 19:31:36 +0200 Subject: [PATCH 3/4] Skip JRuby which does not respond to fork --- spec/datadog/single_step_instrument_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/datadog/single_step_instrument_spec.rb b/spec/datadog/single_step_instrument_spec.rb index 26cef7162d4..f4249f919b8 100644 --- a/spec/datadog/single_step_instrument_spec.rb +++ b/spec/datadog/single_step_instrument_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe 'Single step instrument' do +RSpec.describe 'Single step instrument', skip: !Process.respond_to?(:fork) do it do expect_in_fork do expect_any_instance_of(Object) From 17642d16a355f0de591e99cba387e2b6cbb008d5 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 20 Sep 2024 19:40:23 +0200 Subject: [PATCH 4/4] Exclude linter --- .rubocop_todo.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ca95277508c..93d7206858a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -38,6 +38,7 @@ Metrics/BlockNesting: # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Naming/FileName: Exclude: + - 'lib/datadog/single_step_instrument.rb' - 'lib/datadog/appsec/autoload.rb' - 'lib/datadog/opentelemetry/api/trace/span.rb' - 'lib/datadog/opentelemetry/sdk/trace/span.rb'