appoptics_apm 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -0
  3. data/.travis.yml +15 -12
  4. data/Gemfile +0 -1
  5. data/README.md +7 -38
  6. data/Rakefile +17 -1
  7. data/appoptics_apm.gemspec +2 -0
  8. data/{build_gems.sh → build_gem.sh} +1 -1
  9. data/build_gem_upload_to_packagecloud.sh +15 -0
  10. data/examples/SDK/01_basic_tracing.rb +1 -1
  11. data/ext/oboe_metal/src/VERSION +1 -1
  12. data/ext/oboe_metal/src/bson/bson.h +1 -2
  13. data/ext/oboe_metal/src/bson/platform_hacks.h +4 -4
  14. data/lib/appoptics_apm.rb +28 -30
  15. data/lib/appoptics_apm/api/logging.rb +13 -27
  16. data/lib/appoptics_apm/api/metrics.rb +25 -11
  17. data/lib/appoptics_apm/api/profiling.rb +6 -11
  18. data/lib/appoptics_apm/api/tracing.rb +3 -24
  19. data/lib/appoptics_apm/base.rb +7 -32
  20. data/lib/appoptics_apm/config.rb +26 -4
  21. data/lib/appoptics_apm/frameworks/grape.rb +10 -8
  22. data/lib/appoptics_apm/frameworks/padrino.rb +3 -0
  23. data/lib/appoptics_apm/frameworks/rails.rb +20 -42
  24. data/lib/appoptics_apm/frameworks/rails/inst/action_controller.rb +4 -6
  25. data/lib/appoptics_apm/frameworks/rails/inst/action_controller4.rb +1 -1
  26. data/lib/appoptics_apm/frameworks/rails/inst/action_controller5.rb +1 -1
  27. data/lib/appoptics_apm/frameworks/rails/inst/action_controller_api.rb +1 -1
  28. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +1 -9
  29. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +1 -1
  30. data/lib/appoptics_apm/frameworks/sinatra.rb +4 -1
  31. data/lib/appoptics_apm/inst/bunny-client.rb +16 -18
  32. data/lib/appoptics_apm/inst/memcached.rb +6 -10
  33. data/lib/appoptics_apm/inst/moped.rb +1 -1
  34. data/lib/appoptics_apm/inst/rack.rb +13 -15
  35. data/lib/appoptics_apm/inst/sidekiq-worker.rb +1 -1
  36. data/lib/appoptics_apm/inst/typhoeus.rb +4 -2
  37. data/lib/appoptics_apm/loading.rb +1 -1
  38. data/lib/appoptics_apm/sdk.rb +48 -50
  39. data/lib/appoptics_apm/version.rb +1 -1
  40. data/lib/appoptics_apm/xtrace.rb +1 -1
  41. data/lib/oboe_metal.rb +13 -11
  42. data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +45 -7
  43. metadata +5 -16
  44. data/.codeclimate.yml +0 -43
  45. data/Dockerfile +0 -41
  46. data/Dockerfile_alpine +0 -66
  47. data/Dockerfile_test +0 -73
  48. data/config/initializers/.keep +0 -0
  49. data/docker-compose.yml +0 -95
  50. data/ext/oboe_metal/tests/test.rb +0 -11
  51. data/lib/appoptics_apm/frameworks/rails/inst/action_controller2.rb +0 -61
  52. data/lib/appoptics_apm/frameworks/rails/inst/action_view_2x.rb +0 -56
  53. data/ruby_setup.sh +0 -49
  54. data/run_docker_build_gem_upload_to_packagecloud.sh +0 -20
  55. data/run_tests_docker.rb +0 -38
@@ -53,10 +53,6 @@ module AppOpticsAPM
53
53
  name == 'ActiveRecord::SchemaMigration Load'
54
54
  end
55
55
 
56
- # def cfg
57
- # @config
58
- # end
59
-
60
56
  def execute_with_appoptics(sql, name = nil)
61
57
  if AppOpticsAPM.tracing? && !ignore_payload?(name)
62
58
 
@@ -118,11 +114,7 @@ module AppOpticsAPM
118
114
  end
119
115
 
120
116
  def begin_db_transaction_with_appoptics
