appoptics_apm 4.5.2 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 2f6f74865135bb353e7f453b844739e7c0a93d4c38d38d36982c7710f7f31907
4
- data.tar.gz: cafe57a6604f715e5f33c2dcf657803d256cf3dea951facbc19ca05be1e7865b
2
+ SHA1:
3
+ metadata.gz: cbe2fe3eb37b24986942279b151f1b75bcc1d992
4
+ data.tar.gz: 44afa0ee08b1835b75bfab6bfd18380d43bb9df4
5
5
  SHA512:
6
- metadata.gz: 230aaaa311ae7741a6e65168326a79a7e7cee82edf857827d9ce4dff07624a6f3acff4a655a5fa98ac4d53ed05f90b2a71282cf995259c4e7d2e48ad7d3de9ba
7
- data.tar.gz: 8f43e985fb4379c9c61356a2d24189710db9a1c1c2c9d03bfbc0727ac5e4fdcf7c66dd706120b6e908a346ef1e8942d40a6d28548c02d25554d2c923fbd52e89
6
+ metadata.gz: ea8bbfb90ddee8a6eeac9acba93eda3a66645ca409ded1d15fbb73ef2e9c05f14f0b0052072826a4f5e9704311e5509c528a4de613a902edfe646b8210bae19d
7
+ data.tar.gz: 4282a917fc4d523c471bb2d322f5bff18348b0154d5f18562fad85c8f777e421f091390f11c78adf4e19d75fe7da34c7ac8b9d1a8457239fa89c5b90836fe2ef
@@ -11,11 +11,11 @@ env:
11
11
  - DBTYPE=mysql
12
12
 
13
13
  rvm:
14
- - 2.6.0
14
+ - 2.6.2
15
15
  - 2.5.3
16
16
  - 2.4.5
17
17
  - 2.3.8
18
- # - ruby-head
18
+ - ruby-head
19
19
  # - jruby-9.0.5.0
20
20
 
21
21
  gemfile:
@@ -33,10 +33,11 @@ matrix:
33
33
  exclude:
34
34
  - rvm: ruby-head
35
35
  gemfile: gemfiles/rails42.gemfile
36
- - rvm: 2.6.0
36
+ - rvm: 2.6.2
37
37
  gemfile: gemfiles/rails42.gemfile
38
38
 
39
- - rmv: 2.6.0
39
+
40
+ - rmv: 2.6.2
40
41
  env: DBTYPE=mysql
41
42
  - rvm: 2.5.3
42
43
  env: DBTYPE=mysql
data/Gemfile CHANGED
@@ -15,9 +15,9 @@ group :development, :test do
15
15
  gem 'benchmark-ips'
16
16
  gem 'ruby-debug', :platforms => :jruby
17
17
  gem 'debugger', :platform => :mri_19
18
- gem 'byebug', :platforms => [:mri_22, :mri_23, :mri_24]
19
- gem 'pry'
20
- gem 'pry-byebug', :platforms => [:mri_22, :mri_23, :mri_24]
18
+ gem 'byebug'
19
+ gem 'get_process_mem'
20
+ gem 'memory_profiler'
21
21
  end
22
22
 
23
23
  if defined?(JRUBY_VERSION)
data/README.md CHANGED
@@ -185,8 +185,8 @@ Bundler.require
185
185
  require 'appoptics_apm'
186
186
 
187
187
 
188
- # Tracing mode can be 'never', 'through' (to follow upstream) or 'always'
189
- AppOpticsAPM::Config[:tracing_mode] = 'always'
188
+ # Tracing mode can be :enabled or :disabled
189
+ AppOpticsAPM::Config[:tracing_mode] = :enabled
190
190
 
191
191
  #
192
192
  # Update April 9, 2015 - this is done automagically now
