oboe 2.7.1.7 → 2.7.2.fuchs1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Gemfile +2 -0
  4. data/README.md +3 -3
  5. data/ext/oboe_metal/extconf.rb +11 -11
  6. data/lib/joboe_metal.rb +36 -42
  7. data/lib/oboe.rb +29 -26
  8. data/lib/oboe/api.rb +4 -0
  9. data/lib/oboe/api/layerinit.rb +7 -67
  10. data/lib/oboe/api/logging.rb +50 -28
  11. data/lib/oboe/api/memcache.rb +7 -5
  12. data/lib/oboe/api/profiling.rb +4 -4
  13. data/lib/oboe/api/tracing.rb +6 -5
  14. data/lib/oboe/api/util.rb +13 -9
  15. data/lib/oboe/base.rb +55 -16
  16. data/lib/oboe/config.rb +17 -15
  17. data/lib/oboe/frameworks/padrino.rb +0 -2
  18. data/lib/oboe/frameworks/padrino/templates.rb +5 -6
  19. data/lib/oboe/frameworks/rails.rb +0 -1
  20. data/lib/oboe/frameworks/rails/inst/action_controller.rb +4 -5
  21. data/lib/oboe/frameworks/rails/inst/action_view.rb +4 -4
  22. data/lib/oboe/frameworks/rails/inst/action_view_2x.rb +4 -4
  23. data/lib/oboe/frameworks/rails/inst/action_view_30.rb +2 -2
  24. data/lib/oboe/frameworks/rails/inst/active_record.rb +5 -5
  25. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql.rb +6 -6
  26. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql2.rb +3 -3
  27. data/lib/oboe/frameworks/rails/inst/connection_adapters/oracle.rb +1 -1
  28. data/lib/oboe/frameworks/rails/inst/connection_adapters/postgresql.rb +3 -3
  29. data/lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb +18 -19
  30. data/lib/oboe/frameworks/sinatra.rb +4 -5
  31. data/lib/oboe/inst/cassandra.rb +17 -19
  32. data/lib/oboe/inst/dalli.rb +5 -5
  33. data/lib/oboe/inst/em-http-request.rb +13 -13
  34. data/lib/oboe/inst/faraday.rb +71 -0
  35. data/lib/oboe/inst/http.rb +4 -4
  36. data/lib/oboe/inst/memcache.rb +7 -10
  37. data/lib/oboe/inst/memcached.rb +7 -9
  38. data/lib/oboe/inst/mongo.rb +26 -28
  39. data/lib/oboe/inst/moped.rb +23 -24
  40. data/lib/oboe/inst/rack.rb +10 -11
  41. data/lib/oboe/inst/redis.rb +18 -20
  42. data/lib/oboe/inst/resque.rb +8 -9
  43. data/lib/oboe/instrumentation.rb +3 -0
  44. data/lib/oboe/loading.rb +19 -23
  45. data/lib/{method_profiling.rb → oboe/method_profiling.rb} +22 -8
  46. data/lib/oboe/ruby.rb +23 -3
  47. data/lib/oboe/support.rb +94 -0
  48. data/lib/oboe/thread_local.rb +9 -1
  49. data/lib/oboe/util.rb +90 -18
  50. data/lib/oboe/version.rb +5 -2
  51. data/lib/oboe/xtrace.rb +20 -24
  52. data/lib/oboe_metal.rb +16 -13
  53. data/lib/rails/generators/oboe/templates/oboe_initializer.rb +2 -0
  54. data/test/instrumentation/faraday_test.rb +142 -0
  55. data/test/instrumentation/moped_test.rb +2 -0
  56. data/test/minitest_helper.rb +0 -1
  57. data/test/support/config_test.rb +3 -1
  58. metadata +10 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84f206d306c5aa4c271b644a255d9b672f063df4
4
- data.tar.gz: 159394da1767c2226db490c54c899432b2eb19ee
3
+ metadata.gz: d5ac648bc577d1085f678b6f15864b666f6352f0
4
+ data.tar.gz: 15a6f20155dd56778d08eb2795f18611ea3ec734
5
5
  SHA512:
6
- metadata.gz: ecf5b2f14ebceb8a9edc926740c03b4366a92dd4743e39bcf0083e0f5b110107bd67b2d87a1236bbff21f84c623c97c8ecd9d28303a99f1b95943fecd93dd644
7
- data.tar.gz: b6894f7301c31a2b2391664b76951a20e74fb8d23c06ea02c2127e709875e292c3beb10a09fcbff26894b19a0b02a2f669451db79a884b1f2bb704f8f05c2dcd
6
+ metadata.gz: 82f42deca27a316294712784c69cd55da27f762594b830524a24ef42ab8c6deecc5b624cc57453ba778f78f0f51f21fdc4e2d8c821c71370647cb492d11dd863
7
+ data.tar.gz: 15f6ba38ea81f86cdbf1bc61ccb98fe1fc8bc2e79360749c3bc818ed6ad52092078f9fe01aceeaee3a6c5cf19f6e5bd9504da49dfc823a28c520a54deaf24ebf
@@ -0,0 +1,5 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/HashSyntax:
5
+ EnforcedStyle: hash_rockets
data/Gemfile CHANGED
@@ -26,6 +26,8 @@ gem 'cassandra'
26
26
  gem 'mongo'
27
27
  gem 'resque'
28
28
  gem 'redis'
29
+ gem 'faraday'
30
+ gem 'excon'
29
31
 
30
32
  if RUBY_VERSION >= '1.9'
31
33
  gem 'moped'
data/README.md CHANGED
@@ -123,7 +123,7 @@ You must explicitly tell your Grape application to use Oboe::Rack for tracing to
123
123
 
124
124
  ## Custom Ruby Scripts & Applications
125
125
 
126
- The oboe gem has the ability to instrument any arbitrary Ruby application or script as long as the gem is initialized with the manual methods:
126
+ The oboe gem has the ability to instrument any arbitrary Ruby application or script. Only the `tracing_mode` needs to be set to tell the oboe gem to initiate performance metric collection.
127
127
 
128
128
  ```ruby
129
129
  require 'rubygems'
@@ -135,12 +135,12 @@ require 'oboe'
135
135
 
136
136
  # Tracing mode can be 'never', 'through' (to follow upstream) or 'always'
137
137
  Oboe::Config[:tracing_mode] = 'always'
138
-
139
- Oboe::Ruby.initialize
140
138
  ```
141
139
 
