traceview 3.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +58 -0
- data/Appraisals +10 -0
- data/CHANGELOG.md +490 -0
- data/CONFIG.md +16 -0
- data/Gemfile +95 -0
- data/LICENSE +199 -0
- data/README.md +380 -0
- data/Rakefile +109 -0
- data/examples/DNT.md +35 -0
- data/examples/carrying_context.rb +225 -0
- data/examples/instrumenting_metal_controller.rb +8 -0
- data/examples/puma_on_heroku_config.rb +17 -0
- data/examples/tracing_async_threads.rb +125 -0
- data/examples/tracing_background_jobs.rb +52 -0
- data/examples/tracing_forked_processes.rb +100 -0
- data/examples/unicorn_on_heroku_config.rb +28 -0
- data/ext/oboe_metal/extconf.rb +61 -0
- data/ext/oboe_metal/noop/noop.c +7 -0
- data/ext/oboe_metal/src/bson/bson.h +221 -0
- data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
- data/ext/oboe_metal/src/oboe.h +275 -0
- data/ext/oboe_metal/src/oboe.hpp +352 -0
- data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
- data/ext/oboe_metal/tests/test.rb +11 -0
- data/gemfiles/mongo.gemfile +33 -0
- data/gemfiles/moped.gemfile +33 -0
- data/get_version.rb +5 -0
- data/init.rb +4 -0
- data/lib/joboe_metal.rb +206 -0
- data/lib/oboe/README +2 -0
- data/lib/oboe/backward_compatibility.rb +59 -0
- data/lib/oboe/inst/rack.rb +11 -0
- data/lib/oboe.rb +7 -0
- data/lib/oboe_metal.rb +151 -0
- data/lib/rails/generators/traceview/install_generator.rb +76 -0
- data/lib/rails/generators/traceview/templates/traceview_initializer.rb +159 -0
- data/lib/traceview/api/layerinit.rb +51 -0
- data/lib/traceview/api/logging.rb +209 -0
- data/lib/traceview/api/memcache.rb +31 -0
- data/lib/traceview/api/profiling.rb +50 -0
- data/lib/traceview/api/tracing.rb +135 -0
- data/lib/traceview/api/util.rb +121 -0
- data/lib/traceview/api.rb +18 -0
- data/lib/traceview/base.rb +225 -0
- data/lib/traceview/config.rb +238 -0
- data/lib/traceview/frameworks/grape.rb +97 -0
- data/lib/traceview/frameworks/padrino/templates.rb +58 -0
- data/lib/traceview/frameworks/padrino.rb +64 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
- data/lib/traceview/frameworks/rails/inst/action_controller.rb +216 -0
- data/lib/traceview/frameworks/rails/inst/action_view.rb +56 -0
- data/lib/traceview/frameworks/rails/inst/action_view_2x.rb +54 -0
- data/lib/traceview/frameworks/rails/inst/action_view_30.rb +48 -0
- data/lib/traceview/frameworks/rails/inst/active_record.rb +24 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +117 -0
- data/lib/traceview/frameworks/rails.rb +145 -0
- data/lib/traceview/frameworks/sinatra/templates.rb +56 -0
- data/lib/traceview/frameworks/sinatra.rb +95 -0
- data/lib/traceview/inst/cassandra.rb +279 -0
- data/lib/traceview/inst/dalli.rb +86 -0
- data/lib/traceview/inst/em-http-request.rb +99 -0
- data/lib/traceview/inst/excon.rb +111 -0
- data/lib/traceview/inst/faraday.rb +73 -0
- data/lib/traceview/inst/http.rb +87 -0
- data/lib/traceview/inst/httpclient.rb +173 -0
- data/lib/traceview/inst/memcache.rb +102 -0
- data/lib/traceview/inst/memcached.rb +94 -0
- data/lib/traceview/inst/mongo.rb +238 -0
- data/lib/traceview/inst/moped.rb +474 -0
- data/lib/traceview/inst/rack.rb +122 -0
- data/lib/traceview/inst/redis.rb +271 -0
- data/lib/traceview/inst/resque.rb +192 -0
- data/lib/traceview/inst/rest-client.rb +38 -0
- data/lib/traceview/inst/sequel.rb +162 -0
- data/lib/traceview/inst/typhoeus.rb +102 -0
- data/lib/traceview/instrumentation.rb +21 -0
- data/lib/traceview/loading.rb +94 -0
- data/lib/traceview/logger.rb +41 -0
- data/lib/traceview/method_profiling.rb +84 -0
- data/lib/traceview/ruby.rb +36 -0
- data/lib/traceview/support.rb +113 -0
- data/lib/traceview/thread_local.rb +26 -0
- data/lib/traceview/util.rb +250 -0
- data/lib/traceview/version.rb +16 -0
- data/lib/traceview/xtrace.rb +90 -0
- data/lib/traceview.rb +62 -0
- data/test/frameworks/apps/grape_nested.rb +30 -0
- data/test/frameworks/apps/grape_simple.rb +24 -0
- data/test/frameworks/apps/padrino_simple.rb +45 -0
- data/test/frameworks/apps/sinatra_simple.rb +24 -0
- data/test/frameworks/grape_test.rb +142 -0
- data/test/frameworks/padrino_test.rb +30 -0
- data/test/frameworks/sinatra_test.rb +30 -0
- data/test/instrumentation/cassandra_test.rb +380 -0
- data/test/instrumentation/dalli_test.rb +171 -0
- data/test/instrumentation/em_http_request_test.rb +86 -0
- data/test/instrumentation/excon_test.rb +207 -0
- data/test/instrumentation/faraday_test.rb +235 -0
- data/test/instrumentation/http_test.rb +140 -0
- data/test/instrumentation/httpclient_test.rb +296 -0
- data/test/instrumentation/memcache_test.rb +251 -0
- data/test/instrumentation/memcached_test.rb +226 -0
- data/test/instrumentation/mongo_test.rb +462 -0
- data/test/instrumentation/moped_test.rb +496 -0
- data/test/instrumentation/rack_test.rb +116 -0
- data/test/instrumentation/redis_hashes_test.rb +265 -0
- data/test/instrumentation/redis_keys_test.rb +318 -0
- data/test/instrumentation/redis_lists_test.rb +310 -0
- data/test/instrumentation/redis_misc_test.rb +160 -0
- data/test/instrumentation/redis_sets_test.rb +293 -0
- data/test/instrumentation/redis_sortedsets_test.rb +325 -0
- data/test/instrumentation/redis_strings_test.rb +333 -0
- data/test/instrumentation/resque_test.rb +62 -0
- data/test/instrumentation/rest-client_test.rb +294 -0
- data/test/instrumentation/sequel_mysql2_test.rb +326 -0
- data/test/instrumentation/sequel_mysql_test.rb +326 -0
- data/test/instrumentation/sequel_pg_test.rb +330 -0
- data/test/instrumentation/typhoeus_test.rb +285 -0
- data/test/minitest_helper.rb +187 -0
- data/test/profiling/method_test.rb +198 -0
- data/test/servers/rackapp_8101.rb +22 -0
- data/test/support/backcompat_test.rb +269 -0
- data/test/support/config_test.rb +128 -0
- data/test/support/dnt_test.rb +73 -0
- data/test/support/liboboe_settings_test.rb +104 -0
- data/test/support/xtrace_test.rb +35 -0
- data/traceview.gemspec +29 -0
- metadata +248 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "dalli"
|
6
|
+
gem "memcache-client"
|
7
|
+
gem "memcached", "1.7.2"
|
8
|
+
gem "cassandra"
|
9
|
+
gem "mongo"
|
10
|
+
gem "bson"
|
11
|
+
gem "moped", "~> 1.5"
|
12
|
+
gem "resque"
|
13
|
+
gem "redis"
|
14
|
+
gem "sinatra"
|
15
|
+
gem "padrino", "0.12.0"
|
16
|
+
gem "grape"
|
17
|
+
|
18
|
+
group :development, :test do
|
19
|
+
gem "minitest"
|
20
|
+
gem "minitest-reporters"
|
21
|
+
gem "rack-test"
|
22
|
+
gem "appraisal"
|
23
|
+
end
|
24
|
+
|
25
|
+
group :development do
|
26
|
+
gem "ruby-debug", :platform => :mri_18
|
27
|
+
gem "debugger", :platform => :mri_19
|
28
|
+
gem "byebug", :platforms => [:mri_20, :mri_21]
|
29
|
+
gem "perftools.rb", :platforms => [:mri_20, :mri_21], :require => "perftools"
|
30
|
+
gem "pry"
|
31
|
+
end
|
32
|
+
|
33
|
+
gemspec :name => "oboe", :path => "../"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "dalli"
|
6
|
+
gem "memcache-client"
|
7
|
+
gem "memcached", "1.7.2"
|
8
|
+
gem "cassandra"
|
9
|
+
gem "mongo"
|
10
|
+
gem "bson"
|
11
|
+
gem "moped", "~> 1.5"
|
12
|
+
gem "resque"
|
13
|
+
gem "redis"
|
14
|
+
gem "sinatra"
|
15
|
+
gem "padrino", "0.12.0"
|
16
|
+
gem "grape"
|
17
|
+
|
18
|
+
group :development, :test do
|
19
|
+
gem "minitest"
|
20
|
+
gem "minitest-reporters"
|
21
|
+
gem "rack-test"
|
22
|
+
gem "appraisal"
|
23
|
+
end
|
24
|
+
|
25
|
+
group :development do
|
26
|
+
gem "ruby-debug", :platform => :mri_18
|
27
|
+
gem "debugger", :platform => :mri_19
|
28
|
+
gem "byebug", :platforms => [:mri_20, :mri_21]
|
29
|
+
gem "perftools.rb", :platforms => [:mri_20, :mri_21], :require => "perftools"
|
30
|
+
gem "pry"
|
31
|
+
end
|
32
|
+
|
33
|
+
gemspec :name => "oboe", :path => "../"
|
data/get_version.rb
ADDED
data/init.rb
ADDED
data/lib/joboe_metal.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
# Copyright (c) 2013 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
module Oboe_metal
|
5
|
+
include_package 'com.tracelytics.joboe'
|
6
|
+
java_import 'com.tracelytics.joboe.LayerUtil'
|
7
|
+
java_import 'com.tracelytics.joboe.SettingsReader'
|
8
|
+
java_import 'com.tracelytics.joboe.Context'
|
9
|
+
java_import 'com.tracelytics.joboe.Event'
|
10
|
+
java_import 'com.tracelytics.agent.Agent'
|
11
|
+
|
12
|
+
class Context
|
13
|
+
class << self
|
14
|
+
def toString
|
15
|
+
getMetadata.toHexString
|
16
|
+
end
|
17
|
+
|
18
|
+
def fromString(xtrace)
|
19
|
+
Context.setMetadata(xtrace)
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear
|
23
|
+
clearMetadata
|
24
|
+
end
|
25
|
+
|
26
|
+
def get
|
27
|
+
getMetadata
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Event
|
33
|
+
def self.metadataString(evt)
|
34
|
+
evt.getMetadata.toHexString
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def UdpReporter
|
39
|
+
Java::ComTracelyticsJoboe
|
40
|
+
end
|
41
|
+
|
42
|
+
module Metadata
|
43
|
+
Java::ComTracelyticsJoboeMetaData
|
44
|
+
end
|
45
|
+
|
46
|
+
module Reporter
|
47
|
+
##
|
48
|
+
# Initialize the TraceView Context, reporter and report the initialization
|
49
|
+
#
|
50
|
+
def self.start
|
51
|
+
return unless TraceView.loaded
|
52
|
+
|
53
|
+
if ENV.key?('TRACEVIEW_GEM_TEST')
|
54
|
+
TraceView.reporter = Java::ComTracelyticsJoboe::TestReporter.new
|
55
|
+
else
|
56
|
+
TraceView.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance.buildUdpReporter
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
begin
|
61
|
+
# Import the tracing mode and sample rate settings
|
62
|
+
# from the Java agent (user configured in
|
63
|
+
# /usr/local/tracelytics/javaagent.json when under JRuby)
|
64
|
+
cfg = LayerUtil.getLocalSampleRate(nil, nil)
|
65
|
+
|
66
|
+
if cfg.hasSampleStartFlag
|
67
|
+
TraceView::Config.tracing_mode = 'always'
|
68
|
+
elsif cfg.hasSampleThroughFlag
|
69
|
+
TraceView::Config.tracing_mode = 'through'
|
70
|
+
else
|
71
|
+
TraceView::Config.tracing_mode = 'never'
|
72
|
+
end
|
73
|
+
|
74
|
+
TraceView.sample_rate = cfg.getSampleRate
|
75
|
+
TraceView::Config.sample_rate = cfg.sampleRate
|
76
|
+
TraceView::Config.sample_source = cfg.sampleRateSourceValue
|
77
|
+
rescue => e
|
78
|
+
TraceView.logger.debug "[traceview/debug] Couldn't retrieve/acces joboe sampleRateCfg"
|
79
|
+
TraceView.logger.debug "[traceview/debug] #{e.message}"
|
80
|
+
end
|
81
|
+
|
82
|
+
# Only report __Init from here if we are not instrumenting a framework.
|
83
|
+
# Otherwise, frameworks will handle reporting __Init after full initialization
|
84
|
+
unless defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
|
85
|
+
TraceView::API.report_init unless ENV.key?('TRACEVIEW_GEM_TEST')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# clear_all_traces
|
91
|
+
#
|
92
|
+
# Truncates the trace output file to zero
|
93
|
+
#
|
94
|
+
def self.clear_all_traces
|
95
|
+
TraceView.reporter.reset if TraceView.loaded
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# get_all_traces
|
100
|
+
#
|
101
|
+
# Retrieves all traces written to the trace file
|
102
|
+
#
|
103
|
+
def self.get_all_traces
|
104
|
+
return [] unless TraceView.loaded
|
105
|
+
|
106
|
+
# Joboe TestReporter returns a Java::ComTracelyticsExtEbson::DefaultDocument
|
107
|
+
# document for traces which doesn't correctly support things like has_key? which
|
108
|
+
# raises an unhandled exception on non-existent key (duh). Here we convert
|
109
|
+
# the Java::ComTracelyticsExtEbson::DefaultDocument doc to a pure array of Ruby
|
110
|
+
# hashes
|
111
|
+
traces = []
|
112
|
+
TraceView.reporter.getSentEventsAsBsonDocument.to_a.each do |e|
|
113
|
+
t = {}
|
114
|
+
e.each_pair { |k, v|
|
115
|
+
t[k] = v
|
116
|
+
}
|
117
|
+
traces << t
|
118
|
+
end
|
119
|
+
traces
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.sendReport(evt)
|
123
|
+
evt.report(TraceView.reporter)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module TraceView
|
129
|
+
extend TraceViewBase
|
130
|
+
include Oboe_metal
|
131
|
+
|
132
|
+
class << self
|
133
|
+
def sample?(opts = {})
|
134
|
+
begin
|
135
|
+
return false unless TraceView.always? && TraceView.loaded
|
136
|
+
|
137
|
+
return true if ENV.key?('TRACEVIEW_GEM_TEST')
|
138
|
+
|
139
|
+
# Validation to make Joboe happy. Assure that we have the KVs and that they
|
140
|
+
# are not empty strings.
|
141
|
+
opts[:layer] = nil if opts[:layer].is_a?(String) && opts[:layer].empty?
|
142
|
+
opts[:xtrace] = nil if opts[:xtrace].is_a?(String) && opts[:xtrace].empty?
|
143
|
+
opts['X-TV-Meta'] = nil if opts['X-TV-Meta'].is_a?(String) && opts['X-TV-Meta'].empty?
|
144
|
+
|
145
|
+
opts[:layer] ||= nil
|
146
|
+
opts[:xtrace] ||= nil
|
147
|
+
opts['X-TV-Meta'] ||= nil
|
148
|
+
|
149
|
+
sr_cfg = Java::ComTracelyticsJoboe::LayerUtil.shouldTraceRequest(
|
150
|
+
opts[:layer],
|
151
|
+
{ 'X-Trace' => opts[:xtrace], 'X-TV-Meta' => opts['X-TV-Meta'] })
|
152
|
+
|
153
|
+
# Store the returned SampleRateConfig into TraceView::Config
|
154
|
+
if sr_cfg
|
155
|
+
begin
|
156
|
+
TraceView::Config.sample_rate = cfg.sampleRate
|
157
|
+
TraceView::Config.sample_source = cfg.sampleRateSourceValue
|
158
|
+
# If we fail here, we do so quietly. This was we don't spam logs
|
159
|
+
# on every request
|
160
|
+
end
|
161
|
+
else
|
162
|
+
TraceView.sample_rate = -1
|
163
|
+
TraceView.sample_source = -1
|
164
|
+
end
|
165
|
+
|
166
|
+
sr_cfg ? true : false
|
167
|
+
rescue => e
|
168
|
+
TraceView.logger.debug "[traceview/debug] #{e.message}"
|
169
|
+
false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def set_tracing_mode(_mode)
|
174
|
+
TraceView.logger.warn 'When using JRuby set the tracing mode in /usr/local/tracelytics/javaagent.json instead'
|
175
|
+
end
|
176
|
+
|
177
|
+
def set_sample_rate(_rate)
|
178
|
+
# N/A
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Assure that the Joboe Java Agent was loaded via premain
|
184
|
+
case Java::ComTracelyticsAgent::Agent.getStatus
|
185
|
+
when Java::ComTracelyticsAgent::Agent::AgentStatus::INITIALIZED_SUCCESSFUL
|
186
|
+
TraceView.loaded = true
|
187
|
+
|
188
|
+
when Java::ComTracelyticsAgent::Agent::AgentStatus::INITIALIZED_FAILED
|
189
|
+
TraceView.loaded = false
|
190
|
+
$stderr.puts '=============================================================='
|
191
|
+
$stderr.puts 'TraceView Java Agent not initialized properly.'
|
192
|
+
$stderr.puts 'Possibly misconfigured? Going into no-op mode.'
|
193
|
+
$stderr.puts 'See: http://bit.ly/1zwS5xj'
|
194
|
+
$stderr.puts '=============================================================='
|
195
|
+
|
196
|
+
when Java::ComTracelyticsAgent::Agent::AgentStatus::UNINITIALIZED
|
197
|
+
TraceView.loaded = false
|
198
|
+
$stderr.puts '=============================================================='
|
199
|
+
$stderr.puts 'TraceView Java Agent not loaded. Going into no-op mode.'
|
200
|
+
$stderr.puts 'To preload the TraceView java agent see:'
|
201
|
+
$stderr.puts 'https://support.appneta.com/cloud/installing-jruby-instrumentation'
|
202
|
+
$stderr.puts '=============================================================='
|
203
|
+
|
204
|
+
else
|
205
|
+
TraceView.loaded = false
|
206
|
+
end
|
data/lib/oboe/README
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'traceview/thread_local'
|
2
|
+
|
3
|
+
module Oboe
|
4
|
+
extend TraceViewBase
|
5
|
+
include Oboe_metal
|
6
|
+
|
7
|
+
#
|
8
|
+
# Support for Oboe::API calls
|
9
|
+
#
|
10
|
+
module API
|
11
|
+
include TraceView::API
|
12
|
+
extend ::TraceView::ThreadLocal
|
13
|
+
thread_local :deprecation_notified
|
14
|
+
|
15
|
+
def self.method_missing(sym, *args, &blk)
|
16
|
+
# Notify of deprecation only once
|
17
|
+
unless @deprecated_notified
|
18
|
+
TraceView.logger.warn "[traceview/warn] Note that Oboe::API has been renamed to TraceView::API. (#{sym}:#{args})"
|
19
|
+
TraceView.logger.warn "[traceview/warn] Oboe::API will be deprecated in a future version."
|
20
|
+
@deprecated_notified = true
|
21
|
+
end
|
22
|
+
TraceView::API.send(sym, *args, &blk)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
#
|
28
|
+
# Support for Oboe::Config calls
|
29
|
+
#
|
30
|
+
module Config
|
31
|
+
extend ::TraceView::ThreadLocal
|
32
|
+
thread_local :deprecation_notified
|
33
|
+
|
34
|
+
def self.method_missing(sym, *args)
|
35
|
+
# Notify of deprecation only once
|
36
|
+
unless @deprecated_notified
|
37
|
+
TraceView.logger.warn "[traceview/warn] Note that Oboe::Config has been renamed to TraceView::Config. (#{sym}:#{args})"
|
38
|
+
TraceView.logger.warn "[traceview/warn] Oboe::Config will be deprecated in a future version."
|
39
|
+
@deprecated_notified = true
|
40
|
+
end
|
41
|
+
TraceView::Config.send(sym, *args)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
#
|
48
|
+
# Support for OboeMethodProfiling
|
49
|
+
#
|
50
|
+
module OboeMethodProfiling
|
51
|
+
def self.included(klass)
|
52
|
+
klass.extend ClassMethods
|
53
|
+
end
|
54
|
+
|
55
|
+
module ClassMethods
|
56
|
+
include TraceViewMethodProfiling::ClassMethods
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'traceview/inst/rack'
|
2
|
+
|
3
|
+
module Oboe
|
4
|
+
class Rack < TraceView::Rack
|
5
|
+
# This simply makes Oboe::Rack available (and a clone of TraceView::Rack) for
|
6
|
+
# backward compatibility
|
7
|
+
#
|
8
|
+
# Provided for pre-existing apps (sinatra, padrino, grape etc..) that may still
|
9
|
+
# call `use Oboe::Rack`
|
10
|
+
end
|
11
|
+
end
|
data/lib/oboe.rb
ADDED
data/lib/oboe_metal.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
# Copyright (c) 2013 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
# Disable docs and Camelcase warns since we're implementing
|
5
|
+
# an interface here. See OboeBase for details.
|
6
|
+
# rubocop:disable Style/Documentation, Style/MethodName
|
7
|
+
module TraceView
|
8
|
+
extend TraceViewBase
|
9
|
+
include Oboe_metal
|
10
|
+
|
11
|
+
class Reporter
|
12
|
+
##
|
13
|
+
# Initialize the TraceView Context, reporter and report the initialization
|
14
|
+
#
|
15
|
+
def self.start
|
16
|
+
return unless TraceView.loaded
|
17
|
+
|
18
|
+
begin
|
19
|
+
Oboe_metal::Context.init
|
20
|
+
|
21
|
+
if ENV.key?('TRACEVIEW_GEM_TEST')
|
22
|
+
TraceView.reporter = TraceView::FileReporter.new('/tmp/trace_output.bson')
|
23
|
+
else
|
24
|
+
TraceView.reporter = TraceView::UdpReporter.new(TraceView::Config[:reporter_host], TraceView::Config[:reporter_port])
|
25
|
+
end
|
26
|
+
|
27
|
+
# Only report __Init from here if we are not instrumenting a framework.
|
28
|
+
# Otherwise, frameworks will handle reporting __Init after full initialization
|
29
|
+
unless defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
|
30
|
+
TraceView::API.report_init unless ENV.key?('TRACEVIEW_GEM_TEST')
|
31
|
+
end
|
32
|
+
|
33
|
+
rescue => e
|
34
|
+
$stderr.puts e.message
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.sendReport(evt)
|
40
|
+
TraceView.reporter.sendReport(evt)
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# clear_all_traces
|
45
|
+
#
|
46
|
+
# Truncates the trace output file to zero
|
47
|
+
#
|
48
|
+
def self.clear_all_traces
|
49
|
+
File.truncate($trace_file, 0)
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# get_all_traces
|
54
|
+
#
|
55
|
+
# Retrieves all traces written to the trace file
|
56
|
+
#
|
57
|
+
def self.get_all_traces
|
58
|
+
io = File.open($trace_file, 'r')
|
59
|
+
contents = io.readlines(nil)
|
60
|
+
|
61
|
+
return contents if contents.empty?
|
62
|
+
|
63
|
+
s = StringIO.new(contents[0])
|
64
|
+
|
65
|
+
traces = []
|
66
|
+
|
67
|
+
until s.eof?
|
68
|
+
if ::BSON.respond_to? :read_bson_document
|
69
|
+
traces << BSON.read_bson_document(s)
|
70
|
+
else
|
71
|
+
traces << BSON::Document.from_bson(s)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
traces
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Event
|
80
|
+
def self.metadataString(evt)
|
81
|
+
evt.metadataString
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class << self
|
86
|
+
def sample?(opts = {})
|
87
|
+
begin
|
88
|
+
return false unless TraceView.always? && TraceView.loaded
|
89
|
+
|
90
|
+
# Assure defaults since SWIG enforces Strings
|
91
|
+
layer = opts[:layer] ? opts[:layer].strip : ''
|
92
|
+
xtrace = opts[:xtrace] ? opts[:xtrace].strip : ''
|
93
|
+
tv_meta = opts['X-TV-Meta'] ? opts['X-TV-Meta'].strip : ''
|
94
|
+
|
95
|
+
rv = TraceView::Context.sampleRequest(layer, xtrace, tv_meta)
|
96
|
+
|
97
|
+
if rv == 0
|
98
|
+
if ENV.key?('TRACEVIEW_GEM_TEST')
|
99
|
+
# When in test, always trace and don't clear
|
100
|
+
# the stored sample rate/source
|
101
|
+
true
|
102
|
+
else
|
103
|
+
TraceView.sample_rate = -1
|
104
|
+
TraceView.sample_source = -1
|
105
|
+
false
|
106
|
+
end
|
107
|
+
else
|
108
|
+
# liboboe version > 1.3.1 returning a bit masked integer with SampleRate and
|
109
|
+
# source embedded
|
110
|
+
TraceView.sample_rate = (rv & SAMPLE_RATE_MASK)
|
111
|
+
TraceView.sample_source = (rv & SAMPLE_SOURCE_MASK) >> 24
|
112
|
+
true
|
113
|
+
end
|
114
|
+
rescue StandardError => e
|
115
|
+
TraceView.logger.debug "[oboe/error] sample? error: #{e.inspect}"
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def set_tracing_mode(mode)
|
121
|
+
return unless TraceView.loaded
|
122
|
+
|
123
|
+
value = mode.to_sym
|
124
|
+
|
125
|
+
case value
|
126
|
+
when :never
|
127
|
+
TraceView::Context.setTracingMode(OBOE_TRACE_NEVER)
|
128
|
+
|
129
|
+
when :always
|
130
|
+
TraceView::Context.setTracingMode(OBOE_TRACE_ALWAYS)
|
131
|
+
|
132
|
+
when :through
|
133
|
+
TraceView::Context.setTracingMode(OBOE_TRACE_THROUGH)
|
134
|
+
|
135
|
+
else
|
136
|
+
TraceView.logger.fatal "[oboe/error] Invalid tracing mode set: #{mode}"
|
137
|
+
TraceView::Context.setTracingMode(OBOE_TRACE_THROUGH)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def set_sample_rate(rate)
|
142
|
+
return unless TraceView.loaded
|
143
|
+
|
144
|
+
# Update liboboe with the new SampleRate value
|
145
|
+
TraceView::Context.setDefaultSampleRate(rate.to_i)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
# rubocop:enable Style/Documentation
|
150
|
+
|
151
|
+
TraceView.loaded = true
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright (c) 2013 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
module Oboe
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
7
|
+
desc "Copies an oboe initializer files to your application."
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
# Set defaults
|
11
|
+
@tracing_mode = 'through'
|
12
|
+
@sample_rate = '300000'
|
13
|
+
@verbose = 'false'
|
14
|
+
|
15
|
+
print_header
|
16
|
+
|
17
|
+
while true do
|
18
|
+
print_body
|
19
|
+
|
20
|
+
user_tracing_mode = ask shell.set_color "* Tracing Mode? [through]:", :yellow
|
21
|
+
user_tracing_mode.downcase!
|
22
|
+
|
23
|
+
break if user_tracing_mode.blank?
|
24
|
+
valid = ['always', 'through', 'never'].include?(user_tracing_mode)
|
25
|
+
|
26
|
+
say shell.set_color "Valid values are 'always', 'through' or 'never'", :red, :bold unless valid
|
27
|
+
if valid
|
28
|
+
@tracing_mode = user_tracing_mode
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
print_footer
|
34
|
+
|
35
|
+
template "oboe_initializer.rb", "config/initializers/traceview.rb"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def print_header
|
41
|
+
say ""
|
42
|
+
say shell.set_color "Welcome to the TraceView Ruby instrumentation setup.", :green, :bold
|
43
|
+
say ""
|
44
|
+
say "To instrument your Rails application, you can setup your tracing strategy here."
|
45
|
+
say ""
|
46
|
+
say shell.set_color "Documentation Links", :magenta
|
47
|
+
say "-------------------"
|
48
|
+
say ""
|
49
|
+
say "Details on configuring your sample rate:"
|
50
|
+
say "https://support.appneta.com/cloud/configuring-sampling"
|
51
|
+
say ""
|
52
|
+
say "More information on instrumenting Ruby applications can be found here:"
|
53
|
+
say "https://support.appneta.com/cloud/installing-ruby-instrumentation"
|
54
|
+
end
|
55
|
+
|
56
|
+
def print_body
|
57
|
+
say ""
|
58
|
+
say shell.set_color "Tracing Mode", :magenta
|
59
|
+
say "------------"
|
60
|
+
say "Tracing Mode determines when traces should be initiated for incoming requests. Valid"
|
61
|
+
say "options are #{shell.set_color "always", :yellow}, #{shell.set_color "through", :yellow} (when using an instrumented Apache or Nginx) and #{shell.set_color "never", :yellow}."
|
62
|
+
say ""
|
63
|
+
say "If you're not using an instrumented Apache or Nginx, set this directive to #{shell.set_color "always", :yellow} in"
|
64
|
+
say "order to initiate tracing from Ruby."
|
65
|
+
say ""
|
66
|
+
end
|
67
|
+
|
68
|
+
def print_footer
|
69
|
+
say ""
|
70
|
+
say "You can change configuration values in the future by modifying config/initializers/traceview.rb"
|
71
|
+
say ""
|
72
|
+
say "Thanks! Creating the TraceView initializer..."
|
73
|
+
say ""
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|