Skip to content

Commit

Permalink
Ensure fork
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Jul 5, 2024
1 parent 3d44b89 commit 89dffeb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib-injection/host_inject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 89dffeb

Please sign in to comment.