instana 1.192.1 → 1.193.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +200 -133
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +10 -1145
  5. data/.rubocop_todo.yml +1140 -0
  6. data/Appraisals +103 -0
  7. data/Gemfile +14 -32
  8. data/LICENSE +2 -1
  9. data/Rakefile +19 -39
  10. data/benchmarks/10k-rack-traces.rb +3 -0
  11. data/benchmarks/Gemfile +4 -0
  12. data/benchmarks/id_generation.rb +4 -0
  13. data/benchmarks/opentracing.rb +4 -0
  14. data/benchmarks/rack_vanilla_vs_traced.rb +3 -0
  15. data/benchmarks/stackprof_rack_tracing.rb +3 -0
  16. data/benchmarks/time_processing.rb +4 -0
  17. data/bin/console +8 -4
  18. data/examples/opentracing.rb +4 -0
  19. data/examples/tracing.rb +4 -0
  20. data/extras/license_header.rb +44 -0
  21. data/gemfiles/.bundle/config +1 -2
  22. data/gemfiles/cuba_30.gemfile +18 -0
  23. data/gemfiles/dalli_20.gemfile +18 -0
  24. data/gemfiles/excon_02.gemfile +18 -0
  25. data/gemfiles/graphql_10.gemfile +18 -0
  26. data/gemfiles/grpc_10.gemfile +18 -0
  27. data/gemfiles/net_http_01.gemfile +17 -0
  28. data/gemfiles/rack_16.gemfile +18 -0
  29. data/gemfiles/rack_20.gemfile +18 -0
  30. data/gemfiles/rails_42.gemfile +21 -0
  31. data/gemfiles/rails_50.gemfile +21 -0
  32. data/gemfiles/rails_52.gemfile +21 -0
  33. data/gemfiles/rails_60.gemfile +21 -0
  34. data/gemfiles/redis_40.gemfile +18 -0
  35. data/gemfiles/resque_122.gemfile +19 -0
  36. data/gemfiles/resque_20.gemfile +18 -0
  37. data/gemfiles/rest_client_16.gemfile +18 -0
  38. data/gemfiles/rest_client_20.gemfile +18 -0
  39. data/gemfiles/roda_20.gemfile +18 -0
  40. data/gemfiles/roda_30.gemfile +18 -0
  41. data/gemfiles/sidekiq_42.gemfile +18 -0
  42. data/gemfiles/sidekiq_50.gemfile +18 -0
  43. data/gemfiles/sinatra_14.gemfile +18 -0
  44. data/instana.gemspec +5 -7
  45. data/lib/instana.rb +3 -0
  46. data/lib/instana/activator.rb +44 -0
  47. data/lib/instana/activators/action_cable.rb +24 -0
  48. data/lib/instana/activators/action_controller_api.rb +21 -0
  49. data/lib/instana/activators/action_controller_base.rb +21 -0
  50. data/lib/instana/activators/action_view.rb +21 -0
  51. data/lib/instana/activators/active_record.rb +21 -0
  52. data/lib/instana/activators/cuba.rb +21 -0
  53. data/lib/instana/activators/dalli.rb +23 -0
  54. data/lib/instana/activators/excon.rb +20 -0
  55. data/lib/instana/activators/graphql.rb +22 -0
  56. data/lib/instana/activators/grpc_client.rb +20 -0
  57. data/lib/instana/activators/grpc_server.rb +20 -0
  58. data/lib/instana/activators/net_http.rb +20 -0
  59. data/lib/instana/activators/rack.rb +16 -0
  60. data/lib/instana/activators/rails.rb +18 -0
  61. data/lib/instana/activators/redis.rb +20 -0
  62. data/lib/instana/activators/resque_client.rb +21 -0
  63. data/lib/instana/activators/resque_worker.rb +33 -0
  64. data/lib/instana/activators/rest_client.rb +20 -0
  65. data/lib/instana/activators/roda.rb +21 -0
  66. data/lib/instana/activators/sidekiq_client.rb +24 -0
  67. data/lib/instana/activators/sidekiq_worker.rb +24 -0
  68. data/lib/instana/activators/sinatra.rb +21 -0
  69. data/lib/instana/agent.rb +3 -0
  70. data/lib/instana/agent/helpers.rb +3 -0
  71. data/lib/instana/agent/hooks.rb +3 -0
  72. data/lib/instana/agent/tasks.rb +3 -0
  73. data/lib/instana/base.rb +3 -0
  74. data/lib/instana/collector.rb +3 -0
  75. data/lib/instana/collectors/gc.rb +3 -0
  76. data/lib/instana/collectors/memory.rb +3 -0
  77. data/lib/instana/collectors/thread.rb +3 -0
  78. data/lib/instana/config.rb +3 -0
  79. data/lib/instana/frameworks/cuba.rb +9 -13
  80. data/lib/instana/frameworks/rails.rb +22 -32
  81. data/lib/instana/frameworks/roda.rb +10 -13
  82. data/lib/instana/frameworks/sinatra.rb +4 -8
  83. data/lib/instana/helpers.rb +3 -0
  84. data/lib/instana/instrumentation/action_cable.rb +53 -0
  85. data/lib/instana/instrumentation/action_controller.rb +84 -0
  86. data/lib/instana/instrumentation/action_view.rb +30 -0
  87. data/lib/instana/instrumentation/active_record.rb +50 -0
  88. data/lib/instana/instrumentation/dalli.rb +10 -18
  89. data/lib/instana/instrumentation/excon.rb +54 -57
  90. data/lib/instana/instrumentation/graphql.rb +19 -18
  91. data/lib/instana/instrumentation/grpc.rb +73 -66
  92. data/lib/instana/instrumentation/instrumented_request.rb +6 -1
  93. data/lib/instana/instrumentation/net-http.rb +46 -47
  94. data/lib/instana/instrumentation/rack.rb +4 -0
  95. data/lib/instana/instrumentation/redis.rb +13 -18
  96. data/lib/instana/instrumentation/resque.rb +17 -50
  97. data/lib/instana/instrumentation/rest-client.rb +5 -17
  98. data/lib/instana/instrumentation/sidekiq-client.rb +3 -9
  99. data/lib/instana/instrumentation/sidekiq-worker.rb +3 -9
  100. data/lib/instana/opentracing/carrier.rb +3 -0
  101. data/lib/instana/opentracing/tracer.rb +3 -0
  102. data/lib/instana/rack.rb +4 -0
  103. data/lib/instana/secrets.rb +10 -7
  104. data/lib/instana/setup.rb +6 -1
  105. data/lib/instana/thread_local.rb +3 -0
  106. data/lib/instana/tracer.rb +3 -0
  107. data/lib/instana/tracing/processor.rb +3 -0
  108. data/lib/instana/tracing/span.rb +3 -0
  109. data/lib/instana/tracing/span_context.rb +3 -0
  110. data/lib/instana/util.rb +4 -41
  111. data/lib/instana/version.rb +4 -1
  112. data/lib/oj_check.rb +3 -0
  113. data/lib/opentracing.rb +3 -0
  114. data/test/activator_test.rb +30 -0
  115. data/test/agent/agent_test.rb +3 -0
  116. data/test/benchmarks/bench_id_generation.rb +3 -0
  117. data/test/benchmarks/bench_opentracing.rb +3 -0
  118. data/test/config_test.rb +3 -0
  119. data/test/frameworks/cuba_test.rb +41 -40
  120. data/test/frameworks/roda_test.rb +43 -41
  121. data/test/frameworks/sinatra_test.rb +64 -64
  122. data/test/instana_test.rb +3 -0
  123. data/test/instrumentation/dalli_test.rb +3 -0
  124. data/test/instrumentation/excon_test.rb +4 -0
  125. data/test/instrumentation/graphql_test.rb +3 -0
  126. data/test/instrumentation/grpc_test.rb +5 -1
  127. data/test/instrumentation/{net-http_test.rb → net_http_test.rb} +4 -0
  128. data/test/instrumentation/{instrumented_request_test.rb → rack_instrumented_request_test.rb} +4 -1
  129. data/test/{frameworks → instrumentation}/rack_test.rb +3 -1
  130. data/test/instrumentation/rails_action_cable_test.rb +131 -0
  131. data/test/{frameworks/rails/actioncontroller_test.rb → instrumentation/rails_action_controller_test.rb} +40 -21
  132. data/test/instrumentation/rails_action_view_test.rb +151 -0
  133. data/test/instrumentation/rails_active_record_test.rb +122 -0
  134. data/test/instrumentation/redis_test.rb +3 -0
  135. data/test/instrumentation/resque_test.rb +6 -11
  136. data/test/instrumentation/{rest-client_test.rb → rest_client_test.rb} +9 -0
  137. data/test/instrumentation/sidekiq-client_test.rb +4 -0
  138. data/test/instrumentation/sidekiq-worker_test.rb +4 -0
  139. data/test/secrets_test.rb +3 -0
  140. data/test/support/apps/active_record/active_record.rb +24 -0
  141. data/test/{servers/grpc_50051.rb → support/apps/grpc/boot.rb} +4 -1
  142. data/test/{apps → support/apps/grpc}/grpc_server.rb +3 -0
  143. data/test/{servers/rackapp_6511.rb → support/apps/http_endpoint/boot.rb} +3 -0
  144. data/test/{servers/rails_3205.rb → support/apps/rails/boot.rb} +10 -13
  145. data/test/{models → support/apps/rails/models}/block.rb +4 -1
  146. data/test/{models → support/apps/rails/models}/block6.rb +3 -0
  147. data/test/support/apps/resque/boot.rb +5 -0
  148. data/test/{jobs → support/apps/resque/jobs}/resque_error_job.rb +3 -0
  149. data/test/{jobs → support/apps/resque/jobs}/resque_fast_job.rb +3 -0
  150. data/test/support/apps/sidekiq/boot.rb +25 -0
  151. data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_1.rb +3 -0
  152. data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_2.rb +3 -0
  153. data/test/{servers → support/apps}/sidekiq/worker.rb +5 -2
  154. data/test/support/helpers.rb +97 -0
  155. data/test/test_helper.rb +27 -144
  156. data/test/tracing/custom_test.rb +3 -0
  157. data/test/tracing/id_management_test.rb +4 -0
  158. data/test/tracing/opentracing_test.rb +3 -0
  159. data/test/tracing/tracer_async_test.rb +3 -0
  160. data/test/tracing/tracer_test.rb +3 -0
  161. metadata +105 -96
  162. data/gemfiles/libraries.gemfile +0 -73
  163. data/gemfiles/rails32.gemfile +0 -51
  164. data/gemfiles/rails42.gemfile +0 -50
  165. data/gemfiles/rails50.gemfile +0 -52
  166. data/gemfiles/rails52.gemfile +0 -52
  167. data/gemfiles/rails60.gemfile +0 -72
  168. data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +0 -58
  169. data/lib/instana/frameworks/instrumentation/action_controller.rb +0 -194
  170. data/lib/instana/frameworks/instrumentation/action_view.rb +0 -43
  171. data/lib/instana/frameworks/instrumentation/active_record.rb +0 -27
  172. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +0 -87
  173. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +0 -62
  174. data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +0 -103
  175. data/lib/instana/instrumentation.rb +0 -25
  176. data/lib/instana/test.rb +0 -43
  177. data/test/apps/cuba.rb +0 -19
  178. data/test/apps/roda.rb +0 -13
  179. data/test/apps/sinatra.rb +0 -9
  180. data/test/frameworks/rails/actionview3_test.rb +0 -210
  181. data/test/frameworks/rails/actionview4_test.rb +0 -208
  182. data/test/frameworks/rails/actionview5_test.rb +0 -221
  183. data/test/frameworks/rails/activerecord_test.rb +0 -279
  184. data/test/servers/helpers/sidekiq_worker_initializer.rb +0 -27
