oneapm_rpm 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.rubocop.yml +725 -0
- data/Gemfile +3 -0
- data/Guardfile +7 -0
- data/LICENSE +1 -0
- data/README.md +3 -0
- data/config/cert/cacert.pem +1177 -0
- data/config/database.yml +5 -0
- data/lib/initializers/goliath.rb +11 -0
- data/lib/initializers/other.rb +1 -0
- data/lib/initializers/rails.rb +15 -0
- data/lib/one_apm/agent.rb +253 -0
- data/lib/one_apm/agent/agent.rb +283 -0
- data/lib/one_apm/agent/agent/connect.rb +175 -0
- data/lib/one_apm/agent/agent/container_data_manager.rb +218 -0
- data/lib/one_apm/agent/agent/forkable_dispatcher_functions.rb +96 -0
- data/lib/one_apm/agent/agent/helpers.rb +45 -0
- data/lib/one_apm/agent/agent/start.rb +226 -0
- data/lib/one_apm/agent/agent/start_worker_thread.rb +148 -0
- data/lib/one_apm/agent/busy_calculator.rb +115 -0
- data/lib/one_apm/agent/cross_app/cross_app_monitor.rb +181 -0
- data/lib/one_apm/agent/cross_app/cross_app_tracing.rb +336 -0
- data/lib/one_apm/agent/database.rb +308 -0
- data/lib/one_apm/agent/database/active_record_helper.rb +80 -0
- data/lib/one_apm/agent/database/obfuscation_helpers.rb +76 -0
- data/lib/one_apm/agent/database/obfuscator.rb +78 -0
- data/lib/one_apm/agent/database/postgres_explain_obfuscator.rb +45 -0
- data/lib/one_apm/agent/datastores.rb +175 -0
- data/lib/one_apm/agent/datastores/metric_helper.rb +83 -0
- data/lib/one_apm/agent/datastores/mongo.rb +27 -0
- data/lib/one_apm/agent/datastores/mongo/metric_translator.rb +189 -0
- data/lib/one_apm/agent/datastores/mongo/obfuscator.rb +37 -0
- data/lib/one_apm/agent/datastores/mongo/statement_formatter.rb +51 -0
- data/lib/one_apm/agent/event/event_listener.rb +40 -0
- data/lib/one_apm/agent/event/event_loop.rb +191 -0
- data/lib/one_apm/agent/event/worker_loop.rb +97 -0
- data/lib/one_apm/agent/harvester.rb +48 -0
- data/lib/one_apm/agent/inbound_request_monitor.rb +30 -0
- data/lib/one_apm/agent/javascript_instrumentor.rb +186 -0
- data/lib/one_apm/agent/pipe/pipe_channel_manager.rb +275 -0
- data/lib/one_apm/agent/pipe/pipe_service.rb +81 -0
- data/lib/one_apm/agent/sampler.rb +55 -0
- data/lib/one_apm/agent/sampler_collection.rb +65 -0
- data/lib/one_apm/agent/samplers/cpu_sampler.rb +49 -0
- data/lib/one_apm/agent/samplers/delayed_job_sampler.rb +109 -0
- data/lib/one_apm/agent/samplers/memory_sampler.rb +144 -0
- data/lib/one_apm/agent/samplers/object_sampler.rb +22 -0
- data/lib/one_apm/agent/samplers/vm_sampler.rb +124 -0
- data/lib/one_apm/agent/synthetics_monitor.rb +48 -0
- data/lib/one_apm/agent/threading/agent_thread.rb +74 -0
- data/lib/one_apm/agent/threading/backtrace_node.rb +133 -0
- data/lib/one_apm/agent/threading/backtrace_service.rb +259 -0
- data/lib/one_apm/agent/threading/thread_profile.rb +155 -0
- data/lib/one_apm/collector/collector/helper.rb +139 -0
- data/lib/one_apm/collector/collector/http_connection.rb +254 -0
- data/lib/one_apm/collector/collector/server_methods.rb +71 -0
- data/lib/one_apm/collector/collector_service.rb +123 -0
- data/lib/one_apm/collector/commands/agent_command.rb +17 -0
- data/lib/one_apm/collector/commands/thread_profiler_session.rb +108 -0
- data/lib/one_apm/collector/commands/xray_session.rb +53 -0
- data/lib/one_apm/collector/commands/xray_session_collection.rb +156 -0
- data/lib/one_apm/collector/containers/agent_command_router.rb +153 -0
- data/lib/one_apm/collector/containers/custom_event_aggregator.rb +94 -0
- data/lib/one_apm/collector/containers/error_collector.rb +349 -0
- data/lib/one_apm/collector/containers/sql_sampler.rb +331 -0
- data/lib/one_apm/collector/containers/stats_engine.rb +34 -0
- data/lib/one_apm/collector/containers/transaction_event_aggregator.rb +249 -0
- data/lib/one_apm/collector/containers/transaction_sampler.rb +352 -0
- data/lib/one_apm/collector/containers/utilization_data.rb +36 -0
- data/lib/one_apm/collector/stats_engine/gc_profiler.rb +106 -0
- data/lib/one_apm/collector/stats_engine/metric_stats.rb +243 -0
- data/lib/one_apm/collector/stats_engine/stats_hash.rb +105 -0
- data/lib/one_apm/configuration.rb +429 -0
- data/lib/one_apm/configuration/autostart.rb +41 -0
- data/lib/one_apm/configuration/default_source.rb +1026 -0
- data/lib/one_apm/configuration/environment_source.rb +113 -0
- data/lib/one_apm/configuration/high_security_source.rb +56 -0
- data/lib/one_apm/configuration/manual_source.rb +13 -0
- data/lib/one_apm/configuration/server_source.rb +60 -0
- data/lib/one_apm/configuration/yaml_source.rb +134 -0
- data/lib/one_apm/errors/agent_errors.rb +26 -0
- data/lib/one_apm/errors/internal_agent_error.rb +16 -0
- data/lib/one_apm/errors/noticed_error.rb +79 -0
- data/lib/one_apm/frameworks/external.rb +15 -0
- data/lib/one_apm/frameworks/rails.rb +103 -0
- data/lib/one_apm/frameworks/rails3.rb +37 -0
- data/lib/one_apm/frameworks/rails4.rb +21 -0
- data/lib/one_apm/frameworks/ruby.rb +21 -0
- data/lib/one_apm/frameworks/sinatra.rb +12 -0
- data/lib/one_apm/inst/3rd/active_merchant.rb +35 -0
- data/lib/one_apm/inst/3rd/acts_as_solr.rb +70 -0
- data/lib/one_apm/inst/3rd/authlogic.rb +23 -0
- data/lib/one_apm/inst/3rd/sunspot.rb +31 -0
- data/lib/one_apm/inst/background_job/active_job.rb +88 -0
- data/lib/one_apm/inst/background_job/delayed_job.rb +52 -0
- data/lib/one_apm/inst/background_job/delayed_job_injection.rb +8 -0
- data/lib/one_apm/inst/background_job/resque.rb +107 -0
- data/lib/one_apm/inst/background_job/sidekiq.rb +64 -0
- data/lib/one_apm/inst/dispatcher/passenger.rb +25 -0
- data/lib/one_apm/inst/dispatcher/rainbows.rb +23 -0
- data/lib/one_apm/inst/framework/grape.rb +94 -0
- data/lib/one_apm/inst/framework/padrino.rb +30 -0
- data/lib/one_apm/inst/framework/sinatra.rb +185 -0
- data/lib/one_apm/inst/framework/sinatra/ignorer.rb +50 -0
- data/lib/one_apm/inst/framework/sinatra/transaction_namer.rb +54 -0
- data/lib/one_apm/inst/http_clients/curb.rb +189 -0
- data/lib/one_apm/inst/http_clients/excon.rb +70 -0
- data/lib/one_apm/inst/http_clients/excon/connection.rb +31 -0
- data/lib/one_apm/inst/http_clients/excon/middleware.rb +55 -0
- data/lib/one_apm/inst/http_clients/httpclient.rb +44 -0
- data/lib/one_apm/inst/http_clients/net.rb +34 -0
- data/lib/one_apm/inst/http_clients/typhoeus.rb +76 -0
- data/lib/one_apm/inst/nosql/memcache.rb +134 -0
- data/lib/one_apm/inst/nosql/mongo.rb +126 -0
- data/lib/one_apm/inst/nosql/mongo_moped.rb +85 -0
- data/lib/one_apm/inst/nosql/redis.rb +83 -0
- data/lib/one_apm/inst/orm/active_record.rb +99 -0
- data/lib/one_apm/inst/orm/active_record_4.rb +28 -0
- data/lib/one_apm/inst/orm/data_mapper.rb +180 -0
- data/lib/one_apm/inst/orm/sequel.rb +47 -0
- data/lib/one_apm/inst/rack.rb +38 -0
- data/lib/one_apm/inst/rack/rack.rb +44 -0
- data/lib/one_apm/inst/rack/rack_builder.rb +51 -0
- data/lib/one_apm/inst/rails/action_controller.rb +118 -0
- data/lib/one_apm/inst/rails/action_web_service.rb +44 -0
- data/lib/one_apm/inst/rails/errors.rb +43 -0
- data/lib/one_apm/inst/rails3/action_controller.rb +172 -0
- data/lib/one_apm/inst/rails3/errors.rb +43 -0
- data/lib/one_apm/inst/rails4/action_controller.rb +27 -0
- data/lib/one_apm/inst/rails4/action_controller_subscriber.rb +121 -0
- data/lib/one_apm/inst/rails4/action_view.rb +23 -0
- data/lib/one_apm/inst/rails4/action_view_subscriber.rb +93 -0
- data/lib/one_apm/inst/rails4/active_record_subscriber.rb +96 -0
- data/lib/one_apm/inst/rails4/errors.rb +42 -0
- data/lib/one_apm/inst/rails_middleware.rb +40 -0
- data/lib/one_apm/inst/support/evented_subscriber.rb +98 -0
- data/lib/one_apm/inst/support/ignore_actions.rb +39 -0
- data/lib/one_apm/inst/support/queue_time.rb +76 -0
- data/lib/one_apm/inst/transaction_base.rb +405 -0
- data/lib/one_apm/logger/agent_logger.rb +206 -0
- data/lib/one_apm/logger/audit_logger.rb +78 -0
- data/lib/one_apm/logger/memory_logger.rb +50 -0
- data/lib/one_apm/logger/null_logger.rb +19 -0
- data/lib/one_apm/metrics/metric_data.rb +72 -0
- data/lib/one_apm/metrics/metric_spec.rb +82 -0
- data/lib/one_apm/metrics/stats.rb +173 -0
- data/lib/one_apm/probe.rb +16 -0
- data/lib/one_apm/probe/framework_loader.rb +53 -0
- data/lib/one_apm/probe/instance_methods.rb +105 -0
- data/lib/one_apm/probe/instrumentation.rb +60 -0
- data/lib/one_apm/rack/browser_monitoring.rb +144 -0
- data/lib/one_apm/rack/middleware_base.rb +27 -0
- data/lib/one_apm/rack/middleware_hooks.rb +17 -0
- data/lib/one_apm/rack/middleware_tracing.rb +81 -0
- data/lib/one_apm/rack/middleware_wrapper.rb +86 -0
- data/lib/one_apm/support/chained_call.rb +15 -0
- data/lib/one_apm/support/coerce.rb +81 -0
- data/lib/one_apm/support/collection_helper.rb +79 -0
- data/lib/one_apm/support/dotted_hash.rb +45 -0
- data/lib/one_apm/support/encoders.rb +34 -0
- data/lib/one_apm/support/environment_report.rb +127 -0
- data/lib/one_apm/support/event_buffer.rb +82 -0
- data/lib/one_apm/support/event_buffer/sampled_buffer.rb +45 -0
- data/lib/one_apm/support/event_buffer/sized_buffer.rb +21 -0
- data/lib/one_apm/support/event_buffer/synthetics_event_buffer.rb +40 -0
- data/lib/one_apm/support/helper.rb +49 -0
- data/lib/one_apm/support/hostname.rb +13 -0
- data/lib/one_apm/support/http_clients/curb_wrappers.rb +65 -0
- data/lib/one_apm/support/http_clients/excon_wrappers.rb +63 -0
- data/lib/one_apm/support/http_clients/httpclient_wrappers.rb +61 -0
- data/lib/one_apm/support/http_clients/net_http_wrappers.rb +48 -0
- data/lib/one_apm/support/http_clients/typhoeus_wrappers.rb +73 -0
- data/lib/one_apm/support/http_clients/uri_util.rb +39 -0
- data/lib/one_apm/support/json_marshaller.rb +68 -0
- data/lib/one_apm/support/json_wrapper.rb +130 -0
- data/lib/one_apm/support/language_support.rb +142 -0
- data/lib/one_apm/support/library_detection.rb +119 -0
- data/lib/one_apm/support/local_environment.rb +196 -0
- data/lib/one_apm/support/marshaller.rb +62 -0
- data/lib/one_apm/support/method_tracer.rb +334 -0
- data/lib/one_apm/support/method_tracer/helpers.rb +92 -0
- data/lib/one_apm/support/method_tracer/traced_method_stack.rb +103 -0
- data/lib/one_apm/support/obfuscator.rb +47 -0
- data/lib/one_apm/support/okjson.rb +601 -0
- data/lib/one_apm/support/parameter_filtering.rb +35 -0
- data/lib/one_apm/support/rules_engine.rb +56 -0
- data/lib/one_apm/support/rules_engine/replacement_rule.rb +80 -0
- data/lib/one_apm/support/rules_engine/segment_terms_rule.rb +46 -0
- data/lib/one_apm/support/server.rb +11 -0
- data/lib/one_apm/support/supported_versions.rb +257 -0
- data/lib/one_apm/support/system_info.rb +211 -0
- data/lib/one_apm/support/timer_lib.rb +29 -0
- data/lib/one_apm/support/version_number.rb +51 -0
- data/lib/one_apm/support/vm.rb +30 -0
- data/lib/one_apm/support/vm/jruby_vm.rb +38 -0
- data/lib/one_apm/support/vm/monotonic_gc_profiler.rb +43 -0
- data/lib/one_apm/support/vm/mri_vm.rb +85 -0
- data/lib/one_apm/support/vm/rubinius_vm.rb +129 -0
- data/lib/one_apm/support/vm/snapshot.rb +18 -0
- data/lib/one_apm/transaction.rb +336 -0
- data/lib/one_apm/transaction/class_methods.rb +132 -0
- data/lib/one_apm/transaction/instance_helpers.rb +82 -0
- data/lib/one_apm/transaction/metric_constants.rb +42 -0
- data/lib/one_apm/transaction/sample_buffer/force_persist_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/slowest_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/synthetics_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/transaction_sample_buffer.rb +101 -0
- data/lib/one_apm/transaction/sample_buffer/xray_sample_buffer.rb +60 -0
- data/lib/one_apm/transaction/segment.rb +193 -0
- data/lib/one_apm/transaction/segment_summary.rb +51 -0
- data/lib/one_apm/transaction/thread_local_access.rb +73 -0
- data/lib/one_apm/transaction/transaction_analysis.rb +78 -0
- data/lib/one_apm/transaction/transaction_apdex.rb +20 -0
- data/lib/one_apm/transaction/transaction_cpu.rb +22 -0
- data/lib/one_apm/transaction/transaction_finish_append.rb +67 -0
- data/lib/one_apm/transaction/transaction_ignore.rb +33 -0
- data/lib/one_apm/transaction/transaction_jruby_functions.rb +40 -0
- data/lib/one_apm/transaction/transaction_metrics.rb +53 -0
- data/lib/one_apm/transaction/transaction_name.rb +90 -0
- data/lib/one_apm/transaction/transaction_namer.rb +49 -0
- data/lib/one_apm/transaction/transaction_sample.rb +204 -0
- data/lib/one_apm/transaction/transaction_sample_builder.rb +168 -0
- data/lib/one_apm/transaction/transaction_state.rb +149 -0
- data/lib/one_apm/transaction/transaction_summary.rb +28 -0
- data/lib/one_apm/transaction/transaction_synthetics.rb +40 -0
- data/lib/one_apm/transaction/transaction_timings.rb +54 -0
- data/lib/one_apm/version.rb +13 -0
- data/lib/oneapm_rpm.rb +16 -0
- data/lib/sequel/extensions/oneapm_instrumentation.rb +84 -0
- data/lib/sequel/plugins/oneapm_instrumentation.rb +66 -0
- data/oneapm.yml +135 -0
- data/oneapm_rpm.gemspec +58 -0
- metadata +474 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/rack/middleware_tracing'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
module Rack
|
7
|
+
class MiddlewareBase
|
8
|
+
include MiddlewareTracing
|
9
|
+
|
10
|
+
attr_reader :transaction_options, :category, :target
|
11
|
+
|
12
|
+
def initialize(app, options={})
|
13
|
+
@app = app
|
14
|
+
@category = :middleware
|
15
|
+
@target = self
|
16
|
+
@transaction_options = {
|
17
|
+
:transaction_name => build_transaction_name
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_transaction_name
|
22
|
+
prefix = OneApm::TransactionNamer.prefix_for_category(nil, @category)
|
23
|
+
"#{prefix}#{self.class.name}/call"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/rack/middleware_base'
|
4
|
+
|
5
|
+
module OneApm::Rack
|
6
|
+
class MiddlewareHooks < MiddlewareBase
|
7
|
+
|
8
|
+
def self.needed?
|
9
|
+
!OneApm::Agent.config[:disable_rack_middleware]
|
10
|
+
end
|
11
|
+
|
12
|
+
def traced_call(env)
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/support/method_tracer'
|
4
|
+
require 'one_apm/transaction'
|
5
|
+
require 'one_apm/transaction/transaction_state'
|
6
|
+
require 'one_apm/inst/support/queue_time'
|
7
|
+
require 'one_apm/inst/transaction_base'
|
8
|
+
|
9
|
+
# This module is intended to be included into both MiddlewareWrapper and our
|
10
|
+
# internal middleware classes.
|
11
|
+
#
|
12
|
+
# Host classes must define two methods:
|
13
|
+
#
|
14
|
+
# * target: returns the original middleware being traced
|
15
|
+
# * category: returns the category for the resulting agent transaction
|
16
|
+
# should be either :middleware or :rack
|
17
|
+
# * transaction_options: returns an options hash to be passed to
|
18
|
+
# Transaction.start when tracing this middleware.
|
19
|
+
#
|
20
|
+
# The target may be self, in which case the host class should define a
|
21
|
+
# #traced_call method, instead of the usual #call.
|
22
|
+
|
23
|
+
module OneApm::Rack
|
24
|
+
module MiddlewareTracing
|
25
|
+
TXN_STARTED_KEY = 'oneapm.transaction_started'.freeze unless defined?(TXN_STARTED_KEY)
|
26
|
+
|
27
|
+
def _oa_has_middleware_tracing
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_transaction_options(env, first_middleware)
|
32
|
+
opts = transaction_options
|
33
|
+
opts = merge_first_middleware_options(opts, env) if first_middleware
|
34
|
+
opts
|
35
|
+
end
|
36
|
+
|
37
|
+
def merge_first_middleware_options(opts, env)
|
38
|
+
opts.merge(
|
39
|
+
:request => ::Rack::Request.new(env),
|
40
|
+
:apdex_start_time => OneApm::Agent::Instrumentation::QueueTime.parse_frontend_timestamp(env)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def note_transaction_started(env)
|
45
|
+
env[TXN_STARTED_KEY] = true unless env[TXN_STARTED_KEY]
|
46
|
+
end
|
47
|
+
|
48
|
+
def capture_http_response_code(state, result)
|
49
|
+
if result.is_a?(Array) && state.current_transaction
|
50
|
+
state.current_transaction.http_response_code = result[0]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def call(env)
|
55
|
+
first_middleware = note_transaction_started(env)
|
56
|
+
|
57
|
+
state = OneApm::TransactionState.tl_get
|
58
|
+
|
59
|
+
begin
|
60
|
+
OneApm::Transaction.start(state, category, build_transaction_options(env, first_middleware))
|
61
|
+
events.notify(:before_call, env) if first_middleware
|
62
|
+
|
63
|
+
result = (target == self) ? traced_call(env) : target.call(env)
|
64
|
+
|
65
|
+
capture_http_response_code(state, result)
|
66
|
+
events.notify(:after_call, env, result) if first_middleware
|
67
|
+
|
68
|
+
result
|
69
|
+
rescue Exception => e
|
70
|
+
OneApm::Agent.notice_error(e)
|
71
|
+
raise e
|
72
|
+
ensure
|
73
|
+
OneApm::Transaction.stop(state)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def events
|
78
|
+
OneApm::Agent.instance.events
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/support/method_tracer'
|
4
|
+
require 'one_apm/transaction'
|
5
|
+
require 'one_apm/transaction/transaction_state'
|
6
|
+
require 'one_apm/inst/support/queue_time'
|
7
|
+
require 'one_apm/inst/transaction_base'
|
8
|
+
require 'one_apm/rack/middleware_tracing'
|
9
|
+
|
10
|
+
module OneApm::Rack
|
11
|
+
class MiddlewareWrapper
|
12
|
+
include MiddlewareTracing
|
13
|
+
|
14
|
+
class MiddlewareClassWrapper
|
15
|
+
|
16
|
+
def initialize(middleware_class)
|
17
|
+
@middleware_class = middleware_class
|
18
|
+
end
|
19
|
+
|
20
|
+
def new(*args, &blk)
|
21
|
+
middleware_instance = @middleware_class.new(*args, &blk)
|
22
|
+
MiddlewareWrapper.wrap(middleware_instance)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
def is_sinatra_app?(target)
|
30
|
+
defined?(::Sinatra::Base) && target.kind_of?(::Sinatra::Base)
|
31
|
+
end
|
32
|
+
|
33
|
+
def wrap_class(target_class)
|
34
|
+
MiddlewareClassWrapper.new(target_class)
|
35
|
+
end
|
36
|
+
|
37
|
+
def needs_wrapping?(target)
|
38
|
+
!target.respond_to?(:_oa_has_middleware_tracing) &&
|
39
|
+
!is_sinatra_app?(target)
|
40
|
+
end
|
41
|
+
|
42
|
+
def wrap(target, is_app = false)
|
43
|
+
if needs_wrapping?(target)
|
44
|
+
self.new(target, is_app)
|
45
|
+
else
|
46
|
+
target
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
attr_reader :target, :category, :transaction_options
|
53
|
+
|
54
|
+
def initialize(target, is_app = false)
|
55
|
+
@target = target
|
56
|
+
@is_app = is_app
|
57
|
+
@category = determine_category
|
58
|
+
@target_class_name = determine_class_name
|
59
|
+
@transaction_name = "#{determine_prefix}#{@target_class_name}/call"
|
60
|
+
@transaction_options = {
|
61
|
+
:transaction_name => @transaction_name
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def determine_category
|
66
|
+
@is_app ? :rack : :middleware
|
67
|
+
end
|
68
|
+
|
69
|
+
def determine_prefix
|
70
|
+
OneApm::TransactionNamer.prefix_for_category(nil, @category)
|
71
|
+
end
|
72
|
+
|
73
|
+
# In 'normal' usage, the target will be an application instance that
|
74
|
+
# responds to #call. With Rails, however, the target may be a subclass
|
75
|
+
# of Rails::Application that defines a method_missing that proxies #call
|
76
|
+
# to a singleton instance of the the subclass. We need to ensure that we
|
77
|
+
# capture the correct name in both cases.
|
78
|
+
def determine_class_name
|
79
|
+
if @target.is_a?(Class)
|
80
|
+
@target.name
|
81
|
+
else
|
82
|
+
@target.class.name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# This class is used by OneApm::Agent.set_sql_obfuscator to chain multiple
|
4
|
+
# obfuscation blocks when not using the default :replace action
|
5
|
+
class OneApm::ChainedCall
|
6
|
+
def initialize(block1, block2)
|
7
|
+
@block1 = block1
|
8
|
+
@block2 = block2
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(sql)
|
12
|
+
sql = @block1.call(sql)
|
13
|
+
@block2.call(sql)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
# We really don't want to send bad values to the collector, and it doesn't
|
5
|
+
# accept types like Rational that have occasionally slipped into our data.
|
6
|
+
#
|
7
|
+
# These methods are intended to safely coerce things into the form we want,
|
8
|
+
# to provide documentation of expected types on to_collector_array methods,
|
9
|
+
# and to log failures if totally invalid data gets into outgoing data
|
10
|
+
module Coerce
|
11
|
+
def int(value, context=nil)
|
12
|
+
Integer(value)
|
13
|
+
rescue => error
|
14
|
+
log_failure(value, Integer, context, error)
|
15
|
+
0
|
16
|
+
end
|
17
|
+
|
18
|
+
def int_or_nil(value, context=nil)
|
19
|
+
return nil if value.nil?
|
20
|
+
Integer(value)
|
21
|
+
rescue => error
|
22
|
+
log_failure(value, Integer, context, error)
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def float(value, context=nil)
|
27
|
+
result = Float(value)
|
28
|
+
raise "Value #{result.inspect} is not finite." unless result.finite?
|
29
|
+
result
|
30
|
+
rescue => error
|
31
|
+
log_failure(value, Float, context, error)
|
32
|
+
0.0
|
33
|
+
end
|
34
|
+
|
35
|
+
def string(value, context=nil)
|
36
|
+
return value if value.nil?
|
37
|
+
String(value)
|
38
|
+
rescue => error
|
39
|
+
log_failure(value.class, String, context, error)
|
40
|
+
""
|
41
|
+
end
|
42
|
+
|
43
|
+
# Convert a hash into a format acceptable to be included with Transaction
|
44
|
+
# event data.
|
45
|
+
#
|
46
|
+
# We accept a hash and will return a new hash where all of the keys
|
47
|
+
# have been converted to strings. As values we only allow Strings,
|
48
|
+
# Floats, Integers. Symbols are also allowed but are converted to strings.
|
49
|
+
# Any values of other type (e.g. Hash, Array, any other class) are
|
50
|
+
# discarded. Their keys are also removed from the results hash.
|
51
|
+
def event_params(value, context=nil)
|
52
|
+
unless value.is_a? Hash
|
53
|
+
raise ArgumentError, "Expected Hash but got #{value.class}"
|
54
|
+
end
|
55
|
+
value.inject({}) do |memo, (key, val)|
|
56
|
+
case val
|
57
|
+
when String, Integer, TrueClass, FalseClass
|
58
|
+
memo[key.to_s] = val
|
59
|
+
when Float
|
60
|
+
if val.finite?
|
61
|
+
memo[key.to_s] = val
|
62
|
+
else
|
63
|
+
memo[key.to_s] = nil
|
64
|
+
end
|
65
|
+
when Symbol
|
66
|
+
memo[key.to_s] = val.to_s
|
67
|
+
end
|
68
|
+
memo
|
69
|
+
end
|
70
|
+
rescue => error
|
71
|
+
log_failure(value.class, 'valid event params', context, error)
|
72
|
+
{}
|
73
|
+
end
|
74
|
+
|
75
|
+
def log_failure(value, type, context, error)
|
76
|
+
msg = "Unable to convert '#{value}' to #{type}"
|
77
|
+
msg += " in context '#{context}'" if context
|
78
|
+
OneApm::Agent.logger.warn(msg, error)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/probe'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
module CollectionHelper
|
7
|
+
DEFAULT_TRUNCATION_SIZE=16 * 1024
|
8
|
+
DEFAULT_ARRAY_TRUNCATION_SIZE=128
|
9
|
+
# Transform parameter hash into a hash whose values are strictly
|
10
|
+
# strings
|
11
|
+
def normalize_params(params)
|
12
|
+
case params
|
13
|
+
when Hash
|
14
|
+
# optimize for empty hash since that is often what this is called with.
|
15
|
+
return params if params.empty?
|
16
|
+
new_params = {}
|
17
|
+
params.each do | key, value |
|
18
|
+
new_params[truncate(normalize_params(key),64)] = normalize_params(value)
|
19
|
+
end
|
20
|
+
new_params
|
21
|
+
when Symbol, FalseClass, TrueClass, nil
|
22
|
+
params
|
23
|
+
when Numeric
|
24
|
+
truncate(params.to_s)
|
25
|
+
when String
|
26
|
+
truncate(params)
|
27
|
+
when Array
|
28
|
+
params.first(DEFAULT_ARRAY_TRUNCATION_SIZE).map{|item| normalize_params(item)}
|
29
|
+
else
|
30
|
+
truncate(flatten(params))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Return an array of strings (backtrace), cleaned up for readability
|
35
|
+
# Return nil if there is no backtrace
|
36
|
+
|
37
|
+
def strip_oa_from_backtrace(backtrace)
|
38
|
+
if backtrace && !Agent.config[:disable_backtrace_cleanup]
|
39
|
+
# this is for 1.9.1, where strings no longer have Enumerable
|
40
|
+
backtrace = backtrace.split("\n") if String === backtrace
|
41
|
+
backtrace = backtrace.map(&:to_s)
|
42
|
+
backtrace = backtrace.reject do |line|
|
43
|
+
line.include?(OneApm::Probe.oneapm_root) or
|
44
|
+
line =~ /^oneapm_rpm\s/
|
45
|
+
end
|
46
|
+
# rename methods back to their original state
|
47
|
+
backtrace = backtrace.collect {|line| line.gsub(/_without_(oneapm|trace)/, "")}
|
48
|
+
end
|
49
|
+
backtrace
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Convert any kind of object to a short string.
|
55
|
+
def flatten(object)
|
56
|
+
case object
|
57
|
+
when nil then ''
|
58
|
+
when object.instance_of?(String) then object
|
59
|
+
when String then String.new(object) # convert string subclasses to strings
|
60
|
+
else "#<#{object.class.to_s}>"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
def truncate(string, len=DEFAULT_TRUNCATION_SIZE)
|
64
|
+
case string
|
65
|
+
when Symbol then string
|
66
|
+
when nil then ""
|
67
|
+
when String
|
68
|
+
real_string = flatten(string)
|
69
|
+
if real_string.size > len
|
70
|
+
real_string = real_string.slice(0...len)
|
71
|
+
real_string << "..."
|
72
|
+
end
|
73
|
+
real_string
|
74
|
+
else
|
75
|
+
truncate(flatten(string), len)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
module Support
|
5
|
+
class DottedHash < ::Hash
|
6
|
+
|
7
|
+
def self.symbolize(hash)
|
8
|
+
hash.keys.each do |key|
|
9
|
+
hash[key.to_sym] = hash.delete(key)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(hash, keep_nesting = false)
|
14
|
+
merge!(hash) if keep_nesting
|
15
|
+
merge!(dot_flattened(hash))
|
16
|
+
|
17
|
+
DottedHash.symbolize(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
"#<#{self.class.name}:#{object_id} #{super}>"
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_hash
|
25
|
+
{}.replace(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
# turns {'a' => {'b' => 'c'}} into {'a.b' => 'c'}
|
31
|
+
def dot_flattened(nested_hash, names=[], result={})
|
32
|
+
nested_hash.each do |key, val|
|
33
|
+
next if val == nil
|
34
|
+
if val.respond_to?(:has_key?)
|
35
|
+
dot_flattened(val, names + [key], result)
|
36
|
+
else
|
37
|
+
result[(names + [key]).join('.')] = val
|
38
|
+
end
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'zlib'
|
5
|
+
|
6
|
+
module OneApm
|
7
|
+
module Support
|
8
|
+
module Encoders
|
9
|
+
module Identity
|
10
|
+
def self.encode(data, opts=nil)
|
11
|
+
data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Compressed
|
16
|
+
def self.encode(data, opts=nil)
|
17
|
+
Zlib::Deflate.deflate(data, Zlib::DEFAULT_COMPRESSION)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Base64CompressedJSON
|
22
|
+
def self.encode(data, opts={})
|
23
|
+
normalize_encodings = if opts[:skip_normalization]
|
24
|
+
false
|
25
|
+
else
|
26
|
+
Agent.config[:normalize_json_string_encodings]
|
27
|
+
end
|
28
|
+
json = ::OneApm::JSONWrapper.dump(data, :normalize => normalize_encodings)
|
29
|
+
Base64.encode64(Compressed.encode(json))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|