Skip to content

Commit

Permalink
Handle NameError during profiler initialization
Browse files Browse the repository at this point in the history
In #1545 a user reported a NameError during profiler initialization.

I wasn't able to reproduce the issue, but I've added a small check and
a nicer message in case it comes back to ask users to report the issue
to us, and that avoids breaking their application.

Issue #1545
  • Loading branch information
ivoanjo committed Jun 9, 2021
1 parent b20dc3b commit f5776d1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/ddtrace/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ def build_tracer(settings, agent_settings)
def build_profiler(settings, agent_settings)
return unless Datadog::Profiling.supported? && settings.profiling.enabled

unless defined?(Datadog::Profiling::Tasks::Setup)
# In #1545 a user reported a NameError due to this constant being uninitialized
# I've documented my suspicion on why that happened in
# https://github.com/DataDog/dd-trace-rb/issues/1545#issuecomment-856049025
#
# > Thanks for the info! It seems to feed into my theory: there's two moments in the code where we check if
# > profiler is "supported": 1) when loading ddtrace (inside preload) and 2) when starting the profile
# > after Datadog.configure gets run.
# > The problem is that the code assumes that both checks 1) and 2) will always reach the same conclusion:
# > either profiler is supported, or profiler is not supported.
# > In the problematic case, it looks like in your case check 1 decides that profiler is not
# > supported => doesn't load it, and then check 2 decides that it is => assumes it is loaded and tries to
# > start it.
#
# I was never able to validate if this was the issue or why exactly .supported? would change its mind BUT
# just in case it happens again, I've left this check which avoids breaking the user's application AND
# would instead direct them to report it to us instead, so that we can investigate what's wrong.
Datadog.logger.error(
'Profiling was marked as supported and enabled, but setup task was not loaded properly. ' \
'Please report this at https://github.com/DataDog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug'
)

return
end

# Load extensions needed to support some of the Profiling features
Datadog::Profiling::Tasks::Setup.new.run

Expand Down

0 comments on commit f5776d1

Please sign in to comment.