@@ -0,0 +1,30 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Instrumentation
6
+ module ActionView
7
+ def render_partial(*args)
8
+ call_payload = {
9
+ render: {
10
+ type: :partial,
11
+ name: @options.is_a?(Hash) ? @options[:partial].to_s : 'Unknown'
12
+ }
13
+ }
14
+
15
+ ::Instana::Tracer.trace(:render, call_payload) { super(*args) }
16
+ end
17
+
18
+ def render_collection(*args)
19
+ call_payload = {
20
+ render: {
21
+ type: :collection,
22
+ name: @path.to_s
23
+ }
24
+ }
25
+
26
+ ::Instana::Tracer.trace(:render, call_payload) { super(*args) }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Instrumentation
6
+ module ActiveRecord
7
+ IGNORED_NAMES = %w[SCHEMA EXPLAIN CACHE].freeze
8
+ IGNORED_SQL = %w[BEGIN COMMIT SET].freeze
9
+ SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i.freeze
10
+
11
+ def log(sql, name = 'SQL', binds = [], *args)
12
+ call_payload = {
13
+ activerecord: {
14
+ adapter: @config[:adapter],
15
+ host: @config[:host],
16
+ username: @config[:username],
17
+ db: @config[:database],
18
+ sql: maybe_sanitize(sql)
19
+ }
20
+ }
21
+
22
+ if binds.all? { |b| b.respond_to?(:value_before_type_cast) }
23
+ mapped = binds.map(&:value_before_type_cast)
24
+ call_payload[:activerecord][:binds] = mapped
25
+ end
26
+
27
+ maybe_trace(call_payload, name) { super(sql, name, binds, *args) }
28
+ end
29
+
30
+ private
31
+
32
+ def maybe_sanitize(sql)
33
+ ::Instana.config[:sanitize_sql] ? sql.gsub(SANITIZE_REGEXP, '?') : sql
34
+ end
35
+
36
+ def maybe_trace(call_payload, name, &blk)
37
+ if ::Instana.tracer.tracing? && !ignored?(call_payload, name)
38
+ ::Instana.tracer.trace(:activerecord, call_payload, &blk)
39
+ else
40
+ yield
41
+ end
42
+ end
43
+
44
+ def ignored?(call_payload, name)
45
+ IGNORED_NAMES.include?(name) ||
46
+ IGNORED_SQL.any? { |s| call_payload[:activerecord][:sql].upcase.start_with?(s) }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,15 +1,13 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2017
3
+
1
4
  module Instana