121
- if AppOpticsAPM.tracing?
122
- AppOpticsAPM::API.trace('activerecord', { :Query => 'BEGIN', :Flavor => :mysql }, :ar_started) do
123
- begin_db_transaction_without_appoptics
124
- end
125
- else
117
+ AppOpticsAPM::API.trace('activerecord', { :Query => 'BEGIN', :Flavor => :mysql }, :ar_started) do
126
118
  begin_db_transaction_without_appoptics
127
119
  end
128
120
  end
@@ -61,7 +61,7 @@ module AppOpticsAPM
61
61
  end
62
62
 
63
63
  def exec_query_with_appoptics(sql, name = nil, binds = [], prepare: false)
64
- if AppOpticsAPM.tracing? && AppOpticsAPM.layer_op != :ar_started && !ignore_payload?(name)
64
+ if AppOpticsAPM.tracing? && !AppOpticsAPM.tracing_layer_op?(:ar_started) && !ignore_payload?(name)
65
65
 
66
66
  opts = extract_trace_details(sql, name, binds)
67
67
  AppOpticsAPM::API.trace('activerecord', opts) do
@@ -23,12 +23,15 @@ module AppOpticsAPM
23
23
  env['appoptics_apm.action'] = report_kvs[:Action]
24
24
 
25
25
  response
26
+ rescue => e
27
+ ::AppOpticsAPM::API.log_exception('sinatra', e)
28
+ raise e
26
29
  ensure
27
30
  ::AppOpticsAPM::API.log_exit('sinatra', report_kvs)
28
31
  end
29
32
 
30
33
  def handle_exception_with_appoptics(boom)
31
- AppOpticsAPM::API.log_exception(nil, boom)
34
+ AppOpticsAPM::API.log_exception(:sinatra, boom)
32
35
  handle_exception_without_appoptics(boom)
33
36
  end
34
37
 
@@ -32,7 +32,7 @@ module AppOpticsAPM
32
32
 
33
33
  delete_without_appoptics(opts)
34
34
  rescue => e
35
- AppOpticsAPM::API.log_exception(nil, e)
35
+ AppOpticsAPM::API.log_exception(:'rabbitmq-client', e)
36
36
  raise e
37
37
  ensure
38
38
  AppOpticsAPM::API.log_exit(:'rabbitmq-client', kvs)
@@ -48,20 +48,18 @@ module AppOpticsAPM
48
48
  end
49
49
 
50
50
  def collect_channel_kvs
51
- begin
52
- kvs = {}
53
- kvs[:Spec] = :pushq
54
- kvs[:Flavor] = :rabbitmq
55
- kvs[:RemoteHost] = @connection.host
56
- kvs[:RemotePort] = @connection.port.to_i
57
- kvs[:VirtualHost] = @connection.vhost
58
- kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:bunnyclient][:collect_backtraces]
59
- kvs
60
- rescue => e
61
- AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if AppOpticsAPM::Config[:verbose]
62
- ensure
63
- return kvs
64
- end
51
+ kvs = {}
52
+ kvs[:Spec] = :pushq
53
+ kvs[:Flavor] = :rabbitmq
54
+ kvs[:RemoteHost] = @connection.host
55
+ kvs[:RemotePort] = @connection.port.to_i
56
+ kvs[:VirtualHost] = @connection.vhost
57
+ kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:bunnyclient][:collect_backtraces]
58
+ kvs
59
+ rescue => e
60
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if AppOpticsAPM::Config[:verbose]
61
+ ensure
62
+ return kvs
65
63
  end
66
64
 
67
65
  def basic_publish_with_appoptics(payload, exchange, routing_key, opts = {})
@@ -91,7 +89,7 @@ module AppOpticsAPM
91
89
 
92
90
  basic_publish_without_appoptics(payload, exchange, routing_key, opts)
93
91
  rescue => e
94
- AppOpticsAPM::API.log_exception(nil, e)
92
+ AppOpticsAPM::API.log_exception(:'rabbitmq-client', e)
95
93
  raise e
96
94
  ensure
97
95
  AppOpticsAPM::API.log_exit(:'rabbitmq-client', kvs)
