tingyun_rpm 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/ting_yun/agent/agent.rb +8 -0
- data/lib/ting_yun/agent/collector/stats_engine/base_quantile_hash.rb +20 -0
- data/lib/ting_yun/agent/collector/stats_engine/metric_stats.rb +10 -0
- data/lib/ting_yun/agent/collector/stats_engine.rb +9 -0
- data/lib/ting_yun/agent/collector/transaction_sampler/class_method.rb +2 -2
- data/lib/ting_yun/agent/cross_app/cross_app_tracing.rb +16 -10
- data/lib/ting_yun/agent/datastore/metric_helper.rb +31 -7
- data/lib/ting_yun/agent/datastore.rb +6 -11
- data/lib/ting_yun/agent/dispatcher.rb +5 -1
- data/lib/ting_yun/agent/instance_methods/container_data_manager.rb +5 -1
- data/lib/ting_yun/agent/instance_methods/start_worker_thread.rb +5 -0
- data/lib/ting_yun/agent/method_tracer_helpers.rb +8 -4
- data/lib/ting_yun/agent/transaction/attributes.rb +6 -2
- data/lib/ting_yun/agent/transaction/class_method.rb +14 -5
- data/lib/ting_yun/agent/transaction/instance_method.rb +20 -4
- data/lib/ting_yun/agent/transaction/trace.rb +2 -1
- data/lib/ting_yun/agent/transaction/trace_node.rb +10 -2
- data/lib/ting_yun/agent/transaction/traced_method_stack.rb +2 -2
- data/lib/ting_yun/agent/transaction/transaction_sample_builder.rb +2 -1
- data/lib/ting_yun/agent/transaction/transaction_state.rb +22 -1
- data/lib/ting_yun/agent/transaction/transaction_timings.rb +1 -2
- data/lib/ting_yun/agent/transaction.rb +13 -7
- data/lib/ting_yun/configuration/default_source.rb +44 -7
- data/lib/ting_yun/configuration/yaml_source.rb +1 -0
- data/lib/ting_yun/frameworks/instrumentation.rb +6 -1
- data/lib/ting_yun/frameworks/rails5.rb +10 -0
- data/lib/ting_yun/frameworks.rb +1 -1
- data/lib/ting_yun/http/http_client_request.rb +39 -0
- data/lib/ting_yun/http/net_http_request.rb +4 -0
- data/lib/ting_yun/instrumentation/active_record.rb +11 -5
- data/lib/ting_yun/instrumentation/bunny.rb +142 -0
- data/lib/ting_yun/instrumentation/data_mapper.rb +167 -0
- data/lib/ting_yun/instrumentation/grape.rb +39 -0
- data/lib/ting_yun/instrumentation/http_client.rb +70 -0
- data/lib/ting_yun/instrumentation/kafka.rb +218 -0
- data/lib/ting_yun/instrumentation/memcached.rb +135 -0
- data/lib/ting_yun/instrumentation/middleware_proxy.rb +1 -4
- data/lib/ting_yun/instrumentation/middleware_tracing.rb +5 -1
- data/lib/ting_yun/instrumentation/mongo.rb +18 -6
- data/lib/ting_yun/instrumentation/mongo2.rb +5 -1
- data/lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb +5 -5
- data/lib/ting_yun/instrumentation/moped.rb +4 -3
- data/lib/ting_yun/instrumentation/net.rb +3 -3
- data/lib/ting_yun/instrumentation/rails3/action_controller.rb +8 -4
- data/lib/ting_yun/instrumentation/rails3/action_view.rb +8 -4
- data/lib/ting_yun/instrumentation/rails4/action_controller.rb +29 -0
- data/lib/ting_yun/instrumentation/rails4/action_view.rb +29 -0
- data/lib/ting_yun/instrumentation/rails4/active_record.rb +30 -0
- data/lib/ting_yun/instrumentation/rails5/action_cable.rb +31 -0
- data/lib/ting_yun/instrumentation/rails5/action_controller.rb +29 -0
- data/lib/ting_yun/instrumentation/rails5/action_view.rb +28 -0
- data/lib/ting_yun/instrumentation/rails5/active_record.rb +30 -0
- data/lib/ting_yun/instrumentation/rake.rb +3 -2
- data/lib/ting_yun/instrumentation/redis.rb +6 -5
- data/lib/ting_yun/instrumentation/sidekiq.rb +61 -0
- data/lib/ting_yun/instrumentation/sinatra/action.rb +95 -0
- data/lib/ting_yun/instrumentation/sinatra/view.rb +67 -0
- data/lib/ting_yun/instrumentation/support/action_cable_subscriber.rb +83 -0
- data/lib/ting_yun/instrumentation/{rails4 → support}/action_controller_subscriber.rb +5 -29
- data/lib/ting_yun/instrumentation/{rails4 → support}/action_view_subscriber.rb +2 -24
- data/lib/ting_yun/instrumentation/support/active_record_helper.rb +23 -6
- data/lib/ting_yun/instrumentation/{rails4 → support}/active_record_subscriber.rb +13 -37
- data/lib/ting_yun/instrumentation/support/controller_instrumentation.rb +204 -1
- data/lib/ting_yun/instrumentation/support/database.rb +2 -1
- data/lib/ting_yun/instrumentation/support/external_error.rb +2 -2
- data/lib/ting_yun/instrumentation/support/external_helper.rb +30 -0
- data/lib/ting_yun/instrumentation/support/method_instrumentation.rb +228 -0
- data/lib/ting_yun/instrumentation/support/metric_translator.rb +4 -1
- data/lib/ting_yun/instrumentation/support/sinatra_helper.rb +20 -0
- data/lib/ting_yun/instrumentation/support/transaction_namer.rb +3 -1
- data/lib/ting_yun/instrumentation/thrift.rb +5 -6
- data/lib/ting_yun/logger/agent_logger.rb +1 -0
- data/lib/ting_yun/logger/create_logger_helper.rb +16 -2
- data/lib/ting_yun/metrics/metric_data.rb +8 -2
- data/lib/ting_yun/metrics/metric_spec.rb +2 -1
- data/lib/ting_yun/support/helper.rb +4 -0
- data/lib/ting_yun/support/quantile_p2.rb +204 -0
- data/lib/ting_yun/ting_yun_service/upload_service.rb +38 -12
- data/lib/ting_yun/ting_yun_service.rb +4 -7
- data/lib/ting_yun/version.rb +3 -1
- data/lib/tingyun_rpm.rb +0 -4
- data/tingyun_rpm.gemspec +3 -3
- metadata +35 -13
- data/CODE_OF_CONDUCT.md +0 -13
- data/lib/ting_yun/agent/method_tracer.rb +0 -256
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'ting_yun/agent'
|
4
|
-
require 'ting_yun/agent/
|
4
|
+
require 'ting_yun/agent/method_tracer_helpers'
|
5
5
|
|
6
6
|
module TingYun
|
7
7
|
module Instrumentation
|
@@ -39,6 +39,10 @@ TingYun::Support::LibraryDetection.defer do
|
|
39
39
|
|
40
40
|
# We can't be sure that this will work with future versions of Rails 3.
|
41
41
|
# Currently enabled for Rails 3.1 and 3.2
|
42
|
+
depends_on do
|
43
|
+
!::TingYun::Agent.config[:disable_action_view]
|
44
|
+
end
|
45
|
+
|
42
46
|
depends_on do
|
43
47
|
defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3 && ([1,2].member?(::Rails::VERSION::MINOR.to_i))
|
44
48
|
end
|
@@ -56,7 +60,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
56
60
|
@details = extract_details(options) if respond_to? :extract_details, true
|
57
61
|
identifier = determine_template(options) ? determine_template(options).identifier : nil
|
58
62
|
scope_name = "View/#{TingYun::Instrumentation::Rails3::ActionView.template_metric(identifier, options)}/Rendering"
|
59
|
-
TingYun::Agent::
|
63
|
+
TingYun::Agent::MethodTracerHelpers.trace_execution_scoped scope_name do
|
60
64
|
render_without_tingyun(context, options)
|
61
65
|
end
|
62
66
|
end
|
@@ -70,7 +74,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
70
74
|
def instrument_with_tingyun(name, payload = {}, &block)
|
71
75
|
identifier = payload[:identifier]
|
72
76
|
scope_name = "View/#{TingYun::Instrumentation::Rails3::ActionView.template_metric(identifier)}/Partial"
|
73
|
-
TingYun::Agent::
|
77
|
+
TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(scope_name) do
|
74
78
|
instrument_without_tingyun(name, payload, &block)
|
75
79
|
end
|
76
80
|
end
|
@@ -102,7 +106,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
102
106
|
{}
|
103
107
|
end
|
104
108
|
str = "View/#{TingYun::Instrumentation::Rails3::ActionView.template_metric(@identifier, options)}/#{TingYun::Agent::Instrumentation::Rails3::ActionView.render_type(@identifier)}"
|
105
|
-
TingYun::Agent::
|
109
|
+
TingYun::Agent::MethodTracerHelpers.trace_execution_scoped str do
|
106
110
|
render_without_tingyun(*args, &block)
|
107
111
|
end
|
108
112
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ting_yun/instrumentation/support/action_controller_subscriber'
|
3
|
+
|
4
|
+
TingYun::Support::LibraryDetection.defer do
|
5
|
+
@name = :rails4_controller
|
6
|
+
|
7
|
+
depends_on do
|
8
|
+
!::TingYun::Agent.config[:disable_action_controller]
|
9
|
+
end
|
10
|
+
|
11
|
+
depends_on do
|
12
|
+
defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 4
|
13
|
+
end
|
14
|
+
|
15
|
+
depends_on do
|
16
|
+
defined?(ActionController) && defined?(ActionController::Base)
|
17
|
+
end
|
18
|
+
|
19
|
+
executes do
|
20
|
+
::TingYun::Agent.logger.info 'Installing Rails 4 Controller instrumentation'
|
21
|
+
end
|
22
|
+
|
23
|
+
executes do
|
24
|
+
::TingYun::Instrumentation::Rails::ActionControllerSubscriber \
|
25
|
+
.subscribe(/^process_action.action_controller$/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/instrumentation/support/action_view_subscriber'
|
4
|
+
|
5
|
+
TingYun::Support::LibraryDetection.defer do
|
6
|
+
@name = :rails4_view
|
7
|
+
|
8
|
+
depends_on do
|
9
|
+
!::TingYun::Agent.config[:disable_action_view]
|
10
|
+
end
|
11
|
+
|
12
|
+
depends_on do
|
13
|
+
defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 4
|
14
|
+
end
|
15
|
+
|
16
|
+
depends_on do
|
17
|
+
!TingYun::Agent.config[:disable_view_instrumentation] &&
|
18
|
+
!TingYun::Instrumentation::Rails::ActionViewSubscriber.subscribed?
|
19
|
+
end
|
20
|
+
|
21
|
+
executes do
|
22
|
+
TingYun::Agent.logger.info 'Installing Rails 4 view instrumentation'
|
23
|
+
end
|
24
|
+
|
25
|
+
executes do
|
26
|
+
TingYun::Instrumentation::Rails::ActionViewSubscriber.subscribe(/render_.+\.action_view$/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
#
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ting_yun/instrumentation/support/active_record_subscriber'
|
3
|
+
|
4
|
+
TingYun::Support::LibraryDetection.defer do
|
5
|
+
named :active_record_4
|
6
|
+
|
7
|
+
depends_on do
|
8
|
+
!::TingYun::Agent.config[:disable_active_record]
|
9
|
+
end
|
10
|
+
|
11
|
+
depends_on do
|
12
|
+
defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
|
13
|
+
defined?(::ActiveRecord::VERSION) &&
|
14
|
+
::ActiveRecord::VERSION::MAJOR.to_i >= 4
|
15
|
+
end
|
16
|
+
|
17
|
+
depends_on do
|
18
|
+
!TingYun::Instrumentation::Rails::ActiveRecordSubscriber.subscribed?
|
19
|
+
end
|
20
|
+
|
21
|
+
executes do
|
22
|
+
::TingYun::Agent.logger.info 'Installing ActiveRecord 4 instrumentation'
|
23
|
+
end
|
24
|
+
|
25
|
+
executes do
|
26
|
+
ActiveSupport::Notifications.subscribe('sql.active_record',
|
27
|
+
TingYun::Instrumentation::Rails::ActiveRecordSubscriber.new)
|
28
|
+
::TingYun::Instrumentation::Support::ActiveRecordHelper.instrument_additional_methods
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/instrumentation/support/action_cable_subscriber'
|
4
|
+
|
5
|
+
TingYun::Support::LibraryDetection.defer do
|
6
|
+
named :rails5_action_cable
|
7
|
+
|
8
|
+
depends_on do
|
9
|
+
!::TingYun::Agent.config[:disable_action_cable]
|
10
|
+
end
|
11
|
+
|
12
|
+
depends_on do
|
13
|
+
defined?(::Rails) &&
|
14
|
+
::Rails::VERSION::MAJOR.to_i == 5 &&
|
15
|
+
defined?(::ActionCable)
|
16
|
+
end
|
17
|
+
|
18
|
+
depends_on do
|
19
|
+
!TingYun::Agent.config[:disable_action_cable_instrumentation]
|
20
|
+
end
|
21
|
+
|
22
|
+
executes do
|
23
|
+
::TingYun::Agent.logger.info 'Installing Rails 5 Action Cable instrumentation'
|
24
|
+
end
|
25
|
+
|
26
|
+
executes do
|
27
|
+
# enumerate the specific events we want so that we do not get unexpected additions in the future
|
28
|
+
ActiveSupport::Notifications.subscribe(/(perform_action|transmit)\.action_cable/,
|
29
|
+
TingYun::Instrumentation::Rails::ActionCableSubscriber.new)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/instrumentation/support/action_controller_subscriber'
|
4
|
+
|
5
|
+
|
6
|
+
TingYun::Support::LibraryDetection.defer do
|
7
|
+
named :rails5_controller
|
8
|
+
|
9
|
+
depends_on do
|
10
|
+
!::TingYun::Agent.config[:disable_action_controller]
|
11
|
+
end
|
12
|
+
|
13
|
+
depends_on do
|
14
|
+
defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 5
|
15
|
+
end
|
16
|
+
|
17
|
+
depends_on do
|
18
|
+
defined?(ActionController) && defined?(ActionController::Base)
|
19
|
+
end
|
20
|
+
|
21
|
+
executes do
|
22
|
+
::TingYun::Agent.logger.info 'Installing Rails 5 Controller instrumentation'
|
23
|
+
end
|
24
|
+
|
25
|
+
executes do
|
26
|
+
::TingYun::Instrumentation::Rails::ActionControllerSubscriber \
|
27
|
+
.subscribe(/^process_action.action_controller$/)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/instrumentation/support/action_view_subscriber'
|
4
|
+
|
5
|
+
TingYun::Support::LibraryDetection.defer do
|
6
|
+
named :rails5_view
|
7
|
+
|
8
|
+
depends_on do
|
9
|
+
!::TingYun::Agent.config[:disable_action_view]
|
10
|
+
end
|
11
|
+
|
12
|
+
depends_on do
|
13
|
+
defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 5
|
14
|
+
end
|
15
|
+
|
16
|
+
depends_on do
|
17
|
+
!TingYun::Agent.config[:disable_view_instrumentation] &&
|
18
|
+
!TingYun::Instrumentation::Rails::ActionViewSubscriber.subscribed?
|
19
|
+
end
|
20
|
+
|
21
|
+
executes do
|
22
|
+
::TingYun::Agent.logger.info 'Installing Rails 5 view instrumentation'
|
23
|
+
end
|
24
|
+
|
25
|
+
executes do
|
26
|
+
TingYun::Instrumentation::Rails::ActionViewSubscriber.subscribe(/render_.+\.action_view$/)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ting_yun/instrumentation/support/active_record_subscriber'
|
3
|
+
|
4
|
+
TingYun::Support::LibraryDetection.defer do
|
5
|
+
named :active_record_5
|
6
|
+
|
7
|
+
depends_on do
|
8
|
+
!::TingYun::Agent.config[:disable_active_record]
|
9
|
+
end
|
10
|
+
|
11
|
+
depends_on do
|
12
|
+
defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
|
13
|
+
defined?(::ActiveRecord::VERSION) &&
|
14
|
+
::ActiveRecord::VERSION::MAJOR.to_i == 5
|
15
|
+
end
|
16
|
+
|
17
|
+
depends_on do
|
18
|
+
!TingYun::Instrumentation::Rails::ActiveRecordSubscriber.subscribed?
|
19
|
+
end
|
20
|
+
|
21
|
+
executes do
|
22
|
+
::TingYun::Agent.logger.info 'Installing ActiveRecord 5 instrumentation'
|
23
|
+
end
|
24
|
+
|
25
|
+
executes do
|
26
|
+
ActiveSupport::Notifications.subscribe('sql.active_record',
|
27
|
+
TingYun::Instrumentation::Rails::ActiveRecordSubscriber.new)
|
28
|
+
::TingYun::Instrumentation::Support::ActiveRecordHelper.instrument_additional_methods
|
29
|
+
end
|
30
|
+
end
|
@@ -13,6 +13,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
13
13
|
|
14
14
|
executes do
|
15
15
|
::TingYun::Agent.logger.info 'Installing deferred Rake instrumentation'
|
16
|
+
require 'ting_yun/agent/method_tracer_helpers'
|
16
17
|
end
|
17
18
|
|
18
19
|
executes do
|
@@ -87,7 +88,7 @@ module TingYun
|
|
87
88
|
task.instance_variable_set(:@__tingyun_instrumented_execute, true)
|
88
89
|
task.instance_eval do
|
89
90
|
def execute(*args, &block)
|
90
|
-
TingYun::Agent::
|
91
|
+
TingYun::Agent::MethodTracerHelpers.trace_execution_scoped("Rake/execute/#{self.name}") do
|
91
92
|
super
|
92
93
|
end
|
93
94
|
end
|
@@ -99,7 +100,7 @@ module TingYun
|
|
99
100
|
def self.instrument_invoke_prerequisites_concurrently(task)
|
100
101
|
task.instance_eval do
|
101
102
|
def invoke_prerequisites_concurrently(*_)
|
102
|
-
TingYun::Agent::
|
103
|
+
TingYun::Agent::MethodTracerHelpers.trace_execution_scoped("Rake/execute/multitask") do
|
103
104
|
super
|
104
105
|
end
|
105
106
|
end
|
@@ -6,7 +6,8 @@ TingYun::Support::LibraryDetection.defer do
|
|
6
6
|
named :redis
|
7
7
|
|
8
8
|
depends_on do
|
9
|
-
defined?(::Redis)
|
9
|
+
defined?(::Redis) &&
|
10
|
+
!::TingYun::Agent.config[:disable_redis]
|
10
11
|
end
|
11
12
|
|
12
13
|
|
@@ -20,7 +21,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
20
21
|
|
21
22
|
::Redis::Client.class_eval do
|
22
23
|
|
23
|
-
def record_redis_duration(
|
24
|
+
def record_redis_duration(duration)
|
24
25
|
state = TingYun::Agent::TransactionState.tl_get
|
25
26
|
if state
|
26
27
|
state.timings.rds_duration = state.timings.rds_duration + duration * 1000
|
@@ -32,7 +33,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
32
33
|
def call_with_tingyun_trace(*args, &blk)
|
33
34
|
operation = args[0].is_a?(Array) ? args[0][0] : args[0]
|
34
35
|
|
35
|
-
TingYun::Agent::Datastore.wrap("Redis", operation, nil, method(:record_redis_duration)) do
|
36
|
+
TingYun::Agent::Datastore.wrap("Redis", operation, db, host, port, nil, method(:record_redis_duration)) do
|
36
37
|
call_without_tingyun_trace(*args, &blk)
|
37
38
|
end
|
38
39
|
end
|
@@ -46,7 +47,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
46
47
|
pipeline = args[0]
|
47
48
|
operation = pipeline.is_a?(::Redis::Pipeline::Multi) ? 'multi' : 'pipeline'
|
48
49
|
|
49
|
-
TingYun::Agent::Datastore.wrap("Redis", operation, nil, method(:record_redis_duration)) do
|
50
|
+
TingYun::Agent::Datastore.wrap("Redis", operation, db, host, port, nil, method(:record_redis_duration)) do
|
50
51
|
call_pipelined_without_tingyun_trace(*args, &block)
|
51
52
|
end
|
52
53
|
end
|
@@ -60,7 +61,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
60
61
|
alias_method :connect_without_tingyun, :connect
|
61
62
|
|
62
63
|
def connect(*args, &block)
|
63
|
-
TingYun::Agent::Datastore.wrap("Redis", "connect", nil, method(:record_redis_duration)) do
|
64
|
+
TingYun::Agent::Datastore.wrap("Redis", "connect", db, host, port, nil, method(:record_redis_duration)) do
|
64
65
|
connect_without_tingyun(*args, &block)
|
65
66
|
end
|
66
67
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
TingYun::Support::LibraryDetection.defer do
|
6
|
+
named :sidekiq
|
7
|
+
|
8
|
+
depends_on do
|
9
|
+
defined?(::Sidekiq) && !TingYun::Agent.config[:disable_sidekiq]
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
executes do
|
14
|
+
TingYun::Agent.logger.info 'Installing Sidekiq Instrumentation'
|
15
|
+
require 'ting_yun/instrumentation/support/controller_instrumentation'
|
16
|
+
end
|
17
|
+
|
18
|
+
executes do
|
19
|
+
class TingYun::SidekiqInstrumentation
|
20
|
+
include TingYun::Instrumentation::Support::ControllerInstrumentation
|
21
|
+
def call(worker_instance, msg, queue, *_)
|
22
|
+
trace_args = if worker_instance.respond_to?(:tingyun_trace_args)
|
23
|
+
worker_instance.tingyun_trace_args(msg, queue)
|
24
|
+
else
|
25
|
+
self.class.default_trace_args(msg)
|
26
|
+
end
|
27
|
+
perform_action_with_tingyun_trace(trace_args) do
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.default_trace_args(msg)
|
33
|
+
{
|
34
|
+
:name => 'perform',
|
35
|
+
:class_name => msg['class'],
|
36
|
+
:category => 'BackgroundAction/Sidekiq'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Sidekiq::Extensions::DelayedClass
|
42
|
+
def tingyun_trace_args(msg, queue)
|
43
|
+
(target, method_name, _args) = YAML.load(msg['args'][0])
|
44
|
+
{
|
45
|
+
:name => method_name,
|
46
|
+
:class_name => target.name,
|
47
|
+
:category => 'BackgroundAction/Sidekiq'
|
48
|
+
}
|
49
|
+
rescue => e
|
50
|
+
TingYun::Agent.logger.error("Failure during deserializing YAML for Sidekiq::Extensions::DelayedClass", e)
|
51
|
+
TingYun::SidekiqInstrumentation.default_trace_args(msg)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Sidekiq.configure_server do |config|
|
56
|
+
config.server_middleware do |chain|
|
57
|
+
chain.add TingYun::SidekiqInstrumentation
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/instrumentation/support/split_controller'
|
4
|
+
require 'ting_yun/instrumentation/support/sinatra_helper'
|
5
|
+
module TingYun
|
6
|
+
module Instrumentation
|
7
|
+
module Sinatra
|
8
|
+
module Action
|
9
|
+
|
10
|
+
include TingYun::Instrumentation::Support::SplitController
|
11
|
+
|
12
|
+
def tingyun_metric_path(current_class, path)
|
13
|
+
if find_rule(request.request_method.upcase, path, request.env, request.params)
|
14
|
+
return "Sinatra/#{current_class}/#{namespace}/#{name(path.slice(1..-1), request.env, request.params, request.cookies)}"
|
15
|
+
else
|
16
|
+
return self.env["PATH_INFO"] unless TingYun::Agent.config[:'nbs.auto_action_naming']
|
17
|
+
"Sinatra/#{current_class}/#{path}(#{request.request_method.upcase})".squeeze("/")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
TingYun::Support::LibraryDetection.defer do
|
27
|
+
@name = :sinatra_action
|
28
|
+
|
29
|
+
depends_on do
|
30
|
+
!::TingYun::Agent.config[:disable_action_controller]
|
31
|
+
end
|
32
|
+
|
33
|
+
depends_on do
|
34
|
+
defined?(::Sinatra) && defined?(::Sinatra::Base) && TingYun::Instrumentation::Support::SinatraHelper.version_supported?
|
35
|
+
end
|
36
|
+
|
37
|
+
executes do
|
38
|
+
::TingYun::Agent.logger.info 'Installing Sinatra action instrumentation'
|
39
|
+
end
|
40
|
+
|
41
|
+
executes do
|
42
|
+
::Sinatra::Base.class_eval do
|
43
|
+
|
44
|
+
class << self
|
45
|
+
private
|
46
|
+
alias :route_without_origin_path :route
|
47
|
+
|
48
|
+
def route(verb, path, options = {}, &block)
|
49
|
+
res = route_without_origin_path(verb, path, options = {}, &block)
|
50
|
+
@routes[verb].last << path
|
51
|
+
res
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
private
|
57
|
+
alias :route_eval_without_tingyun_trace :route_eval
|
58
|
+
|
59
|
+
def ty_get_path(base)
|
60
|
+
if routes = base.routes[@request.request_method]
|
61
|
+
routes.each do |pattern, keys, conditions, block, origin_path|
|
62
|
+
route = @request.path_info
|
63
|
+
route = '/' if route.empty? and not settings.empty_path_info?
|
64
|
+
next unless pattern.match(route)
|
65
|
+
return (origin_path.respond_to?(:source) ? origin_path.source : origin_path)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
ty_get_path(base.superclass) if base.superclass.respond_to?(:routes)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def route_eval(*args, &block)
|
73
|
+
|
74
|
+
self.class.class_eval do
|
75
|
+
require 'ting_yun/instrumentation/support/parameter_filtering'
|
76
|
+
require 'ting_yun/instrumentation/support/controller_instrumentation'
|
77
|
+
include TingYun::Instrumentation::Sinatra::Action
|
78
|
+
end
|
79
|
+
|
80
|
+
params = TingYun::Instrumentation::Support::ParameterFiltering.flattened_filter_request_parameters(@params)
|
81
|
+
|
82
|
+
TingYun::Instrumentation::Support::ControllerInstrumentation.perform_action_with_tingyun_trace(
|
83
|
+
:category => :sinatra,
|
84
|
+
:name => @request.path_info,
|
85
|
+
:path => tingyun_metric_path(self.class.name, ty_get_path(self.class)),
|
86
|
+
:params => params,
|
87
|
+
:class_name => self.class.name,
|
88
|
+
:request => @request
|
89
|
+
) do
|
90
|
+
route_eval_without_tingyun_trace(*args, &block)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/agent/method_tracer_helpers'
|
4
|
+
require 'ting_yun/instrumentation/support/sinatra_helper'
|
5
|
+
|
6
|
+
TingYun::Support::LibraryDetection.defer do
|
7
|
+
@name = :sinatra_view
|
8
|
+
|
9
|
+
depends_on do
|
10
|
+
!::TingYun::Agent.config[:disable_action_view]
|
11
|
+
end
|
12
|
+
|
13
|
+
depends_on do
|
14
|
+
defined?(::Sinatra) && defined?(::Sinatra::Templates) && TingYun::Instrumentation::Support::SinatraHelper.version_supported?
|
15
|
+
end
|
16
|
+
|
17
|
+
executes do
|
18
|
+
::TingYun::Agent.logger.info 'Installing Sinatra view instrumentation'
|
19
|
+
end
|
20
|
+
|
21
|
+
executes do
|
22
|
+
::Sinatra::Templates.class_eval do
|
23
|
+
|
24
|
+
def tingyun_template_metric(*args, &block)
|
25
|
+
engine, data, options = args[0..2]
|
26
|
+
eat_errors = options[:eat_errors]
|
27
|
+
views = options[:views] || settings.views || "./views"
|
28
|
+
if data.is_a?(Symbol)
|
29
|
+
body, path, line = settings.templates[data]
|
30
|
+
unless body.respond_to?(:call)
|
31
|
+
template = Tilt[engine]
|
32
|
+
found = false
|
33
|
+
@preferred_extension = engine.to_s
|
34
|
+
find_template(views, data, template) do |file|
|
35
|
+
path ||= file
|
36
|
+
if found = File.exist?(file)
|
37
|
+
path = file
|
38
|
+
break
|
39
|
+
end
|
40
|
+
end
|
41
|
+
path = nil if eat_errors and not found # layout_missing
|
42
|
+
end
|
43
|
+
else
|
44
|
+
path = nil
|
45
|
+
end
|
46
|
+
if path
|
47
|
+
path = path.gsub(settings.root,'') if respond_to?(:settings) && settings.root
|
48
|
+
"View/#{path.gsub(/\.+\//,'')}/Rendering".squeeze("/")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_with_tingyun(*args, &block) # engine, data, options = {}, locals = {}, &block
|
53
|
+
scope_name = tingyun_template_metric(*args, &block)
|
54
|
+
if scope_name
|
55
|
+
TingYun::Agent::MethodTracerHelpers.trace_execution_scoped scope_name do
|
56
|
+
render_without_tingyun(*args, &block)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
render_without_tingyun(*args, &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
alias_method :render_without_tingyun, :render
|
64
|
+
alias_method :render, :render_with_tingyun
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ting_yun/instrumentation/support/evented_subscriber'
|
4
|
+
require 'ting_yun/agent/method_tracer_helpers'
|
5
|
+
require 'ting_yun/agent/transaction'
|
6
|
+
|
7
|
+
module TingYun
|
8
|
+
module Instrumentation
|
9
|
+
module Rails
|
10
|
+
class ActionCableSubscriber < TingYun::Instrumentation::Support::EventedSubscriber
|
11
|
+
|
12
|
+
PERFORM_ACTION = 'perform_action.action_cable'.freeze
|
13
|
+
|
14
|
+
def start (name, id, payload) #THREAD_LOCAL_ACCESS
|
15
|
+
state = TingYun::Agent::TransactionState.tl_get
|
16
|
+
return unless state.execution_traced?
|
17
|
+
event = super
|
18
|
+
if event.name == PERFORM_ACTION
|
19
|
+
start_transaction state, event
|
20
|
+
else
|
21
|
+
start_recording_metrics state, event
|
22
|
+
end
|
23
|
+
rescue => e
|
24
|
+
log_notification_error e, name, 'start'
|
25
|
+
end
|
26
|
+
|
27
|
+
def finish (name, id, payload) #THREAD_LOCAL_ACCESS
|
28
|
+
state = TingYun::Agent::TransactionState.tl_get
|
29
|
+
return unless state.execution_traced?
|
30
|
+
event = super
|
31
|
+
notice_error payload if payload.key? :exception
|
32
|
+
if event.name == PERFORM_ACTION
|
33
|
+
finish_transaction state
|
34
|
+
else
|
35
|
+
stop_recording_metrics state, event
|
36
|
+
end
|
37
|
+
rescue => e
|
38
|
+
log_notification_error e, name, 'finish'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def start_transaction state, event
|
44
|
+
TingYun::Agent::Transaction.start(state, :action_cable, :transaction_name => transaction_name_from_event(event))
|
45
|
+
end
|
46
|
+
|
47
|
+
def finish_transaction state
|
48
|
+
TingYun::Agent::Transaction.stop(state)
|
49
|
+
end
|
50
|
+
|
51
|
+
def start_recording_metrics state, event
|
52
|
+
expected_scope = TingYun::Agent::MethodTracerHelpers::trace_execution_scoped_header(state, event.time.to_f)
|
53
|
+
event.payload[:expected_scope] = expected_scope
|
54
|
+
end
|
55
|
+
|
56
|
+
def stop_recording_metrics state, event
|
57
|
+
expected_scope = event.payload.delete :expected_scope
|
58
|
+
metric_name = metric_name_from_event event
|
59
|
+
TingYun::Agent::MethodTracerHelpers::trace_execution_scoped_footer(state, event.time.to_f, metric_name, [], expected_scope, {:metric => true}, event.end.to_f)
|
60
|
+
end
|
61
|
+
|
62
|
+
def transaction_name_from_event event
|
63
|
+
"WebAction/ActionCable/#{event.payload[:channel_class]}%2F#{event.payload[:action]}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def metric_name_from_event event
|
67
|
+
"ActionCable/#{event.payload[:channel_class]}%2F#{action_name_from_event(event)}"
|
68
|
+
end
|
69
|
+
|
70
|
+
DOT_ACTION_CABLE = ".action_cable".freeze
|
71
|
+
EMPTY_STRING = "".freeze
|
72
|
+
|
73
|
+
def action_name_from_event event
|
74
|
+
event.name.gsub DOT_ACTION_CABLE, EMPTY_STRING
|
75
|
+
end
|
76
|
+
|
77
|
+
def notice_error payload
|
78
|
+
TingYun::Agent.notice_error payload[:exception_object]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|