2
5
  module Instrumentation
3
6
  module Dalli
4
- def self.included(klass)
5
- ::Instana::Util.method_alias(klass, :perform)
6
- ::Instana::Util.method_alias(klass, :get_multi)
7
- end
8
-
9
- def perform_with_instana(*args, &blk)
7
+ def perform(*args, &blk)
10
8
  if !::Instana.tracer.tracing? || ::Instana.tracer.tracing_span?(:memcache)
11
9
  do_skip = true
12
- return perform_without_instana(*args, &blk)
10
+ return super(*args, &blk)
13
11
  end
14
12
 
15
13
  op, key, *_opts = args
@@ -22,7 +20,7 @@ module Instana
22
20
  ::Instana.tracer.log_entry(:memcache, entry_payload)
23
21
  exit_payload = { :memcache => {} }
24
22
 
25
- result = perform_without_instana(*args, &blk)
23
+ result = super(*args, &blk)
26
24
 
27
25
  if op == :get
28
26
  exit_payload[:memcache][:hit] = result ? 1 : 0
@@ -36,7 +34,7 @@ module Instana
36
34
  ::Instana.tracer.log_exit(:memcache, exit_payload) unless do_skip
37
35
  end
38
36
 
39
- def get_multi_with_instana(*keys)
37
+ def get_multi(*keys)
40
38
  entry_payload = { :memcache => {} }