@@ -112,7 +110,7 @@ module AppOpticsAPM
112
110
  kvs[:Queue] = result.name
113
111
  result
114
112
  rescue => e
115
- AppOpticsAPM::API.log_exception(nil, e)
113
+ AppOpticsAPM::API.log_exception(:'rabbitmq-client', e)
116
114
  raise e
117
115
  ensure
118
116
  AppOpticsAPM::API.log_exit(:'rabbitmq-client', kvs)
@@ -131,7 +129,7 @@ module AppOpticsAPM
131
129
 
132
130
  wait_for_confirms_without_appoptics
133
131
  rescue => e
134
- AppOpticsAPM::API.log_exception(nil, e)
132
+ AppOpticsAPM::API.log_exception(:'rabbitmq-client', e)
135
133
  raise e
136
134
  ensure
137
135
  AppOpticsAPM::API.log_exit(:'rabbitmq-client', kvs)
@@ -58,19 +58,15 @@ module AppOpticsAPM
58
58
  layer_kvs[:KVOp] = :get_multi
59
59
 
60
60
  AppOpticsAPM::API.trace(:memcache, layer_kvs || {}, :get_multi) do
61
- begin
62
- info_kvs = {}
63
- info_kvs[:KVKeyCount] = keys.flatten.length
61
+ info_kvs = {}
62
+ info_kvs[:KVKeyCount] = keys.flatten.length
64
63
 
65
- values = get_multi_without_appoptics(keys, raw)
64
+ values = get_multi_without_appoptics(keys, raw)
66
65
 
67
- info_kvs[:KVHitCount] = values.length
68
- info_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:memcached][:collect_backtraces]
66
+ info_kvs[:KVHitCount] = values.length
67
+ info_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:memcached][:collect_backtraces]
69
68
 
70
- AppOpticsAPM::API.log(:memcache, :info, info_kvs)
71
- rescue
72
- values = get_multi_without_appoptics(keys, raw)
73
- end
69
+ AppOpticsAPM::API.log(:memcache, :info, info_kvs)
74
70
  values
75
71
  end
76
72
  else
@@ -256,7 +256,7 @@ module AppOpticsAPM
256
256
  end
257
257
 
258
258
  def update_with_appoptics(change, flags = nil)
259
- if AppOpticsAPM.tracing? && !AppOpticsAPM.tracing_layer_op?([:update_all, :upsert])
259
+ if AppOpticsAPM.tracing? && !AppOpticsAPM.tracing_layer_op?(:update_all) && !AppOpticsAPM.tracing_layer_op?(:upsert)
260
260
  begin
261
261
  report_kvs = extract_trace_details(:update)
262
262
  report_kvs[:Flags] = flags.to_s if flags
@@ -137,11 +137,9 @@ if AppOpticsAPM.loaded
137
137
  confirmed_transaction_name = send_metrics(env, req, req_url, start, status)
138
138
  xtrace = AppOpticsAPM::API.log_end(:rack, :Status => status, :TransactionName => confirmed_transaction_name)
139
139
 
140
- if headers && AppOpticsAPM::XTrace.valid?(xtrace)
141
- # TODO revisit this JRUBY condition
142
- # headers['X-Trace'] = xtrace if headers.is_a?(Hash) unless defined?(JRUBY_VERSION) && AppOpticsAPM.is_continued_trace?
143
- headers['X-Trace'] = xtrace if headers.is_a?(Hash) unless defined?(JRUBY_VERSION) && AppOpticsAPM.is_continued_trace?
144
- end
140
+ # TODO revisit this JRUBY condition
141
+ # headers['X-Trace'] = xtrace if headers.is_a?(Hash) unless defined?(JRUBY_VERSION) && AppOpticsAPM.is_continued_trace?
142
+ headers['X-Trace'] = xtrace if headers.is_a?(Hash)
145
143
 
146
144
  [status, headers, response]
147
145
  rescue Exception => e
@@ -150,11 +148,9 @@ if AppOpticsAPM.loaded
150
148
  confirmed_transaction_name ||= send_metrics(env, req, req_url, start, status)
151
149
  xtrace = AppOpticsAPM::API.log_end(:rack, :Status => status, :TransactionName => confirmed_transaction_name)
