appoptics_apm 4.0.2 → 4.0.3

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/Dockerfile_test +7 -6
  4. data/Rakefile +2 -0
  5. data/docker-compose.yml +22 -0
  6. data/gemfiles/noop.gemfile +17 -0
  7. data/lib/appoptics_apm.rb +2 -2
  8. data/lib/appoptics_apm/api.rb +1 -2
  9. data/lib/appoptics_apm/api/layerinit.rb +3 -1
  10. data/lib/appoptics_apm/api/logging.rb +25 -25
  11. data/lib/appoptics_apm/api/memcache.rb +3 -1
  12. data/lib/appoptics_apm/api/profiling.rb +39 -33
  13. data/lib/appoptics_apm/api/tracing.rb +23 -13
  14. data/lib/appoptics_apm/api/util.rb +1 -1
  15. data/lib/appoptics_apm/base.rb +1 -0
  16. data/lib/appoptics_apm/frameworks/sinatra/templates.rb +1 -1
  17. data/lib/appoptics_apm/inst/rack.rb +135 -111
  18. data/lib/appoptics_apm/instrumentation.rb +1 -1
  19. data/lib/appoptics_apm/version.rb +1 -1
  20. data/test/instrumentation/httpclient_test.rb +4 -20
  21. data/test/instrumentation/mongo_v1_test.rb +1 -1
  22. data/test/instrumentation/rack_test.rb +1 -1
  23. data/test/instrumentation/sequel_mysql2_test.rb +1 -1
  24. data/test/instrumentation/sequel_mysql_test.rb +1 -1
  25. data/test/instrumentation/sequel_pg_test.rb +1 -1
  26. data/test/instrumentation/twitter-cassandra_test.rb +1 -1
  27. data/test/minitest_helper.rb +1 -0
  28. data/test/mocked/curb_mocked_test.rb +14 -1
  29. data/test/mocked/excon_mocked_test.rb +12 -4
  30. data/test/mocked/faraday_mocked_test.rb +5 -1
  31. data/test/mocked/http_mocked_test.rb +6 -0
  32. data/test/mocked/httpclient_mocked_test.rb +14 -1
  33. data/test/mocked/rest_client_mocked_test.rb +7 -1
  34. data/test/mocked/typhoeus_mocked_test.rb +15 -0
  35. data/test/noop/noop_test.rb +145 -0
  36. metadata +5 -4
  37. data/test/support/noop_test.rb +0 -88
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2241f5dc133a92728858f309f3e6170375eb4a8
4
- data.tar.gz: 1f15fd34cdfefc40f301023978e9c45d829da646
3
+ metadata.gz: 14962bf4e9f8b8b81ca0e153a11aea4d14d6e301
4
+ data.tar.gz: 2738dbd25b94e1b2339958ca83ed68e1d9cfd4d3
5
5
  SHA512:
6
- metadata.gz: ed57137d9aeafe9887869d77489e154ab655595e71d2ad0d5a49163f23fb7da76b4719405059eb5ed065fc5a3440f9c4ef9377c1630dd4c6074a640a4c88c131
7
- data.tar.gz: ea25849f7ba00ce4cf66e82322fff7a7d6a015159bd2e7c31182650353abb99f901acaa567a139a0a3a99de0d9ef6053abaec6cdf795b8ca3f440a8f7ad9fa3c
6
+ metadata.gz: b0a701a61d0a71efeb0a046c8c2ed2aa34d0fb73ae7ae9d9cab4c04b60f46bec5a9c99ed10bde6c98a0f2d042742b0c280c7ce51b8786df9903306a0ea2e000a
7
+ data.tar.gz: acc3f8518f0afeb4023ba7d80f0d2168b240189c3321f43a057bb857827d0f82267d121ac41b5b4b5158ea14deda3d546af0996c1007dc6e4ab0d53a2f9ec350
@@ -12,6 +12,7 @@ rvm:
12
12
  # - jruby-9.0.5.0
13
13
 
14
14
  gemfile:
15
+ - gemfiles/noop.gemfile
15
16
  - gemfiles/libraries.gemfile
16
17
  - gemfiles/instrumentation_mocked.gemfile
17
18
  - gemfiles/frameworks.gemfile
@@ -19,6 +19,7 @@ RUN apt-get update \
19
19
  less \
20
20
  tree \
21
21
  psmisc \
