oboe 2.7.1.7-java → 2.7.2.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) 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 -27
  8. data/lib/oboe/api.rb +4 -0
  9. data/lib/oboe/api/layerinit.rb +9 -6
  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 +50 -15
  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/thread_local.rb +9 -1
  48. data/lib/oboe/util.rb +15 -19
  49. data/lib/oboe/version.rb +5 -2
  50. data/lib/oboe/xtrace.rb +20 -24
  51. data/lib/oboe_metal.rb +16 -13
  52. data/lib/rails/generators/oboe/templates/oboe_initializer.rb +2 -0
  53. data/test/instrumentation/faraday_test.rb +142 -0
  54. data/test/instrumentation/moped_test.rb +2 -0
  55. data/test/minitest_helper.rb +0 -1
  56. data/test/support/config_test.rb +3 -1
  57. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f61d146e29c52fd9cfd7df4b64e37907660c646
4
- data.tar.gz: 6e0643dfdd8202eab11ddf38f0f5ddc36b67d563
3
+ metadata.gz: 44cdd9c6976e59b8300d6360a68f7072be9f965d
4
+ data.tar.gz: 41db567e21e8a0bdb4848c371c04490700d1bb71
5
5
  SHA512:
6
- metadata.gz: f1ee3d5063bae9674ac2083a12a08459aa5103f209d7d7548df53ad5e7edc721b45182fa96483d3ab3e196a6ebb9cd53355d2150b1800fc1194e453a24a61e23
7
- data.tar.gz: ff2ec048ad2c95013644396bf71a3fb3626b737b51c9be8796d5de835e3c07eee6660d0fa8dd1ed9608ae9bc35df10308b62c8faf8e213a1123026a2ffcca6b7
6
+ metadata.gz: 0efc756cc2b47d47eb1b3d4a4d2b285032b3fc0e3836041a7a1b3774ef773960ef672408c0a74a69a73b1fb3cbd3de3a00c8b17ce9744388b7e4753f1db62128
7
+ data.tar.gz: b1c8edfb51062734b1e6a9a6e86e0a3d83442d0ef7db1a17591d3f678b9b00d1fbf9403caf4387a9a15938bcc3b151bac2f68dcf038a7b1436f2b7a750e8f4a3
data/.rubocop.yml ADDED
@@ -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
 
data/lib/joboe_metal.rb CHANGED
@@ -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
-
data/lib/oboe.rb CHANGED
@@ -2,53 +2,55 @@
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
10
 
11
11
  # If OboeHeroku is already defined then we are in a PaaS environment
12
12
  # with an alternate metal (see the oboe-heroku gem)
13
13
  unless defined?(OboeHeroku)
14
- require "oboe/base"
14
+ require 'oboe/base'
15
15
 
16
16
  begin
17
17
  if RUBY_PLATFORM == 'java'
18
- require "/usr/local/tracelytics/tracelyticsagent.jar"
19
- require "joboe_metal"
18
+ require '/usr/local/tracelytics/tracelyticsagent.jar'
19
+ require 'joboe_metal'
20
20
  else
21
- require "oboe_metal.so"
22
- require "oboe_metal"
21
+ require 'oboe_metal.so'
22
+ require 'oboe_metal'
23
23
  end
24
24
  rescue LoadError
25
25
  Oboe.loaded = false
26
26
 
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 "=============================================================="
27
+ unless ENV['RAILS_GROUP'] == 'assets' or ENV['IGNORE_TRACEVIEW_WARNING']
28
+ $stderr.puts '=============================================================='
29
+ $stderr.puts 'Missing TraceView libraries. Tracing disabled.'
30
+ $stderr.puts 'See: http://bit.ly/1DaNOjw'
31
+ $stderr.puts '=============================================================='
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
- require "oboe/config"
36
+ require 'oboe/config'
37
37
 
38
38
  if Oboe.loaded
39
- require "oboe/loading"
40
- require "method_profiling"
41
- require "oboe/instrumentation"
42
- require "oboe/ruby"
39
+ require 'oboe/loading'
40
+ require 'oboe/method_profiling'
41
+ require 'oboe/instrumentation'
43
42
 
44
43
  # 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)
44
+ require 'oboe/frameworks/rails'
45
+ require 'oboe/frameworks/sinatra'
46
+ require 'oboe/frameworks/padrino'
47
+ require 'oboe/frameworks/grape'
49
48
  end
50
- rescue Exception => e
51
- $stderr.puts "[oboe/error] Problem loading: #{e.inspect}"
49
+
50
+ # Load Ruby module last. If there is no framework detected,
51
+ # it will load all of the Ruby instrumentation
52
+ require 'oboe/ruby'
53
+ rescue => e
54
+ $stderr.puts '[oboe/error] Problem loading: #{e.inspect}'
52
55
  $stderr.puts e.backtrace
53
56
  end
54
-
data/lib/oboe/api.rb CHANGED
@@ -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,7 +12,7 @@ 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
@@ -44,8 +46,8 @@ module Oboe
44
46
  platform_info['Ruby.Resque.Version'] = "Resque-#{::Resque::VERSION}" if defined?(::Resque)
45
47
 
46
48
  # 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
+ if ::Gem.loaded_specs.key?('mongo')
50
+ platform_info['Ruby.Mongo.Version'] = "Mongo-#{::Gem.loaded_specs['mongo'].version}"
49
51
  end
50
52
 
51
53
  # Report the server in use (if possible)
@@ -66,7 +68,7 @@ module Oboe
66
68
  elsif defined?(::WEBrick)
67
69
  platform_info['Ruby.AppContainer.Version'] = "WEBrick-#{::WEBrick::VERSION}"
68
70
  else
69
- platform_info['Ruby.AppContainer.Version'] = File.basename($0)
71
+ platform_info['Ruby.AppContainer.Version'] = File.basename($PROGRAM_NAME)
70
72
  end
71
73
 
72
74
  rescue StandardError, ScriptError => e
@@ -79,14 +81,15 @@ module Oboe
79
81
  Oboe.logger.debug e.backtrace
80
82
  end
81
83
 
82
- start_trace(layer, nil, platform_info.merge('Force' => true)) { }
84
+ start_trace(layer, nil, platform_info.merge('Force' => true)) {}
83
85
  end
84
86
 
85
87
  ##
86
88
  # force_trace has been deprecated and will be removed in a subsequent version.
87
89
  #
88
90
  def force_trace
89
- Oboe.logger.warn "Oboe::API::LayerInit.force_trace has been deprecated and will be removed in a subsequent version."
91
+ Oboe.logger.warn 'Oboe::API::LayerInit.force_trace has been deprecated and will be ' \
92
+ 'removed in a subsequent version.'
90
93
 
91
94
  saved_mode = Oboe::Config[:tracing_mode]
92
95
  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