152
150
 
153
- if headers && AppOpticsAPM::XTrace.valid?(xtrace)
154
- # TODO revisit this JRUBY condition
155
- # headers['X-Trace'] = xtrace if headers.is_a?(Hash) unless defined?(JRUBY_VERSION) && AppOpticsAPM.is_continued_trace?
156
- headers['X-Trace'] = xtrace if headers.is_a?(Hash) unless defined?(JRUBY_VERSION) && AppOpticsAPM.is_continued_trace?
157
- end
151
+ # TODO revisit this JRUBY condition
152
+ # headers['X-Trace'] = xtrace if headers.is_a?(Hash) unless defined?(JRUBY_VERSION) && AppOpticsAPM.is_continued_trace?
153
+ headers['X-Trace'] = xtrace if headers.is_a?(Hash)
158
154
 
159
155
  raise
160
156
  end
@@ -163,14 +159,16 @@ if AppOpticsAPM.loaded
163
159
  def send_metrics(env, req, req_url, start, status)
164
160
  return if ::AppOpticsAPM::Util.static_asset?(env['PATH_INFO'])
165
161
 
166
- domain = nil
167
- if AppOpticsAPM::Config['transaction_name']['prepend_domain']
168
- domain = [80, 443].include?(req.port) ? req.host : "#{req.host}:#{req.port}"
169
- end
170
162
  status = status.to_i
171
163
  error = status.between?(500,599) ? 1 : 0
172
164
  duration =(1000 * 1000 * (Time.now - start)).round(0)
173
- AppOpticsAPM::Span.createHttpSpan(transaction_name(env), req_url, domain, duration, status, req.request_method, error) || ''
165
+ AppOpticsAPM::Span.createHttpSpan(transaction_name(env), req_url, domain(req), duration, status, req.request_method, error) || ''
166
+ end
167
+
168
+ def domain(req)
169
+ if AppOpticsAPM::Config['transaction_name']['prepend_domain']
170
+ [80, 443].include?(req.port) ? req.host : "#{req.host}:#{req.port}"
171
+ end
174
172
  end
175
173
 
176
174
  def transaction_name(env)
@@ -8,7 +8,7 @@ module AppOpticsAPM
8
8
  # Attempt to collect up pertinent info. If we hit something unexpected,
9
9
  # keep calm and instrument on.
10
10
  report_kvs = {}
11
- worker, msg, queue = args
11
+ _worker, msg, queue = args
12
12
 
13
13
  # Background Job Spec KVs
14
14
  report_kvs[:Spec] = :job
@@ -1,5 +1,6 @@
1
1
  # Copyright (c) 2016 SolarWinds, LLC.
2
2
  # All rights reserved.
3
+ class TyphoeusError < StandardError; end
3
4
 
4
5
  module AppOpticsAPM
5
6
  module Inst
@@ -27,8 +28,9 @@ module AppOpticsAPM
27
28
  response = run_without_appoptics
28
29
 
29
30
  if response.code == 0
30
- AppOpticsAPM::API.log(:typhoeus, :error, { :ErrorClass => response.return_code,
31
- :ErrorMsg => response.return_message })
31
+ exception = TyphoeusError.new(response.return_message)
32
+ exception.set_backtrace(AppOpticsAPM::API.backtrace) if AppOpticsAPM::Config[:typhoeus][:collect_backtraces]
33
+ AppOpticsAPM::API.log_exception(:typhoeus, exception)
32
34
  end
33
35
 
34
36
  kvs = {}
@@ -58,7 +58,7 @@ end
58
58
 
59
59
  AppOpticsAPM::Loading.require_api
60
60
 
61
- # Auto-start the Reporter unless we running Unicorn on Heroku
61
+ # Auto-start the Reporter unless we are running Unicorn on Heroku
62
62
  # In that case, we start the reporters after fork
63
63
  unless AppOpticsAPM.heroku? && AppOpticsAPM.forking_webserver?
64
64
  AppOpticsAPM::Reporter.start if AppOpticsAPM.loaded
@@ -13,14 +13,15 @@ module AppOpticsAPM
13
13
  # broken traces in case of exceptions.