22
+ swig \
22
23
  && rm -rf /var/lib/apt/lists/*
23
24
 
24
25
  # rbenv setup
@@ -38,12 +39,12 @@ RUN . ~/.profile \
38
39
  # && rbenv install jruby-9.0.5.0
39
40
 
40
41
  # install swig 3.0.8
41
- RUN curl -SL http://kent.dl.sourceforge.net/project/swig/swig/swig-3.0.8/swig-3.0.8.tar.gz \
42
- | tar xzC /tmp \
43
- && cd /tmp/swig-3.0.8 \
44
- && ./configure && make && make install \
45
- && cd \
46
- && rm -rf /tmp/swig-3.0.8
42
+ #git statuRUN curl -SL http://kent.dl.sourceforge.net/project/swig/swig/swig-3.0.8/swig-3.0.8.tar.gz \
43
+ # | tar xzC /tmp \
44
+ # && cd /tmp/swig-3.0.8 \
45
+ # && ./configure && make && make install \
46
+ # && cd \
47
+ # && rm -rf /tmp/swig-3.0.8
47
48
 
48
49
  # install postgres, redis, and memcached
49
50
  RUN apt-get update \
data/Rakefile CHANGED
@@ -51,6 +51,8 @@ Rake::TestTask.new do |t|
51
51
  when /instrumentation_mocked/
52
52
  # WebMock is interfering with other tests, so these have to run seperately
53
53
  t.test_files = FileList['test/mocked/*_test.rb']
54
+ when /noop/
55
+ t.test_files = FileList['test/noop/*_test.rb']
54
56
  end
55
57
 
56
58
  if defined?(JRUBY_VERSION)
@@ -34,6 +34,28 @@ services:
34
34
  - MYSQL_HOST=mysql
35
35
  - APPOPTICS_MONGO_SERVER=mongo
36
36
 
37
+ ruby_appoptics_apm_alpine:
38
+ container_name: ruby_appoptics_apm_alpine
39
+ image: ruby_alpine
40
+ build:
41
+ context: .
42
+ dockerfile: ./Dockerfile_alpine
43
+ cpu_quota: 100000 # 1 cpu, assumes cpu_period of 1 second
44
+ mem_limit: 1G
45
+ volumes:
46
+ - .:/code/ruby-appoptics_apm
47
+ depends_on:
48
+ - wait
49
+ links:
50
+ - wait
51
+ environment:
52
+ - APPOPTICS_RABBITMQ_SERVER=rabbitmq
53
+ - DOCKER_MYSQL_PASS=admin
54
+ - MYSQL_ALLOW_EMPTY_PASSWORD=yes
55
+ - MYSQL_ROOT_PASSWORD=admin
56
+ - MYSQL_HOST=mysql
57
+ - APPOPTICS_MONGO_SERVER=mongo
58
+
37
59
  rabbitmq:
38
60
  container_name: rabbitmq
39
61
  image: rabbitmq:3-management
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem 'minitest'
5
+ gem 'minitest-reporters', '< 1.0.18'
6
+ gem 'minitest-debugger', :require => false
7
+ gem 'mocha'
8
+ gem 'rack-test'
9
+ gem 'rake'
10
+ gem 'bson', '~> 4.0'
11
+ gem 'puma', '< 3.1.0'
12
+ if RUBY_VERSION >= '2.0.0'
13
+ gem 'webmock'
14
+ end
15
+ end
16
+
17
+ gemspec :path => File.expand_path(File.dirname(__FILE__) + '/../')
@@ -25,8 +25,8 @@ begin
25
25
  require '/usr/local/tracelytics/tracelyticsagent.jar'
26
26
  require 'joboe_metal'
27
27
  elsif RUBY_PLATFORM =~ /linux/
28
- require "oboe_metal.so"
29
- require "oboe_metal.rb" # sets AppOpticsAPM.loaded = true if successful
28
+ require 'oboe_metal.so'
29
+ require 'oboe_metal.rb' # sets AppOpticsAPM.loaded = true if successful
30
30
  else
31
31
  $stderr.puts '==================================================================='
32
32
  $stderr.puts "AppOptics warning: Platform #{RUBY_PLATFORM} not yet supported."
@@ -4,8 +4,7 @@
4
4
  module AppOpticsAPM
5
5
  ##
6
6
  # This module implements the AppOpticsAPM tracing API.
7
- # See: https://github.com/librato/ruby-appoptics#the-tracing-api
8
- # and/or: http://rdoc.info/gems/appoptics_apm/AppOpticsAPM/API/Tracing
7
+ # See: https://docs.appoptics.com/kb/apm_tracing/ruby/sdk/
9
8
  module API
10
9
  def self.extend_with_tracing
11
10
  extend AppOpticsAPM::API::Logging
@@ -7,7 +7,7 @@ module AppOpticsAPM
7
7
  module API
8
8
  ##
9
9
  # Provides methods related to layer initialization and reporting
10
- module LayerInit
10
+ module LayerInit #:nodoc:
11
11
  # Internal: Report that instrumentation for the given layer has been
12
12
  # installed, as well as the version of instrumentation and version of
13
13
  # layer.
@@ -22,6 +22,8 @@ module AppOpticsAPM
22
22
  end
23
23
 
24
24
  ##
25
+ # :nodoc:
26
+ # Deprecated:
25
27
  # force_trace has been deprecated and will be removed in a subsequent version.
26
28
  #
27
29
  def force_trace
@@ -85,7 +85,7 @@ module AppOpticsAPM
85
85
  # Public: Decide whether or not to start a trace, and report an entry event
86
86
  # appropriately.
87
87
  #
88
- # ==== Attributes
88
+ # ==== Arguments
89
89
  #
90
90
  # * +layer+ - The layer the reported event belongs to
91
91
  # * +xtrace+ - An xtrace metadata string, or nil. Used for cross-application tracing.
@@ -95,7 +95,7 @@ module AppOpticsAPM
95
95
  #
96
96
  # AppOpticsAPM::API.log_start(:layer_name, nil, { :id => @user.id })
97
97
  #
98
- # Returns an xtrace metadata string
98
+ # Returns an xtrace metadata string if we are tracing
99
99
  def log_start(layer, xtrace = nil, opts = {})
100
100
  return if !AppOpticsAPM.loaded || (opts.key?(:URL) && ::AppOpticsAPM::Util.static_asset?(opts[:URL]))
101
101
 
@@ -169,7 +169,7 @@ module AppOpticsAPM
169
169
  ##
170
170
  # Public: Report an exit event and potentially clear the tracing context.
171
171
  #
172
- # ==== Attributes
172
+ # ==== Arguments
173
173
  #
174
174
  # * +layer+ - The layer the reported event belongs to
175
175
  # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
@@ -178,14 +178,15 @@ module AppOpticsAPM
178
178
  #
179
179
  # AppOpticsAPM::API.log_end(:layer_name, { :id => @user.id })
180
180
  #
181
- # Returns an xtrace metadata string
181
+ # Returns an xtrace metadata string if we are tracing
182
182
  def log_end(layer, opts = {})
183
183
  return unless AppOpticsAPM.tracing?
184
184
 
185
- log_event(layer, :exit, AppOpticsAPM::Context.createEvent, opts)
185
+ log_event(layer, :exit, AppOpticsAPM::Context.createEvent, opts) if AppOpticsAPM.tracing?
186
186
  AppOpticsAPM::Context.toString
187
187
  ensure
188
- AppOpticsAPM::Context.clear unless AppOpticsAPM.has_incoming_context?
188
+ # FIXME has_incoming_context commented out, it has importance for JRuby only and breaks ruby tests
189
+ AppOpticsAPM::Context.clear # unless AppOpticsAPM.has_incoming_context?
189
190
  end
190
191
 
191
192
  ##
@@ -193,17 +194,17 @@ module AppOpticsAPM
193
194
  #
194
195
  # A helper method to create and log an entry event
195
196
  #
196
- # ==== Attributes
197
+ # ==== Arguments
197
198
  #
198
199
  # * +layer+ - The layer the reported event belongs to
199
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
200
+ # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
200
201
  # * +op+ - To identify the current operation being traced. Used to avoid double tracing recursive calls.
201
202
  #
202
203
  # ==== Example
203
204
  #
204
205
  # AppOpticsAPM::API.log_entry(:layer_name, { :id => @user.id })
205
206
  #
206
- # Returns an xtrace metadata string
207
+ # Returns an xtrace metadata string if we are tracing
207
208
  def log_entry(layer, opts = {}, op = nil)
208
209
  return unless AppOpticsAPM.tracing?
209
210
 
@@ -216,7 +217,7 @@ module AppOpticsAPM
216
217
  #
217
218
  # A helper method to create and log an info event
218
219
  #
219
- # ==== Attributes
220
+ # ==== Arguments
220
221
  #
221
222
  # * +layer+ - The layer the reported event belongs to
222
223
  # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
@@ -225,11 +226,11 @@ module AppOpticsAPM
225
226
  #
226
227
  # AppOpticsAPM::API.log_info(:layer_name, { :id => @user.id })
227
228
  #
228
- # Returns an xtrace metadata string
229
- def log_info(layer, kvs = {})
229
+ # Returns an xtrace metadata string if we are tracing
230
+ def log_info(layer, opts = {})
230
231
  return unless AppOpticsAPM.tracing?
231
232
 
232
- log_event(layer, :info, AppOpticsAPM::Context.createEvent, kvs)
233
+ log_event(layer, :info, AppOpticsAPM::Context.createEvent, opts)
233
234
  end
234
235
 
235
236
  ##
@@ -237,21 +238,22 @@ module AppOpticsAPM
237
238
  #
238
239
  # A helper method to create and log an exit event
239
240
  #
240
- # ==== Attributes
241
+ # ==== Arguments
241
242
  #
242
243
  # * +layer+ - The layer the reported event belongs to
243
- # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
244
- # * +_op+ - deprecated, has been used to avoid double tracing recursive calls, but is irrelevant in +log_exit+
244
+ # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
245
+ # * +op+ - Used to avoid double tracing recursive calls, needs to be true in +log_exit+ that corresponds to a
246
+ # +log_entry+
245
247
  #
246
248
  # ==== Example
247
249
  #
248
250
  # AppOpticsAPM::API.log_exit(:layer_name, { :id => @user.id })
249
251
  #
250
- # Returns an xtrace metadata string (TODO: does it?)
251
- def log_exit(layer, opts = {}, _op = nil)
252
+ # Returns an xtrace metadata string if we are tracing
253
+ def log_exit(layer, opts = {}, op = nil)
252
254
  return unless AppOpticsAPM.tracing?
253
255
 
254
- AppOpticsAPM.layer_op = nil
256
+ AppOpticsAPM.layer_op = nil if op
255
257
  log_event(layer, :exit, AppOpticsAPM::Context.createEvent, opts)
256
258
  end
257
259
 
@@ -262,7 +264,7 @@ module AppOpticsAPM
262
264
  # If we return from a request that faned out multiple requests
263
265
  # we can add the collected X-Traces to the exit event
264
266
  #
265
- # ==== Attributes
267
+ # ==== Arguments
266
268
  #
267
269
  # * +layer+ - The layer the reported event belongs to
268
270
  # * +traces+ - An array with X-Trace strings returned from the requests
@@ -281,15 +283,13 @@ module AppOpticsAPM
281
283
  #:nodoc:
282
284
  # Internal: Reports agent init to the collector
283
285
  #
284
- # ==== Attributes
286
+ # ==== Arguments
285
287
  #
286
288
  # * +layer+ - The layer the reported event belongs to
287
289
  # * +opts+ - A hash containing key/value pairs that will be reported along with this event
288
290
  def log_init(layer = :rack, opts = {})
289
291
  context = AppOpticsAPM::Metadata.makeRandom
290
- if !context.isValid
291
- return
292
- end
292
+ return unless context.isValid
293
293
 
294
294
  event = context.createEvent
295
295
  event.addInfo(APPOPTICS_STR_LAYER, layer.to_s)
@@ -307,7 +307,7 @@ module AppOpticsAPM
307
307
  #:nodoc:
308
308
  # Internal: Report an event.
309
309
  #
310
- # ==== Attributes
310
+ # ==== Arguments
311
311
  #
312
312
  # * +layer+ - The layer the reported event belongs to
313
313
  # * +label+ - The label for the reported event. See API documentation for reserved labels and usage.
@@ -3,11 +3,13 @@
3
3
  # All rights reserved.
4
4
  #++
5
5
 
6
+ # TODO remove Memcache from API and into some Util module to be included in Modules that need
7
+ # ____ these methods
6
8
  module AppOpticsAPM
7
9
  module API
8
10
  ##
9
11
  # Utility methods for the Memcache instrumentation
10
- module Memcache
12
+ module Memcache #:nodoc:
11
13
  MEMCACHE_OPS = %w(add append cas decr decrement delete fetch get incr increment prepend replace set)
12
14
 
13
15
  def memcache_hit?(result)
@@ -6,19 +6,21 @@
6
6
  module AppOpticsAPM
7
7
  module API
8
8
  ##
9
- # Module that provides profiling of arbitrary blocks of code
9
+ # Module to create profiling traces for blocks of code or methods
10
10
  module Profiling
11
11
  ##
12
12
  # Public: Profile a given block of code. Detect any exceptions thrown by
13
13
  # the block and report errors.
14
14
  #
15
- # profile_name - A name used to identify the block being profiled.
16
- # report_kvs - A hash containing key/value pairs that will be reported along
17
- # with the event of this profile (optional).
18
- # with_backtrace - Boolean to indicate whether a backtrace should
19
- # be collected with this trace event.
15
+ # ==== Arguments
20
16
  #
21
- # Example
17
+ # * +profile_name+ - A name used to identify the block being profiled.
18
+ # * +report_kvs+ - A hash containing key/value pairs that will be reported along
19
+ # with the event of this profile (optional).
20
+ # * +with_backtrace+ - Boolean to indicate whether a backtrace should
21
+ # be collected with this trace event.
22
+ #
23
+ # ==== Example
22
24
  #
23
25
  # def computation(n)
24
26
  # AppOpticsAPM::API.profile('fib', { :n => n }) do
@@ -32,40 +34,44 @@ module AppOpticsAPM
32
34
  def profile(profile_name, report_kvs = {}, with_backtrace = false)
33
35
  return yield unless AppOpticsAPM.tracing?
34
36
 
35
- report_kvs[:Language] ||= :ruby
36
- report_kvs[:ProfileName] ||= profile_name
37
- report_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if with_backtrace
38
-
39
- AppOpticsAPM::API.log(nil, :profile_entry, report_kvs)
40
-
41
37
  begin
42
- yield
43
- rescue => e
44
- log_exception(nil, e)
45
- raise
46
- ensure
47
- exit_kvs = {}
48
- exit_kvs[:Language] = :ruby
49
- exit_kvs[:ProfileName] = report_kvs[:ProfileName]
50
-
51
- AppOpticsAPM::API.log(nil, :profile_exit, exit_kvs)
38
+ report_kvs[:Language] ||= :ruby
39
+ report_kvs[:ProfileName] ||= profile_name
40
+ report_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if with_backtrace
41
+
42
+ AppOpticsAPM::API.log(nil, :profile_entry, report_kvs)
43
+
44
+ begin
45
+ yield
46
+ rescue => e
47
+ log_exception(nil, e)
48
+ raise
49
+ ensure
50
+ exit_kvs = {}
51
+ exit_kvs[:Language] = :ruby
52
+ exit_kvs[:ProfileName] = report_kvs[:ProfileName]
53
+
54
+ AppOpticsAPM::API.log(nil, :profile_exit, exit_kvs)
55
+ end
52
56
  end
53
57
  end
54
58
 
55
59
  ##
56
- # Public: Profile a method on a class or module. That method can be of any (accessible)
60
+ # Public: Add profiling to a method on a class or module. That method can be of any (accessible)
57
61
  # type (instance, singleton, private, protected etc.).
58
62
  #
59
- # klass - the class or module that has the method to profile
60
- # method - the method to profile. Can be singleton, instance, private etc...
61
- # opts - a hash specifying the one or more of the following options:
62
- # * :arguments - report the arguments passed to <tt>method</tt> on each profile (default: false)
63
- # * :result - report the return value of <tt>method</tt> on each profile (default: false)
64
- # * :backtrace - report the return value of <tt>method</tt> on each profile (default: false)
65
- # * :name - alternate name for the profile reported in the dashboard (default: method name)
66
- # extra_kvs - a hash containing any additional KVs you would like reported with the profile
63
+ # ==== Arguments
64
+ #
65
+ # * +klass+ - the class or module that has the method to profile
66
+ # * +method+ - the method to profile. Can be singleton, instance, private etc...
67
+ # * +opts+ - a hash specifying the one or more of the following options:
68
+ # * +:arguments+ - report the arguments passed to <tt>method</tt> on each profile (default: false)
69
+ # * +:result+ - report the return value of <tt>method</tt> on each profile (default: false)
70
+ # * +:backtrace+ - report the return value of <tt>method</tt> on each profile (default: false)
71
+ # * +:name+ - alternate name for the profile reported in the dashboard (default: method name)
72
+ # * +extra_kvs+ - a hash containing any additional key/value pairs you would like reported with the profile
67
73
  #
68
- # Example
74
+ # ==== Example
69
75
  #
70
76
  # opts = {}
71
77
  # opts[:backtrace] = true
@@ -20,6 +20,8 @@ module AppOpticsAPM
20
20
  # * +:URL+ - request URI
21
21
  # * +:Method+
22
22
  #
23
+ # TODO complete the above
24
+ #
23
25
  # Invalid keys: +:Label+, +:Layer+, +:Edge+, +:Timestamp+, +:Timestamp_u+
24
26
  #
25
27
  module Tracing
@@ -56,7 +58,7 @@ module AppOpticsAPM
56
58
  log_exception(layer, e)
57
59
  raise
58
60
  ensure
59
- log_exit(layer)
61
+ log_exit(layer, opts, protect_op)
60
62
  end
61
63
  end
62
64
 
@@ -67,17 +69,20 @@ module AppOpticsAPM
67
69
  # When start_trace returns control to the calling context, the oboe
68
70
  # context will be cleared.
69
71
  #
70
- # layer - The layer the block of code belongs to.
71
- # opts - A hash containing key/value pairs that will be reported along
72
- # with the first event of this layer (optional).
72
+ # ==== Arguments
73
73
  #
74
- # Example
74
+ # * +layer+ - name for the layer to be used as label in the trace view
75
+ # * +xtrace+ - (optional) incoming X-Trace identifier to be continued
76
+ # * +opts+ - (optional) hash containing key/value pairs that will be reported along
77
+ # with the first event of this layer (optional)
78
+ #
79
+ # ==== Example
75
80
  #
76
81
  # def handle_request(request, response)
77
82
  # # ... code that modifies request and response ...
78
83
  # end
79
84
  #
80
- # def handle_request_with_oboe(request, response)
85
+ # def handle_request_with_appoptics(request, response)
81
86
  # result, xtrace = start_trace('rails', request['X-Trace']) do
82
87
  # handle_request(request, response)
83
88
  # end
@@ -92,6 +97,8 @@ module AppOpticsAPM
92
97
  # of the block, and the second element of which is the oboe context that
93
98
  # was set when the block completed execution.
94
99
  def start_trace(layer, xtrace = nil, opts = {})
100
+ return [yield, nil] unless AppOpticsAPM.loaded
101
+
95
102
  log_start(layer, xtrace, opts)
96
103
  begin
97
104
  result = yield
@@ -113,19 +120,20 @@ module AppOpticsAPM
113
120
  # access to the exit event's trace id so we can set the header before any
114
121
  # work is done, and before any headers are sent back to the client.
115
122
  #
116
- # layer - The layer the block of code belongs to.
117
- # xtrace - string - The X-Trace to continue by the target
118
- # target - has to respond to #[]=, The target object in which to place the trace information
119
- # opts - A hash containing key/value pairs that will be reported along
120
- # with the first event of this layer (optional).
123
+ # ===== Arguments
124
+ # * +layer+ - The layer the block of code belongs to.
125
+ # * +xtrace+ - string - The X-Trace to continue by the target
126
+ # * +target+ - has to respond to #[]=, The target object in which to place the trace information
127
+ # * +opts+ - A hash containing key/value pairs that will be reported along
128
+ # with the first event of this layer (optional).
121
129
  #
122
- # Example:
130
+ # ==== Example
123
131
  #
124
132
  # def handle_request(request, response)
125
133
  # # ... code that does something with request and response ...
126
134
  # end
127
135
  #
128
- # def handle_request_with_oboe(request, response)
136
+ # def handle_request_with_appoptics(request, response)
129
137
  # start_trace_with_target('rails', request['X-Trace'], response) do
130
138
  # handle_request(request, response)
131
139
  # end
@@ -133,6 +141,8 @@ module AppOpticsAPM
133
141
  #
134
142
  # Returns the result of the block.
135
143
  def start_trace_with_target(layer, xtrace, target, opts = {})
144
+ return yield unless AppOpticsAPM.loaded
145
+
136
146
  log_start(layer, xtrace, opts)
137
147
  exit_evt = AppOpticsAPM::Context.createEvent
138
148
  begin