41
39
  entry_payload[:memcache][:namespace] = @options[:namespace] if @options.key?(:namespace)
42
40
  entry_payload[:memcache][:command] = :get_multi
@@ -45,7 +43,7 @@ module Instana
45
43
  ::Instana.tracer.log_entry(:memcache, entry_payload)
46
44
  exit_payload = { :memcache => {} }
47
45
 
48
- result = get_multi_without_instana(*keys)
46
+ result = super(*keys)
49
47
 
50
48
  exit_payload[:memcache][:hits] = result.length
51
49
  result
@@ -63,20 +61,14 @@ module Instana
63
61
  ::Instana::Util.method_alias(klass, :request)
64
62
  end
65
63
 
66
- def request_with_instana(op, *args)
64
+ def request(op, *args)
67
65
  if ::Instana.tracer.tracing? || ::Instana.tracer.tracing_span?(:memcache)
68
66
  info_payload = { :memcache => {} }
69
67
  info_payload[:memcache][:server] = "#{@hostname}:#{@port}"
70
68
  ::Instana.tracer.log_info(info_payload)
71
69
  end
72
- request_without_instana(op, *args)
70
+ super(op, *args)
73
71
  end
74
72
  end
75
73
  end
76
74
  end
77
-
78
- if defined?(::Dalli) && ::Instana.config[:dalli][:enabled]
79
- ::Instana.logger.debug "Instrumenting Dalli"
80
- ::Dalli::Client.send(:include, ::Instana::Instrumentation::Dalli)
81
- ::Dalli::Server.send(:include, ::Instana::Instrumentation::DalliServer)
82
- end
@@ -1,74 +1,71 @@
1
- if defined?(::Excon) && ::Instana.config[:excon][:enabled]
2
- module Instana
3
- module Instrumentation
4
- class Excon < ::Excon::Middleware::Base
5
- def request_call(datum)
6
- return @stack.request_call(datum) unless ::Instana.tracer.tracing?
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2016
7
3
 