14
14
  #
15
15
  # Some optional keys that can be used in the +opts+ hash:
16
- # * +:TransactionName+ - this will show up in the transactions column in the traces dashboard
17
- # * +:Controller+ - if present will be combined with +Action+ and show up as transaction in the traces dashboard
18
- # * +:Action+ - if present will be combined with +Controller+ and show up as transaction in the traces dashboard
19
- # * +:HTTP-Host+ - domain portion of URL
20
- # * +:URL+ - request URI
16
+ # * +:Controller+
17
+ # * +:Action+
18
+ # * +:HTTP-Host+
19
+ # * +:URL+
21
20
  # * +:Method+
22
21
  #
23
- # Invalid keys: +:Label+, +:Layer+, +:Edge+, +:Timestamp+, +:Timestamp_u+
22
+ # as well as custom keys. The information will show up in the raw data view of a span.
23
+ #
24
+ # Invalid keys: +:Label+, +:Layer+, +:Edge+, +:Timestamp+, +:Timestamp_u+, +:TransactionName+ (allowed in start_trace)
24
25
  #
25
26
  # The methods are exposed as singleton methods for AppOpticsAPM::SDK.
26
27
  #
@@ -29,7 +30,7 @@ module AppOpticsAPM
29
30
  # * +AppOpticsAPM::SDK.get_transaction_name+
30
31
  # * +AppOpticsAPM::SDK.set_transaction_name+
31
32
  # * +AppOpticsAPM::SDK.start_trace+
32
- # * +AppOpticsAPM::SDK.start_trace_sith_target+
33
+ # * +AppOpticsAPM::SDK.start_trace_with_target+
33
34
  # * +AppOpticsAPM::SDK.trace+
34
35
  # * +AppOpticsAPM::SDK.tracing?+
35
36
  #
@@ -74,14 +75,10 @@ module AppOpticsAPM
74
75
  #
75
76
  # === Example:
76
77
  #
77
- # def computation(n)
78
- # fib(n)
79
- # raise Exception.new
80
- # end
81
- #
82
78
  # def computation_with_appoptics(n)
83
- # trace('fib', { :number => n }, :fib) do
84
- # computation(n)
79
+ # AppOpticsAPM::SDK.trace('computation', { :number => n }, :computation) do
80
+ # return n if n == 0
81
+ # n + computation_with_appoptics(n-1)
85
82
  # end
86
83
  # end
87
84
  #
@@ -91,7 +88,10 @@ module AppOpticsAPM
91
88
  # * The result of the block.
92
89
  #
93
90
  def trace(span, opts = {}, protect_op = nil)
94
- return yield if !AppOpticsAPM.loaded || !AppOpticsAPM.tracing? || (protect_op && AppOpticsAPM.layer_op == protect_op.to_sym)
91
+ return yield if !AppOpticsAPM.loaded || !AppOpticsAPM.tracing? || AppOpticsAPM.tracing_layer_op?(protect_op)
92
+
93
+ opts.delete(:TransactionName)
94
+ opts.delete('TransactionName')
95
95
 
96
96
  AppOpticsAPM::API.log_entry(span, opts, protect_op)
97
97
  begin
@@ -118,6 +118,7 @@ module AppOpticsAPM
118
118
  # * +span+ - Name for the span to be used as label in the trace view.
119
119
  # * +xtrace+ - (optional) incoming X-Trace identifier to be continued.
120
120
  # * +opts+ - (optional) hash containing key/value pairs that will be reported with this span.
121
+ # The value of :TransactionName will set the transaction_name.
121
122
  #
122
123
  # === Example:
123
124
  #
@@ -135,28 +136,7 @@ module AppOpticsAPM
135
136
  # * The result of the block.
136
137
  #
137
138
  def start_trace(span, xtrace = nil, opts = {})
