Skip to content

Commit 50e2f8e

Browse files
authored
Merge pull request #1552 from DataDog/ivoanjo/handle-nameerror-during-initialization
Handle NameError during profiler initialization
2 parents c3873da + 6f2df50 commit 50e2f8e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/ddtrace/configuration/components.rb

+29
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,35 @@ def build_tracer(settings, agent_settings)
7373
def build_profiler(settings, agent_settings)
7474
return unless Datadog::Profiling.supported? && settings.profiling.enabled
7575

76+
unless defined?(Datadog::Profiling::Tasks::Setup)
77+
# In #1545 a user reported a NameError due to this constant being uninitialized
78+
# I've documented my suspicion on why that happened in
79+
# https://github.com/DataDog/dd-trace-rb/issues/1545#issuecomment-856049025
80+
#
81+
# > Thanks for the info! It seems to feed into my theory: there's two moments in the code where we check if
82+
# > profiler is "supported": 1) when loading ddtrace (inside preload) and 2) when starting the profile
83+
# > after Datadog.configure gets run.
84+
# > The problem is that the code assumes that both checks 1) and 2) will always reach the same conclusion:
85+
# > either profiler is supported, or profiler is not supported.
86+
# > In the problematic case, it looks like in your case check 1 decides that profiler is not
87+
# > supported => doesn't load it, and then check 2 decides that it is => assumes it is loaded and tries to
88+
# > start it.
89+
#
90+
# I was never able to validate if this was the issue or why exactly .supported? would change its mind BUT
91+
# just in case it happens again, I've left this check which avoids breaking the user's application AND
92+
# would instead direct them to report it to us instead, so that we can investigate what's wrong.
93+
#
94+
# TODO: As of June 2021, most checks in .supported? are related to the google-protobuf gem; so it's
95+
# very likely that it was the origin of the issue we saw. Thus, if, as planned we end up moving away from
96+
# protobuf OR enough time has passed and no users saw the issue again, we can remove this check altogether.
97+
Datadog.logger.error(
98+
'Profiling was marked as supported and enabled, but setup task was not loaded properly. ' \
99+
'Please report this at https://github.com/DataDog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug'
100+
)
101+
102+
return
103+
end
104+
76105
# Load extensions needed to support some of the Profiling features
77106
Datadog::Profiling::Tasks::Setup.new.run
78107

0 commit comments

Comments
 (0)