From 89dffeb940c0255295b4b1aa9effd77abcd55b53 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 5 Jul 2024 13:19:29 +0200 Subject: [PATCH] Ensure fork --- lib-injection/host_inject.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib-injection/host_inject.rb b/lib-injection/host_inject.rb index 8f7fbc0978e..1f1b56a6837 100644 --- a/lib-injection/host_inject.rb +++ b/lib-injection/host_inject.rb @@ -10,11 +10,13 @@ require 'json' def dd_debug_log(msg) - $stdout.puts "[datadog] #{msg}" if ENV['DD_TRACE_DEBUG'] == 'true' + pid = Process.respond_to?(:pid) ? Process.pid : 0 # Not available on all platforms + $stdout.puts "[datadog][#{pid}][#{$0}] #{msg}" if ENV['DD_TRACE_DEBUG'] == 'true' end def dd_error_log(msg) - warn "[datadog] #{msg}" + pid = Process.respond_to?(:pid) ? Process.pid : 0 # Not available on all platforms + warn "[datadog][#{pid}][#{$0}] #{msg}" end def dd_skip_injection! @@ -92,6 +94,11 @@ def dd_send_telemetry(events) return # Skip injection end + unless Process.respond_to?(:fork) + dd_debug_log 'Fork not supported... skipping injection' + return + end + already_installed = ['ddtrace', 'datadog'].any? do |gem| fork { $stdout = File.new("/dev/null", "w") @@ -204,7 +211,8 @@ def dd_send_telemetry(events) ] ) end - warn "[datadog] Injection failed: #{e.class.name} #{e.message}\nBacktrace: #{e.backtrace.join("\n")}" + pid = Process.respond_to?(:pid) ? Process.pid : 0 # Not available on all platforms + warn "[datadog][#{pid}][#{$0}] Injection failed: #{e.class.name} #{e.message}\nBacktrace: #{e.backtrace.join("\n")}" # Skip injection if the environment variable is set ENV['DD_TRACE_SKIP_LIB_INJECTION'] = 'true'