138
- return yield unless AppOpticsAPM.loaded
139
-
140
- # in case it is not an entry span!
141
- return trace(span, opts) { yield } if AppOpticsAPM::Context.isValid
142
-
143
- AppOpticsAPM::API.log_start(span, xtrace, opts)
144
-
145
- # send_metrics deals with the logic for setting AppOpticsAPM.transaction_name
146
- # and ensures that metrics are sent
147
- # log_end includes sending the transaction_name
148
- result = AppOpticsAPM::API.send_metrics(span, opts) do
149
- begin
150
- yield
151
- rescue Exception => e # rescue everything ok, since we are raising
152
- AppOpticsAPM::API.log_exception(span, e)
153
- e.instance_variable_set(:@xtrace, AppOpticsAPM::API.log_end(span))
154
- raise
155
- end
156
- end
157
- AppOpticsAPM::API.log_end(span)
158
-
159
- result
139
+ start_trace_with_target(span, xtrace, {}, opts) { yield }
160
140
  end
161
141
 
162
142
  # Collect metrics, trace a given block of code, and assign trace info to target.
@@ -198,20 +178,30 @@ module AppOpticsAPM
198
178
  return result
199
179
  end
200
180
 
181
+ # :TransactionName and 'TransactionName' need to be removed from opts
182
+ # :TransactionName should only be sent after it is set by send_metrics
183
+ transaction_name = opts.delete('TransactionName')
184
+ transaction_name = opts.delete(:TransactionName) || transaction_name
185
+ # This is the beginning of a transaction, therefore AppOpticsAPM.transaction_name
186
+ # needs to be set to nil or whatever is provided in the opts
187
+ AppOpticsAPM.transaction_name = transaction_name
188
+
189
+
201
190
  AppOpticsAPM::API.log_start(span, xtrace, opts)
202
191
  exit_evt = AppOpticsAPM::Context.createEvent
203
- result = AppOpticsAPM::API.send_metrics(span, opts) do
204
- begin
205
- target['X-Trace'] = AppOpticsAPM::EventUtil.metadataString(exit_evt) if AppOpticsAPM.tracing?
192
+ result = begin
193
+ AppOpticsAPM::API.send_metrics(span, opts) do
194
+ target['X-Trace'] = AppOpticsAPM::EventUtil.metadataString(exit_evt)
206
195
  yield
207
- rescue Exception => e
208
- AppOpticsAPM::API.log_exception(span, e)
209
- exit_evt.addEdge(AppOpticsAPM::Context.get)
210
- xtrace = AppOpticsAPM::API.log_end(span, opts, exit_evt)
211
- e.instance_variable_set(:@xtrace, xtrace)
212
- raise
213
196
  end
197
+ rescue Exception => e
198
+ AppOpticsAPM::API.log_exception(span, e)
199
+ exit_evt.addEdge(AppOpticsAPM::Context.get)
200
+ xtrace = AppOpticsAPM::API.log_end(span, opts, exit_evt)
201
+ e.instance_variable_set(:@xtrace, xtrace)
202
+ raise
214
203
  end
204
+
215
205
  exit_evt.addEdge(AppOpticsAPM::Context.get)
216
206
  AppOpticsAPM::API.log_end(span, opts, exit_evt)
217
207
 
@@ -229,7 +219,8 @@ module AppOpticsAPM
229
219
  # argument won't change the current transaction name.
230
220
  #
231
221
  # The configuration +AppOpticsAPM.Config+['transaction_name']+['prepend_domain']+ can be set to
232
- # true to have the domain name prepended to the transaction name. This is a global setting.
222
+ # true to have the domain name prepended to the transaction name when an event or a metric are
223
+ # logged. This is a global setting.
233
224
  #
234
225
  # === Argument:
235
226
  #
@@ -268,7 +259,7 @@ module AppOpticsAPM
268
259
  # This is provided for testing
269
260
  #
270
261
  # === Returns:
271
- # * (String or nil) the current transaction name
262
+ # * (String or nil) the current transaction name (without domain prepended)
272
263
  #
273
264
  def get_transaction_name
274
265
  AppOpticsAPM.transaction_name
@@ -277,7 +268,7 @@ module AppOpticsAPM
277
268
  # Determine if this transaction is being traced.
278
269
  #
279
270
  # Tracing puts some extra load on a system, therefor not all transaction are traced.
280
- # The `tracing?` method helps to determine this so that extra work can be avoided when not tracing.
271
+ # The +tracing?+ method helps to determine this so that extra work can be avoided when not tracing.
281
272
  #
