instana 1.11.6 → 1.209.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +263 -0
  3. data/.editorconfig +10 -0
  4. data/.github/ISSUE_TEMPLATE/bug.yml +39 -0
  5. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  6. data/.gitignore +3 -0
  7. data/.rubocop.yml +14 -1136
  8. data/.rubocop_todo.yml +1140 -0
  9. data/Appraisals +124 -0
  10. data/Gemfile +14 -32
  11. data/LICENSE +2 -1
  12. data/README.md +2 -6
  13. data/Rakefile +18 -49
  14. data/bin/console +8 -4
  15. data/docker-compose.yml +20 -0
  16. data/examples/opentracing.rb +4 -0
  17. data/examples/tracing.rb +4 -0
  18. data/extras/license_header.rb +44 -0
  19. data/gemfiles/.bundle/config +1 -2
  20. data/gemfiles/aws_30.gemfile +22 -0
  21. data/gemfiles/cuba_30.gemfile +18 -0
  22. data/gemfiles/dalli_20.gemfile +18 -0
  23. data/gemfiles/excon_02.gemfile +18 -0
  24. data/gemfiles/excon_021.gemfile +18 -0
  25. data/gemfiles/excon_079.gemfile +18 -0
  26. data/gemfiles/graphql_10.gemfile +18 -0
  27. data/gemfiles/grpc_10.gemfile +18 -0
  28. data/gemfiles/mongo_216.gemfile +18 -0
  29. data/gemfiles/net_http_01.gemfile +17 -0
  30. data/gemfiles/rack_16.gemfile +18 -0
  31. data/gemfiles/rack_20.gemfile +18 -0
  32. data/gemfiles/rails_42.gemfile +21 -0
  33. data/gemfiles/rails_50.gemfile +21 -0
  34. data/gemfiles/rails_52.gemfile +21 -0
  35. data/gemfiles/rails_60.gemfile +21 -0
  36. data/gemfiles/redis_40.gemfile +18 -0
  37. data/gemfiles/resque_122.gemfile +19 -0
  38. data/gemfiles/resque_20.gemfile +18 -0
  39. data/gemfiles/rest_client_16.gemfile +18 -0
  40. data/gemfiles/rest_client_20.gemfile +18 -0
  41. data/gemfiles/roda_20.gemfile +18 -0
  42. data/gemfiles/roda_30.gemfile +18 -0
  43. data/gemfiles/shoryuken_50.gemfile +19 -0
  44. data/gemfiles/sidekiq_42.gemfile +18 -0
  45. data/gemfiles/sidekiq_50.gemfile +18 -0
  46. data/gemfiles/sinatra_14.gemfile +18 -0
  47. data/instana.gemspec +8 -14
  48. data/lib/instana/activator.rb +58 -0
  49. data/lib/instana/activators/action_cable.rb +24 -0
  50. data/lib/instana/activators/action_controller_api.rb +21 -0
  51. data/lib/instana/activators/action_controller_base.rb +21 -0
  52. data/lib/instana/activators/action_mailer.rb +22 -0
  53. data/lib/instana/activators/action_view.rb +21 -0
  54. data/lib/instana/activators/active_job.rb +21 -0
  55. data/lib/instana/activators/active_record.rb +21 -0
  56. data/lib/instana/activators/aws_sdk_dynamodb.rb +20 -0
  57. data/lib/instana/activators/aws_sdk_lambda.rb +20 -0
  58. data/lib/instana/activators/aws_sdk_s3.rb +20 -0
  59. data/lib/instana/activators/aws_sdk_sns.rb +20 -0
  60. data/lib/instana/activators/aws_sdk_sqs.rb +20 -0
  61. data/lib/instana/activators/cuba.rb +21 -0
  62. data/lib/instana/activators/dalli.rb +23 -0
  63. data/lib/instana/activators/excon.rb +20 -0
  64. data/lib/instana/activators/graphql.rb +22 -0
  65. data/lib/instana/activators/grpc_client.rb +20 -0
  66. data/lib/instana/activators/grpc_server.rb +20 -0
  67. data/lib/instana/activators/mongo.rb +23 -0
  68. data/lib/instana/activators/net_http.rb +20 -0
  69. data/lib/instana/activators/rack.rb +16 -0
  70. data/lib/instana/activators/rails.rb +18 -0
  71. data/lib/instana/activators/redis.rb +20 -0
  72. data/lib/instana/activators/resque_client.rb +21 -0
  73. data/lib/instana/activators/resque_worker.rb +32 -0
  74. data/lib/instana/activators/rest_client.rb +20 -0
  75. data/lib/instana/activators/roda.rb +21 -0
  76. data/lib/instana/activators/shoryuken.rb +24 -0
  77. data/lib/instana/activators/sidekiq_client.rb +24 -0
  78. data/lib/instana/activators/sidekiq_worker.rb +24 -0
  79. data/lib/instana/activators/sinatra.rb +21 -0
  80. data/lib/instana/backend/agent.rb +68 -0
  81. data/lib/instana/backend/gc_snapshot.rb +41 -0
  82. data/lib/instana/backend/host_agent.rb +83 -0
  83. data/lib/instana/backend/host_agent_activation_observer.rb +99 -0
  84. data/lib/instana/backend/host_agent_lookup.rb +57 -0
  85. data/lib/instana/backend/host_agent_reporting_observer.rb +129 -0
  86. data/lib/instana/backend/process_info.rb +72 -0
  87. data/lib/instana/backend/request_client.rb +74 -0
  88. data/lib/instana/backend/serverless_agent.rb +116 -0
  89. data/lib/instana/base.rb +15 -29
  90. data/lib/instana/config.rb +31 -23
  91. data/lib/instana/frameworks/cuba.rb +32 -3
  92. data/lib/instana/frameworks/rails.rb +22 -32
  93. data/lib/instana/frameworks/roda.rb +41 -3
  94. data/lib/instana/frameworks/sinatra.rb +16 -3
  95. data/lib/instana/instrumentation/action_cable.rb +53 -0
  96. data/lib/instana/instrumentation/action_controller.rb +84 -0
  97. data/lib/instana/instrumentation/action_mailer.rb +22 -0
  98. data/lib/instana/instrumentation/action_view.rb +30 -0
  99. data/lib/instana/instrumentation/active_job.rb +52 -0
  100. data/lib/instana/instrumentation/active_record.rb +50 -0
  101. data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +48 -0
  102. data/lib/instana/instrumentation/aws_sdk_lambda.rb +37 -0
  103. data/lib/instana/instrumentation/aws_sdk_s3.rb +55 -0
  104. data/lib/instana/instrumentation/aws_sdk_sns.rb +29 -0
  105. data/lib/instana/instrumentation/aws_sdk_sqs.rb +98 -0
  106. data/lib/instana/instrumentation/dalli.rb +10 -18
  107. data/lib/instana/instrumentation/excon.rb +73 -61
  108. data/lib/instana/instrumentation/graphql.rb +78 -0
  109. data/lib/instana/instrumentation/grpc.rb +73 -66
  110. data/lib/instana/instrumentation/instrumented_request.rb +190 -0
  111. data/lib/instana/instrumentation/mongo.rb +46 -0
  112. data/lib/instana/instrumentation/net-http.rb +54 -44
  113. data/lib/instana/instrumentation/rack.rb +57 -48
  114. data/lib/instana/instrumentation/redis.rb +13 -18
  115. data/lib/instana/instrumentation/resque.rb +28 -51
  116. data/lib/instana/instrumentation/rest-client.rb +5 -17
  117. data/lib/instana/instrumentation/shoryuken.rb +44 -0
  118. data/lib/instana/instrumentation/sidekiq-client.rb +4 -10
  119. data/lib/instana/instrumentation/sidekiq-worker.rb +4 -10
  120. data/lib/instana/instrumented_logger.rb +26 -0
  121. data/lib/instana/logger_delegator.rb +31 -0
  122. data/lib/instana/open_tracing/carrier.rb +7 -0
  123. data/lib/instana/open_tracing/instana_tracer.rb +99 -0
  124. data/lib/instana/rack.rb +4 -0
  125. data/lib/instana/secrets.rb +59 -0
  126. data/lib/instana/serverless.rb +160 -0
  127. data/lib/instana/setup.rb +36 -12
  128. data/lib/instana/snapshot/deltable.rb +25 -0
  129. data/lib/instana/snapshot/docker_container.rb +151 -0
  130. data/lib/instana/snapshot/fargate_container.rb +88 -0
  131. data/lib/instana/snapshot/fargate_process.rb +67 -0
  132. data/lib/instana/snapshot/fargate_task.rb +72 -0
  133. data/lib/instana/snapshot/google_cloud_run_instance.rb +69 -0
  134. data/lib/instana/snapshot/google_cloud_run_process.rb +58 -0
  135. data/lib/instana/snapshot/lambda_function.rb +39 -0
  136. data/lib/instana/snapshot/ruby_process.rb +48 -0
  137. data/lib/instana/tracer.rb +42 -148
  138. data/lib/instana/tracing/processor.rb +48 -21
  139. data/lib/instana/tracing/span.rb +70 -61
  140. data/lib/instana/tracing/span_context.rb +34 -2
  141. data/lib/instana/util.rb +25 -137
  142. data/lib/instana/version.rb +4 -1
  143. data/lib/instana.rb +12 -2
  144. data/lib/opentracing.rb +29 -3
  145. data/sonar-project.properties +9 -0
  146. data/test/activator_test.rb +30 -0
  147. data/test/backend/agent_test.rb +80 -0
  148. data/test/backend/gc_snapshot_test.rb +11 -0
  149. data/test/backend/host_agent_activation_observer_test.rb +73 -0
  150. data/test/backend/host_agent_lookup_test.rb +78 -0
  151. data/test/backend/host_agent_reporting_observer_test.rb +274 -0
  152. data/test/backend/host_agent_test.rb +57 -0
  153. data/test/backend/process_info_test.rb +83 -0
  154. data/test/backend/request_client_test.rb +39 -0
  155. data/test/backend/serverless_agent_test.rb +83 -0
  156. data/test/benchmarks/bench_id_generation.rb +3 -0
  157. data/test/benchmarks/bench_opentracing.rb +3 -0
  158. data/test/config_test.rb +11 -14
  159. data/test/frameworks/cuba_test.rb +44 -30
  160. data/test/frameworks/roda_test.rb +46 -30
  161. data/test/frameworks/sinatra_test.rb +52 -30
  162. data/test/instana_test.rb +14 -4
  163. data/test/instrumentation/aws_test.rb +196 -0
  164. data/test/instrumentation/dalli_test.rb +3 -0
  165. data/test/instrumentation/excon_test.rb +20 -3
  166. data/test/instrumentation/graphql_test.rb +119 -0
  167. data/test/instrumentation/grpc_test.rb +6 -2
  168. data/test/instrumentation/mongo_test.rb +37 -0
  169. data/test/instrumentation/{net-http_test.rb → net_http_test.rb} +40 -0
  170. data/test/instrumentation/rack_instrumented_request_test.rb +151 -0
  171. data/test/instrumentation/rack_test.rb +404 -0
  172. data/test/instrumentation/rails_action_cable_test.rb +131 -0
  173. data/test/{frameworks/rails/actioncontroller_test.rb → instrumentation/rails_action_controller_test.rb} +48 -17
  174. data/test/instrumentation/rails_action_mailer_test.rb +37 -0
  175. data/test/instrumentation/rails_action_view_test.rb +151 -0
  176. data/test/instrumentation/rails_active_job_test.rb +65 -0
  177. data/test/instrumentation/rails_active_record_database_missing_test.rb +43 -0
  178. data/test/instrumentation/rails_active_record_test.rb +115 -0
  179. data/test/instrumentation/redis_test.rb +13 -0
  180. data/test/instrumentation/resque_test.rb +63 -17
  181. data/test/instrumentation/{rest-client_test.rb → rest_client_test.rb} +9 -0
  182. data/test/instrumentation/shoryuken_test.rb +47 -0
  183. data/test/instrumentation/sidekiq-client_test.rb +4 -0
  184. data/test/instrumentation/sidekiq-worker_test.rb +4 -0
  185. data/test/secrets_test.rb +112 -0
  186. data/test/serverless_test.rb +369 -0
  187. data/test/snapshot/deltable_test.rb +17 -0
  188. data/test/snapshot/docker_container_test.rb +82 -0
  189. data/test/snapshot/fargate_container_test.rb +82 -0
  190. data/test/snapshot/fargate_process_test.rb +35 -0
  191. data/test/snapshot/fargate_task_test.rb +49 -0
  192. data/test/snapshot/google_cloud_run_instance_test.rb +74 -0
  193. data/test/snapshot/google_cloud_run_process_test.rb +33 -0
  194. data/test/snapshot/lambda_function_test.rb +37 -0
  195. data/test/snapshot/ruby_process_test.rb +14 -0
  196. data/test/support/apps/active_record/active_record.rb +24 -0
  197. data/test/{servers/grpc_50051.rb → support/apps/grpc/boot.rb} +4 -1
  198. data/test/{apps → support/apps/grpc}/grpc_server.rb +3 -0
  199. data/test/{servers/rackapp_6511.rb → support/apps/http_endpoint/boot.rb} +3 -0
  200. data/test/{servers/rails_3205.rb → support/apps/rails/boot.rb} +10 -13
  201. data/test/{models → support/apps/rails/models}/block.rb +4 -1
  202. data/test/{models → support/apps/rails/models}/block6.rb +3 -0
  203. data/test/support/apps/resque/boot.rb +5 -0
  204. data/test/{jobs → support/apps/resque/jobs}/resque_error_job.rb +3 -3
  205. data/test/{jobs → support/apps/resque/jobs}/resque_fast_job.rb +6 -3
  206. data/test/support/apps/sidekiq/boot.rb +25 -0
  207. data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_1.rb +3 -0
  208. data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_2.rb +3 -0
  209. data/test/{servers → support/apps}/sidekiq/worker.rb +5 -2
  210. data/test/support/helpers.rb +97 -0
  211. data/test/support/mock_timer.rb +20 -0
  212. data/test/test_helper.rb +49 -145
  213. data/test/tracing/custom_test.rb +4 -4
  214. data/test/tracing/id_management_test.rb +13 -63
  215. data/test/tracing/instrumented_logger_test.rb +39 -0
  216. data/test/tracing/opentracing_test.rb +21 -5
  217. data/test/tracing/processor_test.rb +58 -0
  218. data/test/tracing/span_context_test.rb +22 -0
  219. data/test/tracing/span_test.rb +165 -0
  220. data/test/tracing/tracer_async_test.rb +32 -0
  221. data/test/tracing/tracer_test.rb +113 -14
  222. data/test/util_test.rb +10 -0
  223. metadata +249 -160
  224. data/.travis.yml +0 -43
  225. data/Dockerfile +0 -16
  226. data/benchmarks/10k-rack-traces.rb +0 -92
  227. data/benchmarks/Gemfile +0 -7
  228. data/benchmarks/Gemfile.lock +0 -38
  229. data/benchmarks/id_generation.rb +0 -12
  230. data/benchmarks/opentracing.rb +0 -26
  231. data/benchmarks/rack_vanilla_vs_traced.rb +0 -85
  232. data/benchmarks/stackprof_rack_tracing.rb +0 -77
  233. data/benchmarks/time_processing.rb +0 -12
  234. data/gemfiles/libraries.gemfile +0 -71
  235. data/gemfiles/rails32.gemfile +0 -51
  236. data/gemfiles/rails42.gemfile +0 -50
  237. data/gemfiles/rails50.gemfile +0 -52
  238. data/gemfiles/rails52.gemfile +0 -52
  239. data/gemfiles/rails60.gemfile +0 -72
  240. data/lib/instana/agent/helpers.rb +0 -84
  241. data/lib/instana/agent/hooks.rb +0 -41
  242. data/lib/instana/agent/tasks.rb +0 -48
  243. data/lib/instana/agent.rb +0 -499
  244. data/lib/instana/collector.rb +0 -116
  245. data/lib/instana/collectors/gc.rb +0 -57
  246. data/lib/instana/collectors/memory.rb +0 -34
  247. data/lib/instana/collectors/thread.rb +0 -30
  248. data/lib/instana/eum/eum-test.js.erb +0 -17
  249. data/lib/instana/eum/eum.js.erb +0 -17
  250. data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +0 -58
  251. data/lib/instana/frameworks/instrumentation/action_controller.rb +0 -183
  252. data/lib/instana/frameworks/instrumentation/action_view.rb +0 -43
  253. data/lib/instana/frameworks/instrumentation/active_record.rb +0 -27
  254. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +0 -81
  255. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +0 -56
  256. data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +0 -85
  257. data/lib/instana/helpers.rb +0 -44
  258. data/lib/instana/instrumentation.rb +0 -25
  259. data/lib/instana/opentracing/carrier.rb +0 -4
  260. data/lib/instana/opentracing/tracer.rb +0 -18
  261. data/lib/instana/test.rb +0 -42
  262. data/lib/instana/thread_local.rb +0 -15
  263. data/lib/oj_check.rb +0 -16
  264. data/test/agent/agent_test.rb +0 -148
  265. data/test/apps/cuba.rb +0 -15
  266. data/test/apps/roda.rb +0 -10
  267. data/test/apps/sinatra.rb +0 -5
  268. data/test/frameworks/rack_test.rb +0 -200
  269. data/test/frameworks/rails/actionview3_test.rb +0 -210
  270. data/test/frameworks/rails/actionview4_test.rb +0 -208
  271. data/test/frameworks/rails/actionview5_test.rb +0 -221
  272. data/test/frameworks/rails/activerecord_test.rb +0 -227
  273. data/test/servers/helpers/sidekiq_worker_initializer.rb +0 -27
  274. data/test/tracing/trace_test.rb +0 -67