8
- payload = { :http => {} }
9
- path = datum[:path].split('?').first
10
- payload[:http][:url] = ::Instana.secrets.remove_from_query("#{datum[:connection].instance_variable_get(:@socket_key)}#{path}")
11
- payload[:http][:method] = datum[:method] if datum.key?(:method)
4
+ module Instana
5
+ module Instrumentation
6
+ class Excon < ::Excon::Middleware::Base
7
+ def request_call(datum)
8
+ return @stack.request_call(datum) unless ::Instana.tracer.tracing?
12
9
 
13
- if datum[:pipeline] == true
14
- # Pass the context along in the datum so we get back on response
15
- # and can close out the async span
16
- datum[:instana_span] = ::Instana.tracer.log_async_entry(:excon, payload)
17
- t_context = datum[:instana_span].context
18
- else
19
- ::Instana.tracer.log_entry(:excon, payload)
20
- t_context = ::Instana.tracer.context
21
- end
10
+ payload = { :http => {} }
11
+ path = datum[:path].split('?').first
12
+ payload[:http][:url] = ::Instana.secrets.remove_from_query("#{datum[:connection].instance_variable_get(:@socket_key)}#{path}")
13
+ payload[:http][:method] = datum[:method] if datum.key?(:method)
22
14
 
23
- # Set request headers; encode IDs as hexadecimal strings
24
- datum[:headers]['X-Instana-T'] = t_context.trace_id_header
25
- datum[:headers]['X-Instana-S'] = t_context.span_id_header
26
-
27
- @stack.request_call(datum)
15
+ if datum[:pipeline] == true
16
+ # Pass the context along in the datum so we get back on response
17
+ # and can close out the async span
18
+ datum[:instana_span] = ::Instana.tracer.log_async_entry(:excon, payload)
19
+ t_context = datum[:instana_span].context
20
+ else
21
+ ::Instana.tracer.log_entry(:excon, payload)
22
+ t_context = ::Instana.tracer.context
28
23
  end
29
24
 
30
- def error_call(datum)
31
- return @stack.error_call(datum) unless ::Instana.tracer.tracing?
25
+ # Set request headers; encode IDs as hexadecimal strings
26
+ datum[:headers]['X-Instana-T'] = t_context.trace_id_header
27
+ datum[:headers]['X-Instana-S'] = t_context.span_id_header
28
+
29
+ @stack.request_call(datum)
30
+ end
32
31
 
33
- if datum[:pipeline] == true
34
- ::Instana.tracer.log_async_error(datum[:error], datum[:instana_span])
35
- else
36
- ::Instana.tracer.log_error(datum[:error])
37
- end
38
- @stack.error_call(datum)
32
+ def error_call(datum)
33
+ return @stack.error_call(datum) unless ::Instana.tracer.tracing?
34
+
35
+ if datum[:pipeline] == true
36
+ ::Instana.tracer.log_async_error(datum[:error], datum[:instana_span])
37
+ else
38
+ ::Instana.tracer.log_error(datum[:error])
39
39
  end
40
+ @stack.error_call(datum)
41
+ end
40
42
 
