Skip to content

Commit

Permalink
Merge pull request #1552 from DataDog/ivoanjo/handle-nameerror-during…
Browse files Browse the repository at this point in the history
…-initialization

Handle NameError during profiler initialization
  • Loading branch information
ivoanjo authored Jun 10, 2021
2 parents c3873da + 6f2df50 commit 50e2f8e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/ddtrace/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ 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.
#
# TODO: As of June 2021, most checks in .supported? are related to the google-protobuf gem; so it's
# very likely that it was the origin of the issue we saw. Thus, if, as planned we end up moving away from
# protobuf OR enough time has passed and no users saw the issue again, we can remove this check altogether.
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 50e2f8e

Please sign in to comment.