@@ -0,0 +1,23 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Dalli < Activator
7
+ def can_instrument?
8
+ defined?(::Dalli::Client) &&
9
+ defined?(::Dalli::Server) &&
10
+ Instana.config[:dalli][:enabled]
11
+ end
12
+
13
+ def instrument
14
+ require 'instana/instrumentation/dalli'
15
+
16
+ ::Dalli::Client.prepend ::Instana::Instrumentation::Dalli
17
+ ::Dalli::Server.prepend ::Instana::Instrumentation::DalliServer
18
+
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Excon < Activator
7
+ def can_instrument?
8
+ defined?(::Excon) && defined?(::Excon::Middleware::Base) && ::Excon.respond_to?(:defaults) && Instana.config[:excon][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/excon'
13
+
14
+ ::Excon.defaults[:middlewares].unshift(::Instana::Instrumentation::Excon)
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Graphql < Activator
7
+ def can_instrument?
8
+ defined?(::GraphQL::Schema) &&
9
+ defined?(GraphQL::Tracing::PlatformTracing) &&
10
+ Instana.config[:graphql][:enabled]
11
+ end
12
+
13
+ def instrument
14
+ require 'instana/instrumentation/graphql'
15
+
16
+ ::GraphQL::Schema.use(::Instana::Instrumentation::GraphqlTracing)
17
+
18
+ true
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class GrpcClient < Activator
7
+ def can_instrument?
8
+ defined?(::GRPC::ActiveCall) && ::Instana.config[:grpc][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/grpc'
13
+
14
+ ::GRPC::ClientStub.prepend(::Instana::Instrumentation::GRPCCientInstrumentation)
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class GrpcServer < Activator
7
+ def can_instrument?
8
+ defined?(::GRPC::RpcDesc) && ::Instana.config[:grpc][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/grpc'
13
+
14
+ ::GRPC::RpcDesc.prepend(::Instana::Instrumentation::GRPCServerInstrumentation)
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Mongo < Activator
7
+ def can_instrument?
8
+ defined?(::Mongo::Client) && defined?(::Mongo::Monitoring::Global)
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/mongo'
13
+
14
+ ::Mongo::Monitoring::Global.subscribe(
15
+ ::Mongo::Monitoring::COMMAND,
16
+ ::Instana::Mongo.new
17
+ )
18
+
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class NetHTTP < Activator
7
+ def can_instrument?
8
+ defined?(::Net::HTTP) && ::Instana.config[:nethttp][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/net-http'
13
+
14
+ ::Net::HTTP.prepend(::Instana::Instrumentation::NetHTTPInstrumentation)
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Rack < Activator
7
+ def can_instrument?
8
+ defined?(::Rack)
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/rack'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Rails < Activator
7
+ def can_instrument?
8
+ defined?(::Instana::Rack) &&
9
+ defined?(::Rails) &&
10
+ defined?(::Rails::VERSION)
11
+ end
12
+
13
+ def instrument
14
+ require 'instana/frameworks/rails'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Redis < Activator
7
+ def can_instrument?
8
+ defined?(::Redis) && defined?(::Redis::Client) && ::Instana.config[:redis][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/redis'
13
+
14
+ ::Redis::Client.prepend(::Instana::RedisInstrumentation)
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class ResqueClient < Activator
7
+ def can_instrument?
8
+ defined?(::Resque) &&
9
+ ::Instana.config[:'resque-client'][:enabled]
10
+ end
11
+
12
+ def instrument
13
+ require 'instana/instrumentation/resque'
14
+
15
+ ::Resque.prepend(::Instana::Instrumentation::ResqueClient)
16
+
17
+ true
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class ResqueWorker < Activator
7
+ def can_instrument?
8
+ defined?(::Resque::Worker) &&
9
+ defined?(::Resque::Job) &&
10
+ ::Instana.config[:'resque-worker'][:enabled]
11
+ end
12
+
13
+ def instrument
14
+ require 'instana/instrumentation/resque'
15
+
16
+ ::Resque::Worker.prepend(::Instana::Instrumentation::ResqueWorker)
17
+ ::Resque::Job.prepend(::Instana::Instrumentation::ResqueJob)
18
+
19
+ if ::Instana.config[:'resque-worker'][:'setup-fork']
20
+ ::Resque.after_fork do |_job|
21
+ ::Instana.agent.after_fork
22
+ end
23
+ end
24
+
25
+ # Set this so we assure that any remaining collected traces are reported at_exit
26
+ ENV['RUN_AT_EXIT_HOOKS'] = "1"
27
+
28
+ true
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class RestClient < Activator
7
+ def can_instrument?
8
+ defined?(::RestClient::Request) && ::Instana.config[:'rest-client'][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/rest-client'
13
+
14
+ ::RestClient::Request.prepend ::Instana::Instrumentation::RestClientRequest
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Roda < Activator
7
+ def can_instrument?
8
+ defined?(::Instana::Rack) && defined?(::Roda)
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/frameworks/roda'
13
+
14
+ ::Roda.use ::Instana::Rack
15
+ ::Roda.plugin ::Instana::RodaPathTemplateExtractor
16
+
17
+ true
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Shoryuken < Activator
7
+ def can_instrument?
8
+ defined?(::Shoryuken) && ::Shoryuken.respond_to?(:configure_server)
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/shoryuken'
13
+
14
+ ::Shoryuken.configure_server do |config|
15
+ config.server_middleware do |chain|
16
+ chain.add ::Instana::Instrumentation::Shoryuken
17
+ end
18
+ end
19
+
20
+ true
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class SidekiqClient < Activator
7
+ def can_instrument?
8
+ defined?(::Sidekiq) && ::Sidekiq.respond_to?(:configure_client) && ::Instana.config[:'sidekiq-client'][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/sidekiq-client'
13
+
14
+ ::Sidekiq.configure_client do |cfg|
15
+ cfg.client_middleware do |chain|
16
+ chain.add ::Instana::Instrumentation::SidekiqClient
17
+ end
18
+ end
19
+
20
+ true
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class SidekiqWorker < Activator
7
+ def can_instrument?
8
+ defined?(::Sidekiq) && ::Sidekiq.respond_to?(:configure_server) && ::Instana.config[:'sidekiq-worker'][:enabled]
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/sidekiq-worker'
13
+
14
+ ::Sidekiq.configure_server do |cfg|
15
+ cfg.server_middleware do |chain|
16
+ chain.add ::Instana::Instrumentation::SidekiqWorker
17
+ end
18
+ end
19
+
20
+ true
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Sinatra < Activator
7
+ def can_instrument?
8
+ defined?(::Instana::Rack) && defined?(::Sinatra) && defined?(::Sinatra::Base) && !::Sinatra::Base.middleware.nil?
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/frameworks/sinatra'
13
+
14
+ ::Sinatra::Base.use ::Instana::Rack
15
+ ::Sinatra::Base.register ::Instana::SinatraPathTemplateExtractor
16
+
17
+ true
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Backend
6
+ # Wrapper class around the various transport backends
7
+ # @since 1.197.0
8
+ class Agent
9
+ attr_reader :delegate
10
+
11
+ def initialize(fargate_metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'], logger: ::Instana.logger)
12
+ @delegate = nil
13
+ @logger = logger
14
+ @fargate_metadata_uri = fargate_metadata_uri
15
+ end
16
+
17
+ def setup
18
+ @delegate = if ENV.key?('_HANDLER')
19
+ ServerlessAgent.new([Snapshot::LambdaFunction.new])
20
+ elsif ENV.key?('K_REVISION') && ENV.key?('INSTANA_ENDPOINT_URL')
21
+ ServerlessAgent.new([
22
+ Snapshot::GoogleCloudRunProcess.new,
23
+ Snapshot::GoogleCloudRunInstance.new,
24
+ Snapshot::RubyProcess.new
25
+ ])
26
+ elsif @fargate_metadata_uri && ENV.key?('INSTANA_ENDPOINT_URL')
27
+ ServerlessAgent.new(fargate_snapshots)
28
+ else
29
+ HostAgent.new
30
+ end
31
+
32
+ @delegate.setup
33
+ end
34
+
35
+ def method_missing(mth, *args, &block)
36
+ if @delegate.respond_to?(mth)
37
+ @delegate.public_send(mth, *args, &block)
38
+ else
39
+ super(mth, *args, &block)
40
+ end
41
+ end
42
+
43
+ def respond_to_missing?(mth, include_all = false)
44
+ @delegate.respond_to?(mth, include_all)
45
+ end
46
+
47
+ private
48
+
49
+ def fargate_snapshots
50
+ metadata_uri = URI(@fargate_metadata_uri)
51
+ client = Backend::RequestClient.new(metadata_uri.host, metadata_uri.port, use_ssl: metadata_uri.scheme == "https")
52
+ response = client.send_request('GET', "#{metadata_uri.path}/task")
53
+
54
+ if response.ok?
55
+ docker = response
56
+ .json['Containers']
57
+ .map { |c| [Snapshot::DockerContainer.new(c), Snapshot::FargateContainer.new(c)] }
58
+ .flatten
59
+
60
+ docker + [Snapshot::FargateProcess.new, Snapshot::RubyProcess.new, Snapshot::FargateTask.new]
61
+ else
62
+ @logger.warn("Received #{response.code} when requesting containers.")
63
+ []
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,41 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ require 'singleton'
5
+
6
+ module Instana
7
+ module Backend
8
+ # Keeps track of garbage collector related metrics
9
+ # @since 1.197.0
10
+ class GCSnapshot
11
+ include Singleton
12
+
13
+ def initialize
14
+ ::GC::Profiler.enable
15
+
16
+ @last_major_count = 0
17
+ @last_minor_count = 0
18
+ end
19
+
20
+ def report
21
+ stats = ::GC.stat
22
+ total_time = ::GC::Profiler.total_time * 1000
23
+
24
+ ::GC::Profiler.clear
25
+
26
+ payload = {
27
+ totalTime: total_time,
28
+ heap_live: stats[:heap_live_slots] || stats[:heap_live_num],
29
+ heap_free: stats[:heap_free_slots] || stats[:heap_free_num],
30
+ minorGcs: stats[:minor_gc_count] - @last_minor_count,
31
+ majorGcs: stats[:major_gc_count] - @last_major_count
32
+ }
33
+
34
+ @last_major_count = stats[:major_gc_count]
35
+ @last_minor_count = stats[:minor_gc_count]
36
+
37
+ payload
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,83 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Backend
6
+ # @since 1.197.0
7
+ class HostAgent
8
+ attr_reader :future, :client
9
+
10
+ def initialize(discovery: Concurrent::Atom.new(nil), logger: ::Instana.logger)
11
+ @discovery = discovery
12
+ @logger = logger
13
+ @future = nil
14
+ @client = nil
15
+ end
16
+
17
+ def setup; end
18
+
19
+ def spawn_background_thread
20
+ return if ENV.key?('INSTANA_TEST')
21
+
22
+ @future = Concurrent::Promises.future do
23
+ announce
24
+ end
25
+ end
26
+
27
+ alias start spawn_background_thread
28
+
29
+ def announce
30
+ @client = until_not_nil { HostAgentLookup.new.call }
31
+ @discovery.delete_observers
32
+ @discovery
33
+ .with_observer(HostAgentActivationObserver.new(@client, @discovery))
34
+ .with_observer(HostAgentReportingObserver.new(@client, @discovery))
35
+
36
+ @discovery.swap { nil }
37
+ @client
38
+ end
39
+
40
+ alias after_fork announce
41
+
42
+ # @return [Boolean] true if the agent able to send spans to the backend
43
+ def ready?
44
+ ENV.key?('INSTANA_TEST') || !@discovery.value.nil?
45
+ end
46
+
47
+ # @return [Hash, NilClass] the backend friendly description of the current in process collector
48
+ def source
49
+ {
50
+ e: discovery_value['pid'],
51
+ h: discovery_value['agentUuid']
52
+ }.reject { |_, v| v.nil? }
53
+ end
54
+
55
+ # @return [Array] extra headers to include in the trace
56
+ def extra_headers
57
+ discovery_value['extraHeaders']
58
+ end
59
+
60
+ # @return [Hash] values which are removed from urls sent to the backend
61
+ def secret_values
62
+ discovery_value['secrets']
63
+ end
64
+
65
+ private
66
+
67
+ def until_not_nil
68
+ loop do
69
+ result = yield
70
+ return result unless result.nil?
71
+
72
+ @logger.debug("Waiting on a connection to the agent.")
73
+ sleep(1)
74
+ end
75
+ end
76
+
77
+ def discovery_value
78
+ v = @discovery.value
79
+ v || {}
80
+ end
81
+ end
82
+ end
83
+ end