getappmap / appmap-ruby

AppMap client agent for Ruby
https://appland.org
Other
98 stars 11 forks source link

Only the first shallow call of a sequence of calls is recorded on shallow mode #355

Open zermelo-wisen opened 3 months ago

zermelo-wisen commented 3 months ago

While implementing the shallow mode for appmap-node agent I noticed this and it's been checked by @dividedmind:

I just checked and for example require 'active_support/core_ext'

class Calc
def calc x
y = x.minutes.ago
z = 1.year.ago
y.to_i - z.to_i
end
end

indeed only records #minutes, ignoring #year and both invocations of #ago.

It seems that the problem is with this line return false if hook_package&.shallow? && AppMap.tracing.last_package_for_current_thread == hook_package that checks the last recorded package. Because no other package is recorded between the calls mentioned, the last package stays the same. This causes subsequent calls to be skipped from recording, even if they are also "shallow" calls. A stack based approach can be used to fix this.