142
140
  From here, you can use the Tracing API to instrument areas of code using `Oboe::API.start_trace` (see below). If you prefer to instead dive directly into code, take a look at [this example](https://gist.github.com/pglombardo/8550713) of an instrumented Ruby script.
143
141
 
142
+ Once inside of the `Oboe::API.start_trace` block, performance metrics will be automatically collected for all supported libraries and gems (Redis, Mongo, ActiveRecord etc..).
143
+
144
144
  ## Other
145
145
 
146
146
  You can send deploy notifications to TraceView and have the events show up on your dashboard. See: [Capistrano Deploy Notifications with tlog](https://support.appneta.com/cloud/capistrano-deploy-notifications-tlog)
@@ -7,7 +7,7 @@ require 'rbconfig'
7
7
  # Check if we're running in JRuby
8
8
  jruby = defined?(JRUBY_VERSION) ? true : false
9
9
 
10
- openshift = ENV.has_key?('OPENSHIFT_TRACEVIEW_DIR')
10
+ openshift = ENV.key?('OPENSHIFT_TRACEVIEW_DIR')
11
11
 
12
12
  # When on OpenShift, set the mkmf lib paths so we have no issues linking to
13
13
  # the TraceView libs.
@@ -23,7 +23,7 @@ else
23
23
  dir_config('oboe')
24
24
  end
25
25
 
26
- if jruby or ENV.has_key?('TRACEVIEW_URL')
26
+ if jruby || ENV.key?('TRACEVIEW_URL')
27
27
  # Build the noop extension under JRuby and Heroku.
28
28
  # The oboe-heroku gem builds it's own c extension which links to
29
29
  # libs specific to a Heroku dyno
@@ -32,30 +32,30 @@ if jruby or ENV.has_key?('TRACEVIEW_URL')
32
32
 
33
33
  elsif have_library('oboe', 'oboe_config_get_revision', 'oboe/oboe.h')
34
34
 
35
- $libs = append_library($libs, "oboe")
36
- $libs = append_library($libs, "stdc++")
35
+ $libs = append_library($libs, 'oboe')
36
+ $libs = append_library($libs, 'stdc++')
37
37
 
38
- $CFLAGS << " #{ENV["CFLAGS"]}"
39
- $CPPFLAGS << " #{ENV["CPPFLAGS"]}"
40
- $LIBS << " #{ENV["LIBS"]}"
38
+ $CFLAGS << " #{ENV['CFLAGS']}"
39
+ $CPPFLAGS << " #{ENV['CPPFLAGS']}"
40
+ $LIBS << " #{ENV['LIBS']}"
41
41
 
42
42
  # On OpenShift user rpath to point out the TraceView libraries
43
43
  if openshift
44
- $LDFLAGS << " #{ENV["LDFLAGS"]} -Wl,-rpath=#{tv_lib64},--rpath=#{tv_tlyzer}"
44
+ $LDFLAGS << " #{ENV['LDFLAGS']} -Wl,-rpath=#{tv_lib64},--rpath=#{tv_tlyzer}"
45
45
  end
46
46
 
47
47
  if RUBY_VERSION < '1.9'
48
48
  cpp_command('g++')
49
- $CPPFLAGS << "-I./src/"
49
+ $CPPFLAGS << '-I./src/'
50
50
  end
51
51
  create_makefile('oboe_metal', 'src')
52
52
 
53
53
  else
54
54
  if have_library('oboe')
55
- $stderr.puts "Error: The oboe gem requires an updated liboboe. Please update your liboboe packages."
55
+ $stderr.puts 'Error: The oboe gem requires an updated liboboe. Please update your liboboe packages.'
56
56
  end
57
57
 
58
- $stderr.puts "Error: Could not find the base liboboe libraries. No tracing will occur."
58
+ $stderr.puts 'Error: Could not find the base liboboe libraries. No tracing will occur.'
59
59
  create_makefile('oboe_noop', 'noop')
60
60
  end
61
61
 
@@ -48,42 +48,36 @@ module Oboe_metal
48
48
  # Initialize the Oboe Context, reporter and report the initialization
49
49
  #
50
50
  def self.start
51
- begin
52
- return unless Oboe.loaded
53
-
54
- if ENV.has_key?("OBOE_GEM_TEST")
55
- Oboe.reporter = Java::ComTracelyticsJoboe::TestReporter.new
56
- else
57
- Oboe.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance().buildUdpReporter()
58
- end
51
+ return unless Oboe.loaded
59
52
 
53
+ if ENV.key?('OBOE_GEM_TEST')
54
+ Oboe.reporter = Java::ComTracelyticsJoboe::TestReporter.new
55
+ else
56
+ Oboe.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance.buildUdpReporter
57
+ end
60
58
 
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
59
 
66
- if cfg.hasSampleStartFlag
67
- Oboe::Config.tracing_mode = 'always'
68
- elsif cfg.hasSampleThroughFlag
69
- Oboe::Config.tracing_mode = 'through'
70
- else
71
- Oboe::Config.tracing_mode = 'never'
72
- end
60
+ # Import the tracing mode and sample rate settings
61
+ # from the Java agent (user configured in
62
+ # /usr/local/tracelytics/javaagent.json when under JRuby)
63
+ cfg = LayerUtil.getLocalSampleRate(nil, nil)
73
64
 
74
- Oboe.sample_rate = cfg.sampleRate
75
- Oboe::Config.sample_rate = cfg.sampleRate
76
- Oboe::Config.sample_source = cfg.sampleRateSource.a
65
+ if cfg.hasSampleStartFlag
66
+ Oboe::Config.tracing_mode = 'always'
67
+ elsif cfg.hasSampleThroughFlag
68
+ Oboe::Config.tracing_mode = 'through'
69
+ else
70
+ Oboe::Config.tracing_mode = 'never'
71
+ end
77
72
 
78
- # Only report __Init from here if we are not instrumenting a framework.
79
- # Otherwise, frameworks will handle reporting __Init after full initialization
80
- unless defined?(::Rails) or defined?(::Sinatra) or defined?(::Padrino) or defined?(::Grape)
81
- Oboe::API.report_init
82
- end
73
+ Oboe.sample_rate = cfg.sampleRate
74
+ Oboe::Config.sample_rate = cfg.sampleRate
75
+ Oboe::Config.sample_source = cfg.sampleRateSource.a
83
76
 
84
- rescue Exception => e
85
- $stderr.puts e.message
86
- raise
77
+ # Only report __Init from here if we are not instrumenting a framework.
78
+ # Otherwise, frameworks will handle reporting __Init after full initialization
79
+ unless defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
80
+ Oboe::API.report_init
87
81
  end
88
82
  end
89
83
 
@@ -112,7 +106,7 @@ module Oboe_metal
112
106
  traces = []
113
107
  Oboe.reporter.getSentEventsAsBsonDocument.to_a.each do |e|
114
108
  t = {}
115
- e.each_pair { |k,v|
109
+ e.each_pair { |k, v|
116
110
  t[k] = v
117
111
  }
118
112
  traces << t
@@ -133,22 +127,23 @@ module Oboe
133
127
  class << self
134
128
  def sample?(opts = {})
135
129
  begin
136
- return false unless Oboe.always? and Oboe.loaded
130
+ return false unless Oboe.always? && Oboe.loaded
137
131
 
138
- return true if ENV['OBOE_GEM_TEST'] == "test"
132
+ return true if ENV.key?('OBOE_GEM_TEST')
139
133
 
140
134
  # Validation to make Joboe happy. Assure that we have the KVs and that they
141
135
  # are not empty strings.
142
- opts[:layer] = nil if opts[:layer].is_a?(String) and opts[:layer].empty?
143
- opts[:xtrace] = nil if opts[:xtrace].is_a?(String) and opts[:xtrace].empty?
144
- opts['X-TV-Meta'] = nil if opts['X-TV-Meta'].is_a?(String) and opts['X-TV-Meta'].empty?
136
+ opts[:layer] = nil if opts[:layer].is_a?(String) && opts[:layer].empty?
137
+ opts[:xtrace] = nil if opts[:xtrace].is_a?(String) && opts[:xtrace].empty?
138
+ opts['X-TV-Meta'] = nil if opts['X-TV-Meta'].is_a?(String) && opts['X-TV-Meta'].empty?
145
139
 
146
140
  opts[:layer] ||= nil
147
141
  opts[:xtrace] ||= nil
148
142
  opts['X-TV-Meta'] ||= nil
149
143
 
150
- sr_cfg = Java::ComTracelyticsJoboe::LayerUtil.shouldTraceRequest( opts[:layer],
151
- { 'X-Trace' => opts[:xtrace], 'X-TV-Meta' => opts['X-TV-Meta'] } )
144
+ sr_cfg = Java::ComTracelyticsJoboe::LayerUtil.shouldTraceRequest(
145
+ opts[:layer],
146
+ { 'X-Trace' => opts[:xtrace], 'X-TV-Meta' => opts['X-TV-Meta'] })
152
147
 
153
148
  # Store the returned SampleRateConfig into Oboe::Config
154
149
  if sr_cfg
@@ -163,11 +158,11 @@ module Oboe
163
158
  end
164
159
  end
165
160
 
166
- def set_tracing_mode(mode)
167
- Oboe.logger.warn "When using JRuby set the tracing mode in /usr/local/tracelytics/javaagent.json instead"
161
+ def set_tracing_mode(_mode)
162
+ Oboe.logger.warn 'When using JRuby set the tracing mode in /usr/local/tracelytics/javaagent.json instead'
168
163
  end
169
164
 
170
- def set_sample_rate(rate)
165
+ def set_sample_rate(_rate)
171
166
  # N/A
172
167
  end
173
168
  end
@@ -180,4 +175,3 @@ if status == Java::ComTracelyticsAgent::Agent::AgentStatus::UNINITIALIZED
180
175
  else
181
176
  Oboe.loaded = true
182
177
  end
183
-
@@ -2,53 +2,56 @@
2
2
  # All rights reserved.
3
3
 
4
4
  begin
5
- require "oboe/version"
6
- require "oboe/thread_local"
7
- require "oboe/logger"
8
- require "oboe/util"
9
- require "oboe/xtrace"
5
+ require 'oboe/version'
6
+ require 'oboe/thread_local'
7
+ require 'oboe/logger'
8
+ require 'oboe/util'
9
+ require 'oboe/xtrace'
10
+ require 'oboe/support'
10
11
 
11
12
  # If OboeHeroku is already defined then we are in a PaaS environment
12
13
  # with an alternate metal (see the oboe-heroku gem)
13
14
  unless defined?(OboeHeroku)
14
- require "oboe/base"
15
+ require 'oboe/base'
15
16
 
16
17
  begin
17
18
  if RUBY_PLATFORM == 'java'
18
- require "/usr/local/tracelytics/tracelyticsagent.jar"
19
- require "joboe_metal"
19
+ require '/usr/local/tracelytics/tracelyticsagent.jar'
20
+ require 'joboe_metal'
20
21
  else
21
- require "oboe_metal.so"
22
- require "oboe_metal"
22
+ require 'oboe_metal.so'
23
+ require 'oboe_metal'
23
24
  end
24
25
  rescue LoadError
25
26
  Oboe.loaded = false
26
27
 
27
- unless ENV['RAILS_GROUP'] == 'assets'
28
- $stderr.puts "=============================================================="
29
- $stderr.puts "Missing TraceView libraries. Tracing disabled."
30
- $stderr.puts "See: https://support.tv.appneta.com/solution/articles/137973"
31
- $stderr.puts "=============================================================="
28
+ unless ENV['RAILS_GROUP'] == 'assets' or ENV['IGNORE_TRACEVIEW_WARNING']
29
+ $stderr.puts '=============================================================='
30
+ $stderr.puts 'Missing TraceView libraries. Tracing disabled.'
31
+ $stderr.puts 'See: http://bit.ly/1DaNOjw'
32
+ $stderr.puts '=============================================================='
32
33
  end
33
34
  end
34
35
  end
35
36
 
36
- require "oboe/config"
37
+ require 'oboe/config'
37
38
 
38
39
  if Oboe.loaded
39
- require "oboe/loading"
40
- require "method_profiling"
41
- require "oboe/instrumentation"
42
- require "oboe/ruby"
40
+ require 'oboe/loading'
41
+ require 'oboe/method_profiling'
42
+ require 'oboe/instrumentation'
43
43
 
44
44
  # Frameworks
45
- require "oboe/frameworks/rails" if defined?(::Rails)
46
- require "oboe/frameworks/sinatra" if defined?(::Sinatra)
47
- require "oboe/frameworks/padrino" if defined?(::Padrino)
48
- require "oboe/frameworks/grape" if defined?(::Grape)
45
+ require 'oboe/frameworks/rails'
46
+ require 'oboe/frameworks/sinatra'
47
+ require 'oboe/frameworks/padrino'
48
+ require 'oboe/frameworks/grape'
49
49
  end
50
- rescue Exception => e
50
+
51
+ # Load Ruby module last. If there is no framework detected,
52
+ # it will load all of the Ruby instrumentation
53
+ require 'oboe/ruby'
54
+ rescue => e
51
55
  $stderr.puts "[oboe/error] Problem loading: #{e.inspect}"
52
56
  $stderr.puts e.backtrace
53
57
  end
54
-
@@ -2,6 +2,10 @@
2
2
  # All rights reserved.
3
3
 
4
4
  module Oboe
5
+ ##
6
+ # This module implements the TraceView tracing API.
7
+ # See: https://github.com/appneta/oboe-ruby#the-tracing-api
8
+ # and/or: http://rdoc.info/gems/oboe/Oboe/API/Tracing
5
9
  module API
6
10
  def self.extend_with_tracing
7
11
  extend Oboe::API::Logging
@@ -3,6 +3,8 @@
3
3
 
4
4
  module Oboe
5
5
  module API
6
+ ##
7
+ # Provides methods related to layer initialization and reporting
6
8
  module LayerInit
7
9
  # Internal: Report that instrumentation for the given layer has been
8
10
  # installed, as well as the version of instrumentation and version of
@@ -10,83 +12,21 @@ module Oboe
10
12
  #
11
13
  def report_init(layer = 'rack')
12
14
  # Don't send __Init in development or test
13
- return if ["development", "test"].include? ENV['RACK_ENV']
15
+ return if %w(development test).include? ENV['RACK_ENV']
14
16
 
15
17
  # Don't send __Init if the c-extension hasn't loaded
16
18
  return unless Oboe.loaded
17
19
 
18
- platform_info = { '__Init' => 1 }
19
-
20
- begin
21
- platform_info['Force'] = true
22
- platform_info['Ruby.Platform.Version'] = RUBY_PLATFORM
23
- platform_info['Ruby.Version'] = RUBY_VERSION
24
- platform_info['Ruby.Oboe.Version'] = ::Oboe::Version::STRING
25
- platform_info['RubyHeroku.Oboe.Version'] = ::OboeHeroku::Version::STRING if defined?(::OboeHeroku)
26
-
27
- # Report the framework in use
28
- platform_info['Ruby.Rails.Version'] = "Rails-#{::Rails.version}" if defined?(::Rails)
29
- platform_info['Ruby.Grape.Version'] = "Grape-#{::Grape::VERSION}" if defined?(::Grape)
30
- platform_info['Ruby.Cramp.Version'] = "Cramp-#{::Cramp::VERSION}" if defined?(::Cramp)
31
-
32
- if defined?(::Padrino)
33
- platform_info['Ruby.Padrino.Version'] = "Padrino-#{::Padrino::VERSION}"
34
- elsif defined?(::Sinatra)
35
- platform_info['Ruby.Sinatra.Version'] = "Sinatra-#{::Sinatra::VERSION}"
36
- end
37
-
38
- # Report the instrumented libraries
39
- platform_info['Ruby.Cassandra.Version'] = "Cassandra-#{::Cassandra.VERSION}" if defined?(::Cassandra)
40
- platform_info['Ruby.Dalli.Version'] = "Dalli-#{::Dalli::VERSION}" if defined?(::Dalli)
41
- platform_info['Ruby.MemCache.Version'] = "MemCache-#{::MemCache::VERSION}" if defined?(::MemCache)
42
- platform_info['Ruby.Moped.Version'] = "Moped-#{::Moped::VERSION}" if defined?(::Moped)
43
- platform_info['Ruby.Redis.Version'] = "Redis-#{::Redis::VERSION}" if defined?(::Redis)
44
- platform_info['Ruby.Resque.Version'] = "Resque-#{::Resque::VERSION}" if defined?(::Resque)
45
-
46
- # Special case since the Mongo 1.x driver doesn't embed the version number in the gem directly
47
- if ::Gem.loaded_specs.has_key?('mongo')
48
- platform_info['Ruby.Mongo.Version'] = "Mongo-#{::Gem.loaded_specs['mongo'].version.to_s}"
49
- end
50
-
51
- # Report the server in use (if possible)
52
- if defined?(::Unicorn)
53
- platform_info['Ruby.AppContainer.Version'] = "Unicorn-#{::Unicorn::Const::UNICORN_VERSION}"
54
- elsif defined?(::Puma)
55
- platform_info['Ruby.AppContainer.Version'] = "Puma-#{::Puma::Const::PUMA_VERSION} (#{::Puma::Const::CODE_NAME})"
56
- elsif defined?(::PhusionPassenger)
57
- platform_info['Ruby.AppContainer.Version'] = "#{::PhusionPassenger::PACKAGE_NAME}-#{::PhusionPassenger::VERSION_STRING}"
58
- elsif defined?(::Thin)
59
- platform_info['Ruby.AppContainer.Version'] = "Thin-#{::Thin::VERSION::STRING} (#{::Thin::VERSION::CODENAME})"
60
- elsif defined?(::Mongrel)
61
- platform_info['Ruby.AppContainer.Version'] = "Mongrel-#{::Mongrel::Const::MONGREL_VERSION}"
62
- elsif defined?(::Mongrel2)
63
- platform_info['Ruby.AppContainer.Version'] = "Mongrel2-#{::Mongrel2::VERSION}"
64
- elsif defined?(::Trinidad)
65
- platform_info['Ruby.AppContainer.Version'] = "Trinidad-#{::Trinidad::VERSION}"
66
- elsif defined?(::WEBrick)
67
- platform_info['Ruby.AppContainer.Version'] = "WEBrick-#{::WEBrick::VERSION}"
68
- else
69
- platform_info['Ruby.AppContainer.Version'] = File.basename($0)
70
- end
71
-
72
- rescue StandardError, ScriptError => e
73
- # Also rescue ScriptError (aka SyntaxError) in case one of the expected
74
- # version defines don't exist
75
-
76
- platform_info['Error'] = "Error in layerinit: #{e.message}"
77
-
78
- Oboe.logger.debug "Error in layerinit: #{e.message}"
79
- Oboe.logger.debug e.backtrace
80
- end
81
-
82
- start_trace(layer, nil, platform_info.merge('Force' => true)) { }
20
+ platform_info = Oboe::Util.build_report
21
+ start_trace(layer, nil, platform_info.merge('Force' => true)) {}
83
22
  end
84
23
 
85
24
  ##
86
25
  # force_trace has been deprecated and will be removed in a subsequent version.
87
26
  #
88
27
  def force_trace
89
- Oboe.logger.warn "Oboe::API::LayerInit.force_trace has been deprecated and will be removed in a subsequent version."
28
+ Oboe.logger.warn 'Oboe::API::LayerInit.force_trace has been deprecated and will be ' \
29
+ 'removed in a subsequent version.'
90
30
 
91
31
  saved_mode = Oboe::Config[:tracing_mode]
92
32
  Oboe::Config[:tracing_mode] = 'always'
@@ -3,8 +3,9 @@
3
3
 
4
4
  module Oboe
5
5
  module API
6
+ ##
7
+ # This modules provides the X-Trace logging facilities.
6
8
  module Logging
7
-
8
9
  # Public: Report an event in an active trace.
9
10
  #
10
11
  # layer - The layer the reported event belongs to
@@ -20,7 +21,7 @@ module Oboe
20
21
  # log('logical_layer', 'exit')
21
22
  #
22
23
  # Returns nothing.
23
- def log(layer, label, opts={})
24
+ def log(layer, label, opts = {})
24
25
  log_event(layer, label, Oboe::Context.createEvent, opts)
25
26
  end
26
27
 
@@ -40,14 +41,14 @@ module Oboe
40
41
  #
41
42
  # Returns nothing.
42
43
  def log_exception(layer, exn)
43
- unless exn.instance_variable_get(:@oboe_logged)
44
- log(layer, 'error', {
45
- :ErrorClass => exn.class.name,
46
- :Message => exn.message,
47
- :Backtrace => exn.backtrace.join("\r\n")
48
- })
49
- exn.instance_variable_set(:@oboe_logged, true)
50
- end
44
+ return if exn.instance_variable_get(:@oboe_logged)
45
+
46
+ kvs = { :ErrorClass => exn.class.name,
47
+ :Message => exn.message,
48
+ :Backtrace => exn.backtrace.join("\r\n") }
49
+
50
+ exn.instance_variable_set(:@oboe_logged, true)
51
+ log(layer, 'error', kvs)
51
52
  end
52
53
 
53
54
  # Public: Decide whether or not to start a trace, and report an event
@@ -59,16 +60,14 @@ module Oboe
59
60
  # with this event (optional).
60
61
  #
61
62
  # Returns nothing.
62
- def log_start(layer, xtrace, opts={})
63
- return if Oboe.never? or (opts.has_key?(:URL) and ::Oboe::Util.static_asset?(opts[:URL]))
63
+ def log_start(layer, xtrace, opts = {})
64
+ return if Oboe.never? || (opts.key?(:URL) && ::Oboe::Util.static_asset?(opts[:URL]))
64
65
 
65
- if xtrace and not xtrace.to_s.empty?
66
- Oboe::Context.fromString(xtrace)
67
- end
66
+ Oboe::Context.fromString(xtrace) if xtrace && !xtrace.to_s.empty?
68
67
 
69
68
  if Oboe.tracing?
70
69
  log_entry(layer, opts)
71
- elsif opts.has_key?('Force') or Oboe.sample?(opts.merge(:layer => layer, :xtrace => xtrace))
70
+ elsif opts.key?('Force') || Oboe.sample?(opts.merge(:layer => layer, :xtrace => xtrace))
72
71
  log_event(layer, 'entry', Oboe::Context.startTrace, opts)
73
72
  end
74
73
  end
@@ -78,21 +77,46 @@ module Oboe
78
77
  # layer - The layer the reported event belongs to
79
78
  #
80
79
  # Returns an xtrace metadata string
81
- def log_end(layer, opts={})
80
+ def log_end(layer, opts = {})
82
81
  log_event(layer, 'exit', Oboe::Context.createEvent, opts)
83
82
  xtrace = Oboe::Context.toString
84
83
  Oboe::Context.clear
85
84
  xtrace
86
85
  end
87
86
 
88
- def log_entry(layer, opts={}, protect_op=nil)
89
- Oboe.layer_op = protect_op if protect_op
90
- log_event(layer, 'entry', Oboe::Context.createEvent, opts)
87
+ ##
88
+ # Public: Log an entry event
89
+ #
90
+ # A helper method to create and log an
91
+ # entry event
92
+ #
93
+ # Returns an xtrace metadata string
94
+ def log_entry(layer, kvs = {}, op = nil)
95
+ Oboe.layer_op = op if op
96
+ log_event(layer, 'entry', Oboe::Context.createEvent, kvs)
91
97
  end
92
98
 
93
- def log_exit(layer, opts={}, protect_op=nil)
94
- Oboe.layer_op = nil if protect_op
95
- log_event(layer, 'exit', Oboe::Context.createEvent, opts)
99
+ ##
100
+ # Public: Log an info event
101
+ #
102
+ # A helper method to create and log an
103
+ # info event
104
+ #
105
+ # Returns an xtrace metadata string
106
+ def log_info(layer, kvs = {})
107
+ log_event(layer, 'info', Oboe::Context.createEvent, kvs)
108
+ end
109
+
110
+ ##
111
+ # Public: Log an exit event
112
+ #
113
+ # A helper method to create and log an
114
+ # exit event
115
+ #
116
+ # Returns an xtrace metadata string
117
+ def log_exit(layer, kvs = {}, op = nil)
118
+ Oboe.layer_op = nil if op
119
+ log_event(layer, 'exit', Oboe::Context.createEvent, kvs)
96
120
  end
97
121
 
98
122
  # Internal: Report an event.
@@ -112,15 +136,13 @@ module Oboe
112
136
  # log_event('rails', 'exit', exit)
113
137
  #
114
138
  # Returns nothing.
115
- def log_event(layer, label, event, opts={})
116
- if layer
117
- event.addInfo('Layer', layer.to_s)
118
- end
139
+ def log_event(layer, label, event, opts = {})
140
+ event.addInfo('Layer', layer.to_s) if layer
119
141
  event.addInfo('Label', label.to_s)
120
142
 
121
143
  opts.each do |k, v|
122
144
  event.addInfo(k.to_s, v.to_s) if valid_key? k
123
- end if !opts.nil? and opts.any?
145
+ end if !opts.nil? && opts.any?
124
146
 
125
147
  Oboe::Reporter.sendReport(event) if Oboe.loaded
126
148
  end