41
- def response_call(datum)
42
- # FIXME: Will connect exceptions call a response?
43
- #
44
- return @stack.response_call(datum) unless ::Instana.tracer.tracing?
43
+ def response_call(datum)
44
+ # FIXME: Will connect exceptions call a response?
45
+ #
46
+ return @stack.response_call(datum) unless ::Instana.tracer.tracing?
45
47
 
46
- result = @stack.response_call(datum)
48
+ result = @stack.response_call(datum)
47
49
 
48
- status = datum[:status]
49
- if !status && datum.key?(:response) && datum[:response].is_a?(Hash)
50
- status = datum[:response][:status]
51
- end
50
+ status = datum[:status]
51
+ if !status && datum.key?(:response) && datum[:response].is_a?(Hash)
52
+ status = datum[:response][:status]
53
+ end
52
54
 
53
- if status.between?(500, 511)
54
- # Because of the 5xx response, we flag this span as errored but
55
- # without a backtrace (no exception)
56
- ::Instana.tracer.log_error(nil)
57
- end
55
+ if status.between?(500, 511)
56
+ # Because of the 5xx response, we flag this span as errored but
57
+ # without a backtrace (no exception)
58
+ ::Instana.tracer.log_error(nil)
59
+ end
58
60
 
59
- if datum[:pipeline] == true
60
- # Pickup context of this async span from datum[:instana_span]
61
- ::Instana.tracer.log_async_exit(:excon, { :http => {:status => status } }, datum[:instana_span])
62
- else
63
- ::Instana.tracer.log_exit(:excon, { :http => {:status => status } })
64
- end
65
- result
61
+ if datum[:pipeline] == true
62
+ # Pickup context of this async span from datum[:instana_span]
63
+ ::Instana.tracer.log_async_exit(:excon, { :http => {:status => status } }, datum[:instana_span])
64
+ else
65
+ ::Instana.tracer.log_exit(:excon, { :http => {:status => status } })
66
66
  end
67
+ result
67
68
  end
68
69
  end
69
70
  end
70
-
71
- ::Instana.logger.debug "Instrumenting Excon"
72
- ::Excon.defaults[:middlewares].unshift(::Instana::Instrumentation::Excon)
73
71
  end
74
-
@@ -1,5 +1,8 @@
1
- if defined?(GraphQL::Schema) && defined?(GraphQL::Tracing::PlatformTracing) && ::Instana.config[:graphql][:enabled]
2
- module Instana
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Instrumentation
3
6
  class GraphqlTracing < GraphQL::Tracing::PlatformTracing
4
7
  self.platform_keys = {
5
8
  'lex' => 'lex.graphql',
@@ -11,26 +14,26 @@ if defined?(GraphQL::Schema) && defined?(GraphQL::Tracing::PlatformTracing) && :
11
14
  'execute_query' => 'execute.graphql',
12
15
  'execute_query_lazy' => 'execute.graphql',
13
16
  }
14
-
15
- def platform_trace(platform_key, key, data)
16
- return yield unless key == 'execute_query'
17
+
18
+ def platform_trace(platform_key, key, data)
19
+ return yield unless key == 'execute_query'
17
20
  operation = data[:query].selected_operation
18
-
21
+
19
22
  arguments = []
20
23
  fields = []
21
-
24
+
22
25
  operation.selections.each do |field|
23
26
  arguments.concat(walk_fields(field, :arguments))
24
- fields.concat(walk_fields(field, :selections))
27
+ fields.concat(walk_fields(field, :selections))
25
28
  end
26
-
29
+
27
30
  payload = {
28
31
  operationName: data[:query].operation_name || 'anonymous',
29
32
  operationType: operation.operation_type,
30
33
  arguments: grouped_fields(arguments),
31
34
  fields: grouped_fields(fields),
32
35
  }
33
-
36
+
34
37
  begin
35
38
  ::Instana.tracer.log_entry(:'graphql.server')
36
39
  yield
@@ -41,11 +44,11 @@ if defined?(GraphQL::Schema) && defined?(GraphQL::Tracing::PlatformTracing) && :
41
44
  ::Instana.tracer.log_exit(:'graphql.server', {graphql: payload})
42
45
  end
43
46
  end
44
-
47
+
45
48
  def platform_field_key(type, field)
46
49
  "#{type.graphql_name}.#{field.graphql_name}"
47
50
  end
