Skip to content

Commit

Permalink
do not load DI on ruby 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Nov 4, 2024
1 parent c930fca commit 8396914
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
# Load other products (must follow tracing)
require_relative 'datadog/profiling'
require_relative 'datadog/appsec'
require_relative 'datadog/di'
# Line probes will not work on Ruby < 2.6 because of lack of :script_compiled
# trace point. Only load DI on supported Ruby versions.
if RUBY_VERSION >= '2.6'
require_relative 'datadog/di'
end
require_relative 'datadog/kit'
20 changes: 17 additions & 3 deletions lib/datadog/di.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ def component
end
end

# Activate code tracking by default because line trace points will not work
# without it.
Datadog::DI.activate_tracking!
# :script_compiled trace point was added in Ruby 2.6.
if RUBY_VERSION >= '2.6'
begin
# Activate code tracking by default because line trace points will not work
# without it.
Datadog::DI.activate_tracking!
rescue => exc
if defined?(Datadog.logger)
Datadog.logger.warn("Failed to activate code tracking for DI: #{exc.class}: #{exc}"
else
# We do not have Datadog logger potentially because DI code tracker is
# being loaded early in application boot process and the rest of datadog
# wasn't loaded yet. Output to standard error.
warn("Failed to activate code tracking for DI: #{exc.class}: #{exc}"
end
end
end

0 comments on commit 8396914

Please sign in to comment.