instana 1.192.1 → 1.193.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +200 -133
- data/.gitignore +3 -0
- data/.rubocop.yml +10 -1145
- data/.rubocop_todo.yml +1140 -0
- data/Appraisals +103 -0
- data/Gemfile +14 -32
- data/LICENSE +2 -1
- data/Rakefile +19 -39
- data/benchmarks/10k-rack-traces.rb +3 -0
- data/benchmarks/Gemfile +4 -0
- data/benchmarks/id_generation.rb +4 -0
- data/benchmarks/opentracing.rb +4 -0
- data/benchmarks/rack_vanilla_vs_traced.rb +3 -0
- data/benchmarks/stackprof_rack_tracing.rb +3 -0
- data/benchmarks/time_processing.rb +4 -0
- data/bin/console +8 -4
- data/examples/opentracing.rb +4 -0
- data/examples/tracing.rb +4 -0
- data/extras/license_header.rb +44 -0
- data/gemfiles/.bundle/config +1 -2
- data/gemfiles/cuba_30.gemfile +18 -0
- data/gemfiles/dalli_20.gemfile +18 -0
- data/gemfiles/excon_02.gemfile +18 -0
- data/gemfiles/graphql_10.gemfile +18 -0
- data/gemfiles/grpc_10.gemfile +18 -0
- data/gemfiles/net_http_01.gemfile +17 -0
- data/gemfiles/rack_16.gemfile +18 -0
- data/gemfiles/rack_20.gemfile +18 -0
- data/gemfiles/rails_42.gemfile +21 -0
- data/gemfiles/rails_50.gemfile +21 -0
- data/gemfiles/rails_52.gemfile +21 -0
- data/gemfiles/rails_60.gemfile +21 -0
- data/gemfiles/redis_40.gemfile +18 -0
- data/gemfiles/resque_122.gemfile +19 -0
- data/gemfiles/resque_20.gemfile +18 -0
- data/gemfiles/rest_client_16.gemfile +18 -0
- data/gemfiles/rest_client_20.gemfile +18 -0
- data/gemfiles/roda_20.gemfile +18 -0
- data/gemfiles/roda_30.gemfile +18 -0
- data/gemfiles/sidekiq_42.gemfile +18 -0
- data/gemfiles/sidekiq_50.gemfile +18 -0
- data/gemfiles/sinatra_14.gemfile +18 -0
- data/instana.gemspec +5 -7
- data/lib/instana.rb +3 -0
- data/lib/instana/activator.rb +44 -0
- data/lib/instana/activators/action_cable.rb +24 -0
- data/lib/instana/activators/action_controller_api.rb +21 -0
- data/lib/instana/activators/action_controller_base.rb +21 -0
- data/lib/instana/activators/action_view.rb +21 -0
- data/lib/instana/activators/active_record.rb +21 -0
- data/lib/instana/activators/cuba.rb +21 -0
- data/lib/instana/activators/dalli.rb +23 -0
- data/lib/instana/activators/excon.rb +20 -0
- data/lib/instana/activators/graphql.rb +22 -0
- data/lib/instana/activators/grpc_client.rb +20 -0
- data/lib/instana/activators/grpc_server.rb +20 -0
- data/lib/instana/activators/net_http.rb +20 -0
- data/lib/instana/activators/rack.rb +16 -0
- data/lib/instana/activators/rails.rb +18 -0
- data/lib/instana/activators/redis.rb +20 -0
- data/lib/instana/activators/resque_client.rb +21 -0
- data/lib/instana/activators/resque_worker.rb +33 -0
- data/lib/instana/activators/rest_client.rb +20 -0
- data/lib/instana/activators/roda.rb +21 -0
- data/lib/instana/activators/sidekiq_client.rb +24 -0
- data/lib/instana/activators/sidekiq_worker.rb +24 -0
- data/lib/instana/activators/sinatra.rb +21 -0
- data/lib/instana/agent.rb +3 -0
- data/lib/instana/agent/helpers.rb +3 -0
- data/lib/instana/agent/hooks.rb +3 -0
- data/lib/instana/agent/tasks.rb +3 -0
- data/lib/instana/base.rb +3 -0
- data/lib/instana/collector.rb +3 -0
- data/lib/instana/collectors/gc.rb +3 -0
- data/lib/instana/collectors/memory.rb +3 -0
- data/lib/instana/collectors/thread.rb +3 -0
- data/lib/instana/config.rb +3 -0
- data/lib/instana/frameworks/cuba.rb +9 -13
- data/lib/instana/frameworks/rails.rb +22 -32
- data/lib/instana/frameworks/roda.rb +10 -13
- data/lib/instana/frameworks/sinatra.rb +4 -8
- data/lib/instana/helpers.rb +3 -0
- data/lib/instana/instrumentation/action_cable.rb +53 -0
- data/lib/instana/instrumentation/action_controller.rb +84 -0
- data/lib/instana/instrumentation/action_view.rb +30 -0
- data/lib/instana/instrumentation/active_record.rb +50 -0
- data/lib/instana/instrumentation/dalli.rb +10 -18
- data/lib/instana/instrumentation/excon.rb +54 -57
- data/lib/instana/instrumentation/graphql.rb +19 -18
- data/lib/instana/instrumentation/grpc.rb +73 -66
- data/lib/instana/instrumentation/instrumented_request.rb +6 -1
- data/lib/instana/instrumentation/net-http.rb +46 -47
- data/lib/instana/instrumentation/rack.rb +4 -0
- data/lib/instana/instrumentation/redis.rb +13 -18
- data/lib/instana/instrumentation/resque.rb +17 -50
- data/lib/instana/instrumentation/rest-client.rb +5 -17
- data/lib/instana/instrumentation/sidekiq-client.rb +3 -9
- data/lib/instana/instrumentation/sidekiq-worker.rb +3 -9
- data/lib/instana/opentracing/carrier.rb +3 -0
- data/lib/instana/opentracing/tracer.rb +3 -0
- data/lib/instana/rack.rb +4 -0
- data/lib/instana/secrets.rb +10 -7
- data/lib/instana/setup.rb +6 -1
- data/lib/instana/thread_local.rb +3 -0
- data/lib/instana/tracer.rb +3 -0
- data/lib/instana/tracing/processor.rb +3 -0
- data/lib/instana/tracing/span.rb +3 -0
- data/lib/instana/tracing/span_context.rb +3 -0
- data/lib/instana/util.rb +4 -41
- data/lib/instana/version.rb +4 -1
- data/lib/oj_check.rb +3 -0
- data/lib/opentracing.rb +3 -0
- data/test/activator_test.rb +30 -0
- data/test/agent/agent_test.rb +3 -0
- data/test/benchmarks/bench_id_generation.rb +3 -0
- data/test/benchmarks/bench_opentracing.rb +3 -0
- data/test/config_test.rb +3 -0
- data/test/frameworks/cuba_test.rb +41 -40
- data/test/frameworks/roda_test.rb +43 -41
- data/test/frameworks/sinatra_test.rb +64 -64
- data/test/instana_test.rb +3 -0
- data/test/instrumentation/dalli_test.rb +3 -0
- data/test/instrumentation/excon_test.rb +4 -0
- data/test/instrumentation/graphql_test.rb +3 -0
- data/test/instrumentation/grpc_test.rb +5 -1
- data/test/instrumentation/{net-http_test.rb → net_http_test.rb} +4 -0
- data/test/instrumentation/{instrumented_request_test.rb → rack_instrumented_request_test.rb} +4 -1
- data/test/{frameworks → instrumentation}/rack_test.rb +3 -1
- data/test/instrumentation/rails_action_cable_test.rb +131 -0
- data/test/{frameworks/rails/actioncontroller_test.rb → instrumentation/rails_action_controller_test.rb} +40 -21
- data/test/instrumentation/rails_action_view_test.rb +151 -0
- data/test/instrumentation/rails_active_record_test.rb +122 -0
- data/test/instrumentation/redis_test.rb +3 -0
- data/test/instrumentation/resque_test.rb +6 -11
- data/test/instrumentation/{rest-client_test.rb → rest_client_test.rb} +9 -0
- data/test/instrumentation/sidekiq-client_test.rb +4 -0
- data/test/instrumentation/sidekiq-worker_test.rb +4 -0
- data/test/secrets_test.rb +3 -0
- data/test/support/apps/active_record/active_record.rb +24 -0
- data/test/{servers/grpc_50051.rb → support/apps/grpc/boot.rb} +4 -1
- data/test/{apps → support/apps/grpc}/grpc_server.rb +3 -0
- data/test/{servers/rackapp_6511.rb → support/apps/http_endpoint/boot.rb} +3 -0
- data/test/{servers/rails_3205.rb → support/apps/rails/boot.rb} +10 -13
- data/test/{models → support/apps/rails/models}/block.rb +4 -1
- data/test/{models → support/apps/rails/models}/block6.rb +3 -0
- data/test/support/apps/resque/boot.rb +5 -0
- data/test/{jobs → support/apps/resque/jobs}/resque_error_job.rb +3 -0
- data/test/{jobs → support/apps/resque/jobs}/resque_fast_job.rb +3 -0
- data/test/support/apps/sidekiq/boot.rb +25 -0
- data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_1.rb +3 -0
- data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_2.rb +3 -0
- data/test/{servers → support/apps}/sidekiq/worker.rb +5 -2
- data/test/support/helpers.rb +97 -0
- data/test/test_helper.rb +27 -144
- data/test/tracing/custom_test.rb +3 -0
- data/test/tracing/id_management_test.rb +4 -0
- data/test/tracing/opentracing_test.rb +3 -0
- data/test/tracing/tracer_async_test.rb +3 -0
- data/test/tracing/tracer_test.rb +3 -0
- metadata +105 -96
- data/gemfiles/libraries.gemfile +0 -73
- data/gemfiles/rails32.gemfile +0 -51
- data/gemfiles/rails42.gemfile +0 -50
- data/gemfiles/rails50.gemfile +0 -52
- data/gemfiles/rails52.gemfile +0 -52
- data/gemfiles/rails60.gemfile +0 -72
- data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +0 -58
- data/lib/instana/frameworks/instrumentation/action_controller.rb +0 -194
- data/lib/instana/frameworks/instrumentation/action_view.rb +0 -43
- data/lib/instana/frameworks/instrumentation/active_record.rb +0 -27
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +0 -87
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +0 -62
- data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +0 -103
- data/lib/instana/instrumentation.rb +0 -25
- data/lib/instana/test.rb +0 -43
- data/test/apps/cuba.rb +0 -19
- data/test/apps/roda.rb +0 -13
- data/test/apps/sinatra.rb +0 -9
- data/test/frameworks/rails/actionview3_test.rb +0 -210
- data/test/frameworks/rails/actionview4_test.rb +0 -208
- data/test/frameworks/rails/actionview5_test.rb +0 -221
- data/test/frameworks/rails/activerecord_test.rb +0 -279
- 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
|
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
|
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 =
|
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
|
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 =
|
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
|
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
|
-
|
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
|
-
|
2
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
24
|
-
datum
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
48
|
+
result = @stack.response_call(datum)
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
2
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
11
|
+
CALL_TYPES.each do |call_type|
|
12
|
+
define_method(call_type) do |method, *others, **options|
|
13
|
+
begin
|
14
|
+
kvs = { rpc: {} }
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
kvs[:rpc][:call_type] = :#{call_type}
|
16
|
+
unless ::Instana.tracer.tracing?
|
17
|
+
return super(method, *others, **options)
|
18
|
+
end
|
17
19
|
|
18
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
66
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
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
|