48
-
51
+
49
52
  def platform_authorized_key(type)
50
53
  "#{type.graphql_name}.authorized.graphql"
51
54
  end
@@ -53,17 +56,17 @@ if defined?(GraphQL::Schema) && defined?(GraphQL::Tracing::PlatformTracing) && :
53
56
  def platform_resolve_type_key(type)
54
57
  "#{type.graphql_name}.resolve_type.graphql"
55
58
  end
56
-
59
+
57
60
  private
58
-
61
+
59
62
  def walk_fields(parent, method)
60
63
  return [] unless parent.respond_to?(method)
61
-
64
+
62
65
  parent.send(method).map do |field|
63
66
  [{object: parent.name, field: field.name}] + walk_fields(field, method)
64
67
  end.flatten
65
68
  end
66
-
69
+
67
70
  def grouped_fields(fields)
68
71
  fields
69
72
  .group_by { |p| p[:object] }
@@ -72,6 +75,4 @@ if defined?(GraphQL::Schema) && defined?(GraphQL::Tracing::PlatformTracing) && :
72
75
  end
73
76
  end
74
77
  end
75
-
76
- ::GraphQL::Schema.use(::Instana::GraphqlTracing)
77
78
  end
@@ -1,84 +1,91 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2017
3
+
1
4
  call_types = [:request_response, :client_streamer, :server_streamer, :bidi_streamer]
2
5
 
3
- if defined?(GRPC::ActiveCall) && ::Instana.config[:grpc][:enabled]
4
- call_types.each do |call_type|
5
- GRPC::ClientStub.class_eval <<-RUBY, __FILE__, __LINE__ + 1
6
- def #{call_type}_with_instana(method, *others, **options)
7
- kvs = { rpc: {} }
6
+ module Instana
7
+ module Instrumentation
8
+ module GRPCCientInstrumentation
9
+ CALL_TYPES = [:request_response, :client_streamer, :server_streamer, :bidi_streamer]
8
10
 
9
- unless ::Instana.tracer.tracing?
10
- return #{call_type}_without_instana(method, *others, **options)
11
- end
11
+ CALL_TYPES.each do |call_type|
12
+ define_method(call_type) do |method, *others, **options|
13
+ begin
14
+ kvs = { rpc: {} }
12
15
 
13
- kvs[:rpc][:flavor] = :grpc
14
- kvs[:rpc][:host] = @host
15
- kvs[:rpc][:call] = method
16
- kvs[:rpc][:call_type] = :#{call_type}
16
+ unless ::Instana.tracer.tracing?
17
+ return super(method, *others, **options)
18
+ end
17
19
 
18
- ::Instana.tracer.log_entry(:'rpc-client', kvs)
20
+ kvs[:rpc][:flavor] = :grpc
21
+ kvs[:rpc][:host] = @host
22
+ kvs[:rpc][:call] = method
23
+ kvs[:rpc][:call_type] = call_type
19
24
 
20
- context = ::Instana.tracer.context
21
- if context
22
- options[:metadata] = (options[:metadata] || {}).merge(
23
- 'x-instana-t' => context.trace_id_header,
24
- 'x-instana-s' => context.span_id_header
25
- )
26
- end
25
+ ::Instana.tracer.log_entry(:'rpc-client', kvs)
27
26
 
28
- #{call_type}_without_instana(method, *others, **options)
29
- rescue => e
30
- kvs[:rpc][:error] = true
31
- ::Instana.tracer.log_info(kvs)
32
- ::Instana.tracer.log_error(e)
33
- raise
34
- ensure
35
- ::Instana.tracer.log_exit(:'rpc-client', {})
36
- end
27
+ context = ::Instana.tracer.context
28
+ if context
29
+ options[:metadata] = (options[:metadata] || {}).merge(
30
+ 'x-instana-t' => context.trace_id_header,
31
+ 'x-instana-s' => context.span_id_header
32
+ )
33
+ end
37
34
 
38
- alias #{call_type}_without_instana #{call_type}
39
- alias #{call_type} #{call_type}_with_instana
40
- RUBY
35
+ super(method, *others, **options)
36
+ rescue => e
37
+ kvs[:rpc][:error] = true
38
+ ::Instana.tracer.log_info(kvs)
39
+ ::Instana.tracer.log_error(e)
40
+ raise
41
+ ensure
42
+ ::Instana.tracer.log_exit(:'rpc-client', {})
43
+ end
44
+ end
45
+ end
46
+ end
41
47
  end