282
273
  # === Example:
283
274
  #
@@ -308,7 +299,14 @@ module AppOpticsAPM
308
299
  # end
309
300
  #
310
301
  def appoptics_ready?(wait_milliseconds = 3000)
311
- AppopticsAPM::Context.isReady(wait_milliseconds)
302
+ # These codes are returned by isReady:
303
+ # OBOE_SERVER_RESPONSE_UNKNOWN 0
304
+ # OBOE_SERVER_RESPONSE_OK 1
305
+ # OBOE_SERVER_RESPONSE_TRY_LATER 2
306
+ # OBOE_SERVER_RESPONSE_LIMIT_EXCEEDED 3
307
+ # OBOE_SERVER_RESPONSE_INVALID_API_KEY 4
308
+ # OBOE_SERVER_RESPONSE_CONNECT_ERROR 5
309
+ AppopticsAPM::Context.isReady(wait_milliseconds) == 1
312
310
  end
313
311
  end
314
312
 
@@ -8,7 +8,7 @@ module AppOpticsAPM
8
8
  module Version
9
9
  MAJOR = 4
10
10
  MINOR = 2
11
- PATCH = 3
11
+ PATCH = 4
12
12
 
13
13
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
14
14
  end
@@ -30,7 +30,7 @@ module AppOpticsAPM
30
30
  end
31
31
 
32
32
  def sampled?(xtrace)
33
- xtrace[59].to_i & 1 == 1
33
+ valid?(xtrace) && xtrace[59].to_i & 1 == 1
34
34
  end
35
35
 
36
36
  def set_sampled(xtrace)
@@ -21,25 +21,27 @@ module AppOpticsAPM
21
21
  return unless AppOpticsAPM.loaded
22
22
 
23
23
  begin
24
- protocol = ENV.key?('APPOPTICS_GEM_TEST') ? 'file' :
25
- ENV['TRACELYTICS_REPORTER'] || 'ssl'
24
+ options = []
26
25
 
27
- case protocol
26
+ ENV['APPOPTICS_REPORTER'] = 'file' if ENV.key?('APPOPTICS_GEM_TEST')
27
+
28
+ case ENV['APPOPTICS_REPORTER']
28
29
  when 'file'
29
- options = "file=#{TRACE_FILE}"
30
+ ENV['APPOPTICS_REPORTER_FILE'] = TRACE_FILE
30
31
  when 'udp'
31
- options = "addr=#{AppOpticsAPM::Config[:reporter_host]},port=#{AppOpticsAPM::Config[:reporter_port]}"
32
- else
33
- if ENV['APPOPTICS_SERVICE_KEY'].to_s == ''
32
+ ENV['APPOPTICS_REPORTER_UDP'] = "#{AppOpticsAPM::Config[:reporter_host]}:#{AppOpticsAPM::Config[:reporter_port]}"
33
+ else # default is ssl, service_key is mandatory
34
+ if AppOpticsAPM::Config[:service_key].to_s == '' && ENV['APPOPTICS_SERVICE_KEY'].to_s == ''
34
35
  AppOpticsAPM.logger.warn "[appoptics_apm/warn] APPOPTICS_SERVICE_KEY not set. Cannot submit data."
35
36
  AppOpticsAPM.loaded = false
36
37
  return
37
38
  end
38
- # ssl reporter requires the service key passed in as arg "cid"
39
- options = "cid=#{ENV['APPOPTICS_SERVICE_KEY']}"
39
+ # Oboe will override these settings if there are env settings for them
40
+ options << AppOpticsAPM::Config[:service_key].to_s
41
+ options << AppOpticsAPM::Config[:hostname_alias].to_s
42
+ options << AppOpticsAPM::Config[:debug_level] unless AppOpticsAPM::Config[:debug_level].nil?
40
43
  end
41
-
42
- AppOpticsAPM.reporter = Oboe_metal::Reporter.new(protocol, options)
44
+ AppOpticsAPM.reporter = Oboe_metal::Reporter.new(*options)
43
45
 
44
46
  # Only report __Init from here if we are not instrumenting a framework.
45
47
  # Otherwise, frameworks will handle reporting __Init after full initialization