scoutapp / scout_apm_ruby

ScoutAPM Ruby Agent. Supports Rails, Sinatra, Grape, Rack, and many other frameworks

Home Page:https://scoutapm.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

conflict with opentelemetry-instrumentation-redis 0.15

mjobin-mdsol opened this issue · comments

I am encountering a weird race condition involving adding the scout_apm gem to an app with uses delayed_jobs and opentelemetry-instrumentation-redis

seems like it creates an infinite loop between the two gems


51 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/tracer.rb:34:in `instrument'
-- | -- | --
52 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/instruments/redis.rb:32:in `block in call_with_scout_instruments'
53 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-instrumentation-redis-0.15.0/lib/opentelemetry/instrumentation/redis/patches/client.rb:18:in `call'
54 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace/tracer.rb:29:in `in_span'
55 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace.rb:82:in `with_span'
56 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/context.rb:62:in `with_value'
57 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace.rb:82:in `block in with_span'
58 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace/tracer.rb:29:in `block in in_span'
59 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-instrumentation-redis-0.15.0/lib/opentelemetry/instrumentation/redis/patches/client.rb:23:in `block in call'
60 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/instruments/redis.rb:31:in `call_with_scout_instruments'
61 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/tracer.rb:44:in `instrument'
62 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/tracer.rb:34:in `instrument'
63 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/instruments/redis.rb:32:in `block in call_with_scout_instruments'
64 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-instrumentation-redis-0.15.0/lib/opentelemetry/instrumentation/redis/patches/client.rb:18:in `call'
65 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace/tracer.rb:29:in `in_span'
66 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace.rb:82:in `with_span'
67 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/context.rb:62:in `with_value'
68 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace.rb:82:in `block in with_span'
69 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-api-0.15.0/lib/opentelemetry/trace/tracer.rb:29:in `block in in_span'
70 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-instrumentation-redis-0.15.0/lib/opentelemetry/instrumentation/redis/patches/client.rb:23:in `block in call'
71 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/instruments/redis.rb:31:in `call_with_scout_instruments'
72 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/tracer.rb:44:in `instrument'
73 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/tracer.rb:34:in `instrument'
74 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/scout_apm-4.0.4/lib/scout_apm/instruments/redis.rb:32:in `block in call_with_scout_instruments'
75 | 03/23/202113:30:17.793 +0900 | /home/app/web/vendor/bundle/ruby/2.6.0/gems/opentelemetry-instrumentation-redis-0.15.0/lib/opentelemetry/instrumentation/redis/patches/client.rb:18:in `call'

This is obviously a mix-&-match for Module#prepend and legacy method aliasing.

opentelemetry/instrumentation/redis/patches/client.rb:23 calls super, which is call_with_scout_instruments
and then call_with_scout_instruments is now an alias of OpenTelemetry method prepend patching, which calls Scout again .. and again, creating the infinite loop

Please update to use Module#prepend which requires ruby 2.0 as a private method, 2.1 as a public method ;)

@mjobin-mdsol Thanks for the report. You're correct that it's a conflict in which method we use to instrument. We'll update the instrumentation to use prepend.

any updates here?

@dlanderson your dev branch works for this
problem solved, but expecting an official release

works fine with v4.1.1

heads up, you'll hit this problem again with newrelic_rpm (7.2.0)