@@ -233,7 +233,7 @@ Find more details in the [RubyDoc page](https://www.rubydoc.info/gems/appoptics_
233
233
 
234
234
  # Support
235
235
 
236
- If you find a bug or would like to request an enhancement, feel free to contact our tech support
236
+ If you run into a problem, find a bug, or would like to request an enhancement, feel free to contact our tech support
237
237
  [support@appoptics.com](support@appoptics.com).
238
238
 
239
239
  # Contributing
data/Rakefile CHANGED
@@ -63,13 +63,19 @@ end
63
63
  desc "Run all test suites defined by travis"
64
64
  task "docker_tests" do
65
65
  Dir.chdir('test/run_tests')
66
- exec('docker-compose run --service-ports ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh test')
66
+ exec('docker-compose run ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh test')
67
67
  end
68
68
 
69
69
  desc "Start docker container for testing and debugging"
70
70
  task "docker" do
71
71
  Dir.chdir('test/run_tests')
72
- exec('docker-compose run --service-ports ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh bash')
72
+ exec('docker-compose run ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh bash')
73
+ end
74
+
75
+ desc "Stop all containers that were started for testing and debugging"
76
+ task "docker_down" do
77
+ Dir.chdir('test/run_tests')
78
+ exec('docker-compose down')
73
79
  end
74
80
 
75
81
  desc "Fetch extension dependency files"
@@ -208,7 +214,7 @@ task :environment do
208
214
  ENV['APPOPTICS_GEM_VERBOSE'] = 'true'
209
215
 
210
216
  Bundler.require(:default, :development)
211
- AppOpticsAPM::Config[:tracing_mode] = :always
217
+ AppOpticsAPM::Config[:tracing_mode] = :enabled
212
218
  AppOpticsAPM::Test.load_extras
213
219
 
214
220
  if AppOpticsAPM::Test.gemfile?(:delayed_job)
@@ -216,14 +222,6 @@ task :environment do
216
222
  end
217
223
  end
218
224
 
219
- task :console => :environment do
220
- ARGV.clear
221
- if AppOpticsAPM::Test.gemfile?(:delayed_job)
222
- require './test/servers/delayed_job'
223
- end
224
- Pry.start
225
- end
226
-
227
225
  # Used when testing Resque locally
228
226
  task 'resque:setup' => :environment do
229
227
  require 'resque/tasks'
@@ -46,14 +46,12 @@ Automatic tracing and metrics for Ruby applications. Get started at appoptics.co
46
46
  s.add_development_dependency('rake', '>= 0.9.0')
47
47
  s.add_development_dependency('simplecov', '>= 0.16.0') if ENV["SIMPLECOV_COVERAGE"]
48
48
  s.add_development_dependency('simplecov-console', '>= 0.4.0') if ENV["SIMPLECOV_COVERAGE"]
49
+ s.add_development_dependency('irb', '>= 1.0.0') if RUBY_VERSION >= '2.6.0'
49
50
 
50
51
  unless defined?(JRUBY_VERSION)
51
52
  s.add_development_dependency('byebug', '>= 8.0.0')
52
- s.add_development_dependency('pry', '>= 0.10.0')
53
- s.add_development_dependency('pry-byebug', '>= 3.0.0')
54
53
  s.add_development_dependency('minitest-hooks', '>= 1.5.0')
55
- else
56
- s.add_development_dependency('pry', '>= 0.10.0')
54
+ s.add_development_dependency('benchmark-ips', '>= 2.7.2')
57
55
  end
58
56
 
59
57
  s.required_ruby_version = '>= 2.0.0'
@@ -1,6 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
- # build the gem
3
+ # build the gem,
4
+ # oboe/c-lib version can be given as optional parameter
4
5
  if [ "$1" != "" ]; then
5
6
  OBOE_VERSION=$1 ./build_gem.sh
6
7
  else
@@ -7,7 +7,7 @@
7
7
  # `bundle exec ruby 01_basic_tracing.rb`
8
8
 
9
9
  require 'appoptics_apm'
10
- unless AppopticsAPM::SDK.appoptics_ready(10_000)
10
+ unless AppopticsAPM::SDK.appoptics_ready?(10_000)
11
11
  puts "aborting!!! Agent not ready after 10 seconds"
12
12
  exit false
13
13
  end
@@ -51,6 +51,7 @@ AppOpticsAPM::SDK.start_trace('outer_span') do
51
51
 
52
52
  AppOpticsAPM::SDK.trace('simple_span') do
53
53
  do_work
54
+ AppOpticsAPM::API.log_info(AppOpticsAPM.layer, { some: :fancy, hash: :to, send: 1 })
54
55
  end
55
56
 
56
57
  end
@@ -1 +1 @@
1
- 3.3.0
1
+ 4.0.1
@@ -8,7 +8,7 @@ begin
8
8
  require 'appoptics_apm/logger'
9
9
  require 'appoptics_apm/util'
10
10
  require 'appoptics_apm/xtrace'
11
- require 'appoptics_apm/support'
11
+ require 'appoptics_apm/support_report'
12
12
  require 'appoptics_apm/base'
13
13
  AppOpticsAPM.loaded = false
14
14
 
@@ -49,6 +49,7 @@ begin
49
49
  # tracing mode is configured via config file but can only be set once we have oboe_metal loaded
50
50
  AppOpticsAPM.set_tracing_mode(AppOpticsAPM::Config[:tracing_mode].to_sym)
51
51
  require 'appoptics_apm/instrumentation'
52
+ require 'appoptics_apm/support/transaction_metrics'
52
53
 
53
54
  # Frameworks
54
55
  require 'appoptics_apm/frameworks/rails'
@@ -31,7 +31,7 @@ module AppOpticsAPM
31
31
  'removed in a subsequent version.'
32
32
 
33
33
  saved_mode = AppOpticsAPM::Config[:tracing_mode]
34
- AppOpticsAPM::Config[:tracing_mode] = :always
34
+ AppOpticsAPM::Config[:tracing_mode] = :enabled
35
35
  yield
36
36
  ensure
37
37
  AppOpticsAPM::Config[:tracing_mode] = saved_mode
@@ -87,7 +87,8 @@ module AppOpticsAPM
87
87
  end
88
88
 
89
89
  ##
90
- # Public: Decide whether or not to start a trace, and report an entry event
90
+ # Public: Start a trace depending on TransactionSettings
91
+ # or decide whether or not to start a trace, and report an entry event
91
92
  # appropriately.
92
93
  #
93
94
  # ==== Arguments
@@ -95,83 +96,38 @@ module AppOpticsAPM
95
96
  # * +layer+ - The layer the reported event belongs to
96
97
  # * +xtrace+ - An xtrace metadata string, or nil. Used for cross-application tracing.
97
98
  # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
99
+ # * +settings+ - An instance of TransactionSettings
98
100
  #
99
101
  # ==== Example
100
102
  #
101
103
  # AppOpticsAPM::API.log_start(:layer_name, nil, { :id => @user.id })
102
104
  #
103
105
  # Returns an xtrace metadata string if we are tracing
104
- def log_start(layer, xtrace = nil, opts = {})
105
- return if !AppOpticsAPM.loaded || (opts.key?(:URL) && AppOpticsAPM::Util.static_asset?(opts[:URL]))
106
-
107
- #--
108
- # Is the below necessary? Only on JRuby? Could there be an existing context but not x-trace header?
109
- # See discussion at:
110
- # https://github.com/librato/ruby-tracelytics/pull/6/files?diff=split#r131029135
111
- #
112
- # Used by JRuby/Java webservers such as Tomcat
113
- # AppOpticsAPM::Context.fromString(xtrace) if AppOpticsAPM.pickup_context?(xtrace)
114
-
115
- # if AppOpticsAPM.tracing?
116
- # # Pre-existing context. Either we inherited context from an
117
- # # incoming X-Trace request header or under JRuby, Joboe started
118
- # # tracing before the JRuby code was called (e.g. Tomcat)
119
- # AppOpticsAPM.is_continued_trace = true
120
-
121
- # if AppOpticsAPM.has_xtrace_header
122
- # opts[:TraceOrigin] = :continued_header
123
- # elsif AppOpticsAPM.has_incoming_context
124
- # opts[:TraceOrigin] = :continued_context
125
- # else
126
- # opts[:TraceOrigin] = :continued
127
- # end
128
-
129
- # return log_entry(layer, opts)
130
- # end
131
- #++
106
+ #
107
+ def log_start(layer, xtrace = nil, opts = {}, settings = nil)
108
+ return unless AppOpticsAPM.loaded
109
+
110
+ # check if tracing decision is already in effect and a Context created
111
+ return log_entry(layer, opts) if AppOpticsAPM::Context.isValid
132
112
 
133
113
  # This is a bit ugly, but here is the best place to reset the layer_op thread local var.
134
- AppOpticsAPM.layer_op = nil unless AppOpticsAPM::Context.isValid
135
-
136
- if AppOpticsAPM.sample?(opts.merge(:xtrace => xtrace))
137
- # Yes, we're sampling this request
138
- # Probablistic tracing of a subset of requests based off of
139
- # sample rate and sample source
140
- opts[:SampleRate] = AppOpticsAPM.sample_rate
141
- opts[:SampleSource] = AppOpticsAPM.sample_source
142
- opts[:TraceOrigin] = :always_sampled
143
-
144
- if xtrace_v2?(xtrace)
145
- # continue valid incoming xtrace
146
- # use it for current context, ensuring sample bit is set
147
- AppOpticsAPM::XTrace.set_sampled(xtrace)
148
-
149
- md = AppOpticsAPM::Metadata.fromString(xtrace)
150
- AppOpticsAPM::Context.fromString(xtrace)
151
- log_event(layer, :entry, md.createEvent, opts)
152
- else
153
- # discard invalid incoming xtrace
154
- # create a new context, ensuring sample bit set
155
- md = AppOpticsAPM::Metadata.makeRandom(true)
156
- AppOpticsAPM::Context.set(md)
157
- log_event(layer, :entry, AppOpticsAPM::Event.startTrace(md), opts)
158
- end
114
+ AppOpticsAPM.layer_op = nil
115
+
116
+ xtrace = nil unless AppOpticsAPM::XTrace.valid?(xtrace)
117
+
118
+ settings ||= AppOpticsAPM::TransactionSettings.new(nil, xtrace)
119
+
120
+ if settings.do_sample
121
+ opts[:SampleRate] = settings.rate
122
+ opts[:SampleSource] = settings.source
123
+
124
+ AppOpticsAPM::XTrace.set_sampled(xtrace) if xtrace
125
+ event = create_start_event(xtrace)
126
+ log_event(layer, :entry, event, opts)
159
127
  else
160
- # No, we're not sampling this request
161
- # set the context but don't log the event
162
- if xtrace_v2?(xtrace)
163
- # continue valid incoming xtrace
164
- # use it for current context, ensuring sample bit is not set
165
- AppOpticsAPM::XTrace.unset_sampled(xtrace)
166
- AppOpticsAPM::Context.fromString(xtrace)
167
- else
168
- # discard invalid incoming xtrace
169
- # create a new context, ensuring sample bit not set
170
- md = AppOpticsAPM::Metadata.makeRandom(false)
171
- AppOpticsAPM::Context.fromString(md.toString)
172
- end
128
+ create_nontracing_context(xtrace)
129
+ AppOpticsAPM::Context.toString
173
130
  end
174
- AppOpticsAPM::Context.toString
175
131
  end
176
132
 
177
133
  ##
@@ -187,6 +143,7 @@ module AppOpticsAPM
187
143
  # AppOpticsAPM::API.log_end(:layer_name, { :id => @user.id })
188
144
  #
189
145
  # Returns an xtrace metadata string if we are tracing
146
+ #
190
147
  def log_end(layer, opts = {}, event = nil)
191
148
  return AppOpticsAPM::Context.toString unless AppOpticsAPM.tracing?
192
149
 
@@ -214,11 +171,19 @@ module AppOpticsAPM
214
171
  # AppOpticsAPM::API.log_entry(:layer_name, { :id => @user.id })
215
172
  #
216
173
  # Returns an xtrace metadata string if we are tracing
217
- def log_entry(layer, opts = {}, op = nil)
174
+ #
175
+ def log_entry(layer, opts = {}, op = nil) #, event = nil)
218
176
  return AppOpticsAPM::Context.toString unless AppOpticsAPM.tracing?
219
177
 
220
- AppOpticsAPM.layer_op = (AppOpticsAPM.layer_op || []) << op.to_sym if op
221
- log_event(layer, :entry, AppOpticsAPM::Context.createEvent, opts)
178
+ if op
179
+ # check if re-entry but also add op to list for log_exit
180
+ re_entry = AppOpticsAPM.layer_op&.last == op.to_sym
181
+ AppOpticsAPM.layer_op = (AppOpticsAPM.layer_op || []) << op.to_sym
182
+ return AppOpticsAPM::Context.toString if re_entry
183
+ end
184
+
185
+ event ||= AppOpticsAPM::Context.createEvent
186
+ log_event(layer, :entry, event, opts)
222
187
  end
223
188
 
224
189
  ##
@@ -236,6 +201,7 @@ module AppOpticsAPM
236
201
  # AppOpticsAPM::API.log_info(:layer_name, { :id => @user.id })
237
202
  #
238
203
  # Returns an xtrace metadata string if we are tracing
204
+ #
239
205
  def log_info(layer, opts = {})
240
206
  return AppOpticsAPM::Context.toString unless AppOpticsAPM.tracing?
241
207
 
@@ -251,7 +217,7 @@ module AppOpticsAPM
251
217
  #
252
218
  # * +layer+ - The layer the reported event belongs to
253
219
  # * +opts+ - A hash containing key/value pairs that will be reported along with this event (optional).
254
- # * +op+ - Used to avoid double tracing recursive calls, needs to be true in +log_exit+ that corresponds to a
220
+ # * +op+ - Used to avoid double tracing recursive calls, needs to be the same in +log_exit+ that corresponds to a
255
221
  # +log_entry+
256
222
  #
257
223
  # ==== Example
@@ -262,7 +228,15 @@ module AppOpticsAPM
262
228
  def log_exit(layer, opts = {}, op = nil)
263
229
  return AppOpticsAPM::Context.toString unless AppOpticsAPM.tracing?
264
230
 
265
- AppOpticsAPM.layer_op.pop if op && AppOpticsAPM.layer_op.is_a?(Array) && AppOpticsAPM.layer_op.last == op.to_sym
231
+ if op
232
+ if AppOpticsAPM.layer_op&.last == op.to_sym
233
+ AppOpticsAPM.layer_op.pop
234
+ else
235
+ AppOpticsAPM.logger.warn "[ruby/logging] op parameter of exit event doesn't correspond to an entry event op"
236
+ end
237
+ # check if the next op is the same, don't log event if so
238
+ return AppOpticsAPM::Context.toString if AppOpticsAPM.layer_op&.last == op.to_sym
239
+ end
266
240
 
267
241
  log_event(layer, :exit, AppOpticsAPM::Context.createEvent, opts)
268
242
  end
@@ -367,6 +341,34 @@ module AppOpticsAPM
367
341
  AppOpticsAPM::Context.toString
368
342
  end
369
343
 
344
+ def create_start_event(xtrace = nil)
345
+ if AppOpticsAPM::XTrace.sampled?(xtrace)
346
+ md = AppOpticsAPM::Metadata.fromString(xtrace)
347
+ AppOpticsAPM::Context.fromString(xtrace)
348
+ md.createEvent
349
+ else
350
+ md = AppOpticsAPM::Metadata.makeRandom(true)
351
+ AppOpticsAPM::Context.set(md)
352
+ AppOpticsAPM::Event.startTrace(md)
353
+ end
354
+ end
355
+
356
+ public
357
+
358
+ def create_nontracing_context(xtrace)
359
+ if AppOpticsAPM::XTrace.valid?(xtrace)
360
+ # continue valid incoming xtrace
361
+ # use it for current context, ensuring sample bit is not set
362
+ AppOpticsAPM::XTrace.unset_sampled(xtrace)
363
+ AppOpticsAPM::Context.fromString(xtrace)
364
+ else
365
+ # discard invalid incoming xtrace
366
+ # create a new context, ensuring sample bit not set
367
+ md = AppOpticsAPM::Metadata.makeRandom(false)
368
+ AppOpticsAPM::Context.fromString(md.toString)
369
+ end
370
+ end
371
+
370
372
  # need to set the context to public, otherwise the following `extends` will be private in api.rb
371
373
  public
372
374
 
@@ -2,8 +2,8 @@
2
2
  # All rights reserved.
3
3
 
4
4
  # Constants from liboboe
5
- APPOPTICS_TRACE_NEVER = 0
6
- APPOPTICS_TRACE_ALWAYS = 1
5
+ APPOPTICS_TRACE_DISABLED = 0
6
+ APPOPTICS_TRACE_ENABLED = 1
7
7
 
8
8
  # OBOE_SAMPLE_RATE_SOURCE_FILE = 1
9
9
  # OBOE_SAMPLE_RATE_SOURCE_DEFAULT = 2
@@ -147,22 +147,26 @@ module AppOpticsAPMBase
147
147
  AppOpticsAPM.layer_op.last == operation.to_sym
148
148
  end
149
149
 
150
+ # TODO ME review use of these boolean statements
151
+ # ____ they should now be handled by TransactionSettings,
152
+ # ____ because there can be exceptions to :enabled and :disabled
153
+
150
154
  ##
151
- # Returns true if the tracing_mode is set to always.
155
+ # Returns true if the tracing_mode is set to :enabled.
152
156
  # False otherwise
153
157
  #
154
- def always?
158
+ def tracing_enabled?
155
159
  AppOpticsAPM::Config[:tracing_mode] &&
156
- AppOpticsAPM::Config[:tracing_mode].to_sym == :always
160
+ [:enabled, :always].include?(AppOpticsAPM::Config[:tracing_mode].to_sym)
157
161
  end
158
162
 
159
163
  ##
160
- # Returns true if the tracing_mode is set to never.
164
+ # Returns true if the tracing_mode is set to :disabled.
161
165
  # False otherwise
162
166
  #
163
- def never?
167
+ def tracing_disabled?
164
168
  AppOpticsAPM::Config[:tracing_mode] &&
165
- AppOpticsAPM::Config[:tracing_mode].to_sym == :never
169
+ [:disabled, :never].include?(AppOpticsAPM::Config[:tracing_mode].to_sym)
166
170
  end
167
171
 
168
172
  ##
@@ -170,7 +174,7 @@ module AppOpticsAPMBase
170
174
  # False otherwise
171
175
  #
172
176
  def tracing?
173
- return false if !AppOpticsAPM.loaded || AppOpticsAPM.never?
177
+ return false if !AppOpticsAPM.loaded # || AppOpticsAPM.tracing_disabled?
174
178
  AppOpticsAPM::Context.isSampled
175
179
  end
176
180