42
- ::Instana.logger.debug 'Instrumenting GRPC client'
43
48
  end
44
49
 
45
- if defined?(GRPC::RpcDesc) && ::Instana.config[:grpc][:enabled]
46
- call_types.each do |call_type|
47
- GRPC::RpcDesc.class_eval <<-RUBY, __FILE__, __LINE__ + 1
48
- def handle_#{call_type}_with_instana(active_call, mth, *others)
49
- kvs = { rpc: {} }
50
- metadata = active_call.metadata
50
+ module Instana
51
+ module Instrumentation
52
+ module GRPCServerInstrumentation
53
+ CALL_TYPES = [:request_response, :client_streamer, :server_streamer, :bidi_streamer]
51
54
 
52
- incoming_context = {}
53
- if metadata.key?('x-instana-t')
54
- incoming_context[:trace_id] = ::Instana::Util.header_to_id(metadata['x-instana-t'])
55
- incoming_context[:span_id] = ::Instana::Util.header_to_id(metadata['x-instana-s']) if metadata.key?('x-instana-s')
56
- incoming_context[:level] = metadata['x-instana-l'] if metadata.key?('x-instana-l')
57
- end
55
+ CALL_TYPES.each do |call_type|
56
+ define_method(:"handle_#{call_type}") do |active_call, mth, *others|
57
+ begin
58
+ kvs = { rpc: {} }
59
+ metadata = active_call.metadata
58
60
 
59
- kvs[:rpc][:flavor] = :grpc
60
- kvs[:rpc][:host] = Socket.gethostname
61
- kvs[:rpc][:call] = "/\#{mth.owner.service_name}/\#{name}"
62
- kvs[:rpc][:call_type] = :#{call_type}
63
- kvs[:rpc][:peer] = { address: active_call.peer }
61
+ incoming_context = {}
62
+ if metadata.key?('x-instana-t')
63
+ incoming_context[:trace_id] = ::Instana::Util.header_to_id(metadata['x-instana-t'])
64
+ incoming_context[:span_id] = ::Instana::Util.header_to_id(metadata['x-instana-s']) if metadata.key?('x-instana-s')
65
+ incoming_context[:level] = metadata['x-instana-l'] if metadata.key?('x-instana-l')
66
+ end
64
67
 
65
- ::Instana.tracer.log_start_or_continue(
66
- :'rpc-server', kvs, incoming_context
67
- )
68
+ kvs[:rpc][:flavor] = :grpc
69
+ kvs[:rpc][:host] = Socket.gethostname
70
+ kvs[:rpc][:call] = "/#{mth.owner.service_name}/#{name}"
71
+ kvs[:rpc][:call_type] = call_type
72
+ kvs[:rpc][:peer] = { address: active_call.peer }
68
73
 
69
- handle_#{call_type}_without_instana(active_call, mth, *others)
70
- rescue => e
71
- kvs[:rpc][:error] = true
72
- ::Instana.tracer.log_info(kvs)
73
- ::Instana.tracer.log_error(e)
74
- raise
75
- ensure
76
- ::Instana.tracer.log_end(:'rpc-server', {}) if ::Instana.tracer.tracing?
77
- end
74
+ ::Instana.tracer.log_start_or_continue(
75
+ :'rpc-server', kvs, incoming_context
76
+ )
78
77
 
79
- alias handle_#{call_type}_without_instana handle_#{call_type}
80
- alias handle_#{call_type} handle_#{call_type}_with_instana
81
- RUBY
78
+ super(active_call, mth, *others)
79
+ rescue => e
80
+ kvs[:rpc][:error] = true
81
+ ::Instana.tracer.log_info(kvs)
82
+ ::Instana.tracer.log_error(e)
83
+ raise
84
+ ensure
85
+ ::Instana.tracer.log_end(:'rpc-server', {}) if ::Instana.tracer.tracing?
86
+ end
87
+ end
88
+ end
89
+ end
82
90
  end
83
- ::Instana.logger.debug 'Instrumenting GRPC server'
84
91
  end