appoptics_apm 4.7.0 → 4.8.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbff2f2eda2d2c65cf7dbac060957eb6505b3eba743f11dc415f6b06c67217cb
4
- data.tar.gz: 6008d6151ab8eb3b29aa465ebb131eef38139d159587e35d5d68dd07de716104
3
+ metadata.gz: d0ccc84ee6065cc578c0b3dd768825b56a9cd17a1661e4df703621cec10e03c7
4
+ data.tar.gz: f981f8b2dd4e858b52dc71ad8055c931544a3428a35ca13f30575447fb4a67d9
5
5
  SHA512:
6
- metadata.gz: 1247aa650e5ff98074d479248c01ff11c8b18f0c63dac47987f79b75efe7518987f43af8ce9adf63cf50df7b9f8d9024deb59da1b9d4b3bd9be56c9d70252114
7
- data.tar.gz: 7196764529dfde97d4ca10871d9506a21e411454e5acdd0218945241de2acb22b1ece9e38876ed054d586ed695b276d602ebe116b1f08ff2cf5a98c9537fd5de
6
+ metadata.gz: 8636c892f94298fb8851641566ca7ccef1f72888c4f37242898993e68278f09904b231c75271a2448cef3530ab7477b36cab000644ab24e605eee9ba0f377c6e
7
+ data.tar.gz: 96b455b4744604a8d52ce794c070bca3b95543a0e820454d86e3a55ab49a9f22232b9386cecf4bdd1d97585f5e4fdb4e8d796af9ee4cf5138a67736ee0cefedd
data/.travis.yml CHANGED
@@ -14,7 +14,6 @@ rvm:
14
14
  - 2.6.2
15
15
  - 2.5.3
16
16
  - 2.4.5
17
- - 2.3.8
18
17
  - ruby-head
19
18
  # - jruby-9.0.5.0
20
19
 
data/.yardopts CHANGED
@@ -1,5 +1,6 @@
1
1
  --no-private
2
2
  --readme yardoc_frontpage.md
3
+ lib/appoptics_apm/sdk/logging.rb
3
4
  lib/appoptics_apm/sdk/tracing.rb
4
5
  lib/appoptics_apm/sdk/custom_metrics.rb
5
6
  lib/appoptics_apm/sdk/current_trace.rb
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The appoptics_apm gem provides [AppOptics APM](https://www.appoptics.com/) performance instrumentation for Ruby.
4
4
 
5
- ![Ruby AppOpticsAPM](https://docs.appoptics.com/_images/ruby_trace.png)
5
+ ![Ruby AppOpticsAPM](https://docs.appoptics.com/_images/ruby_trace_smaller.png)
6
6
 
7
7
  It has the ability to report performance metrics on an array of libraries, databases and frameworks such as Rails,
8
8
  Mongo, Memcache, ActiveRecord, Cassandra, Rack, Resque
data/Rakefile CHANGED
@@ -108,6 +108,7 @@ task :fetch_ext_deps do
108
108
  # oboe and bson header files
109
109
  FileUtils.mkdir_p(File.join(ext_src_dir, 'bson'))
110
110
  %w(oboe.h oboe.hpp oboe_debug.h oboe.i bson/bson.h bson/platform_hacks.h).each do |filename|
111
+ # %w(oboe.h oboe_debug.h bson/bson.h bson/platform_hacks.h).each do |filename|
111
112
  remote_file = File.join(oboe_s3_dir, 'include', filename)
112
113
  local_file = File.join(ext_src_dir, filename)
113
114
 
@@ -1 +1 @@
1
- 4.1.0
1
+ 5.0.0
data/lib/appoptics_apm.rb CHANGED
@@ -21,22 +21,23 @@ begin
21
21
  require 'joboe_metal'
22
22
  elsif RUBY_PLATFORM =~ /linux/
23
23
  require_relative './oboe_metal.so'
24
+ require 'appoptics_apm/oboe_init_options'
24
25
  require 'oboe_metal.rb' # sets AppOpticsAPM.loaded = true if successful
25
26
  else
26
- $stderr.puts '==================================================================='
27
- $stderr.puts "AppOptics warning: Platform #{RUBY_PLATFORM} not yet supported."
28
- $stderr.puts 'see: https://docs.appoptics.com/kb/apm_tracing/supported_platforms/'
29
- $stderr.puts 'Tracing disabled.'
30
- $stderr.puts 'Contact support@appoptics.com if this is unexpected.'
31
- $stderr.puts '==================================================================='
27
+ AppOpticsAPM.logger.warn '==================================================================='
28
+ AppOpticsAPM.logger.warn "AppOptics warning: Platform #{RUBY_PLATFORM} not yet supported."
29
+ AppOpticsAPM.logger.warn 'see: https://docs.appoptics.com/kb/apm_tracing/supported_platforms/'
30
+ AppOpticsAPM.logger.warn 'Tracing disabled.'
31
+ AppOpticsAPM.logger.warn 'Contact support@appoptics.com if this is unexpected.'
32
+ AppOpticsAPM.logger.warn '==================================================================='
32
33
  end
33
34
  rescue LoadError => e
34
35
  unless ENV['RAILS_GROUP'] == 'assets' or ENV['IGNORE_APPOPTICS_WARNING']
35
- $stderr.puts '=============================================================='
36
- $stderr.puts 'Missing AppOpticsAPM libraries. Tracing disabled.'
37
- $stderr.puts "Error: #{e.message}"
38
- $stderr.puts 'See: https://docs.appoptics.com/kb/apm_tracing/ruby/'
39
- $stderr.puts '=============================================================='
36
+ AppOpticsAPM.logger.error '=============================================================='
37
+ AppOpticsAPM.logger.error 'Missing AppOpticsAPM libraries. Tracing disabled.'
38
+ AppOpticsAPM.logger.error "Error: #{e.message}"
39
+ AppOpticsAPM.logger.error 'See: https://docs.appoptics.com/kb/apm_tracing/ruby/'
40
+ AppOpticsAPM.logger.error '=============================================================='
40
41
  end
41
42
  end
42
43
 
@@ -46,8 +47,6 @@ begin
46
47
  require 'appoptics_apm/method_profiling'
47
48
 
48
49
  if AppOpticsAPM.loaded
49
- # tracing mode is configured via config file but can only be set once we have oboe_metal loaded
50
- AppOpticsAPM.set_tracing_mode(AppOpticsAPM::Config[:tracing_mode].to_sym)
51
50
  require 'appoptics_apm/instrumentation'
52
51
  require 'appoptics_apm/support/transaction_metrics'
53
52
 
@@ -57,10 +56,11 @@ begin
57
56
  require 'appoptics_apm/frameworks/padrino'
58
57
  require 'appoptics_apm/frameworks/grape'
59
58
  else
60
- $stderr.puts '=============================================================='
61
- $stderr.puts 'AppOpticsAPM not loaded. Tracing disabled.'
62
- $stderr.puts 'Service Key may be wrong or missing.'
63
- $stderr.puts '=============================================================='
59
+ AppOpticsAPM.logger.warn '=============================================================='
60
+ AppOpticsAPM.logger.warn 'AppOpticsAPM not loaded. Tracing disabled.'
61
+ AppOpticsAPM.logger.warn 'There may be a problem with the service key or other settings.'
62
+ AppOpticsAPM.logger.warn 'Please check previous log messages.'
63
+ AppOpticsAPM.logger.warn '=============================================================='
64
64
  require 'appoptics_apm/noop/context'
65
65
  require 'appoptics_apm/noop/metadata'
66
66
  end
@@ -21,13 +21,10 @@ SAMPLE_SOURCE_MASK = 0b1111000000000000000000000000
21
21
  # ZERO_SAMPLE_RATE_MASK = 0b1111000000000000000000000000
22
22
  # ZERO_SAMPLE_SOURCE_MASK = 0b0000111111111111111111111111
23
23
 
24
- APPOPTICS_STR_BLANK = ''.freeze
24
+ # APPOPTICS_STR_BLANK = ''.freeze
25
25
  APPOPTICS_STR_LAYER = 'Layer'.freeze
26
26
  APPOPTICS_STR_LABEL = 'Label'.freeze
27
27
 
28
- # Used in tests to store local trace data
29
- TRACE_FILE = '/tmp/appoptics_traces.bson'.freeze
30
-
31
28
  ##
32
29
  # This module is the base module for the various implementations of AppOpticsAPM reporting.
33
30
  # Current variations as of 2014-09-10 are a c-extension, JRuby (using AppOpticsAPM Java
@@ -67,19 +67,22 @@ module AppOpticsAPM
67
67
  ].join(' ')
68
68
  end
69
69
  load(config_files[0])
70
- check_env_vars
70
+ # sets AppOpticsAPM::Config[:debug_level], AppOpticsAPM.logger.level
71
+ set_log_level
72
+
73
+ # the verbose setting is only relevant for ruby, ENV['APPOPTICS_GEM_VERBOSE'] overrides
74
+ if ENV.key?('APPOPTICS_GEM_VERBOSE')
75
+ AppOpticsAPM::Config[:verbose] = ENV['APPOPTICS_GEM_VERBOSE'].downcase == 'true'
76
+ end
71
77
  end
72
78
 
73
- # There are 4 variables that can be set in the config file or as env vars.
74
- # Oboe will override vars passed in if it finds an environment variable
75
- # :debug_level and :verbose need special consideration, because they are used in Ruby
76
- def self.check_env_vars
79
+ def self.set_log_level
77
80
  unless (-1..6).include?(AppOpticsAPM::Config[:debug_level])
78
81
  AppOpticsAPM::Config[:debug_level] = 3
79
82
  end
80
83
 
81
- # let's find and use the equivalent debug level for ruby
82
- debug_level = ENV['APPOPTICS_DEBUG_LEVEL'] ? ENV['APPOPTICS_DEBUG_LEVEL'].to_i : AppOpticsAPM::Config[:debug_level]
84
+ # let's find and use the equivalent debug level for ruby
85
+ debug_level = (ENV['APPOPTICS_DEBUG_LEVEL'] || AppOpticsAPM::Config[:debug_level] || 3).to_i
83
86
  if debug_level < 0
84
87
  # there should be no logging if APPOPTICS_DEBUG_LEVEL == -1
85
88
  # In Ruby level 5 is UNKNOWN and it can log, but level 6 is quiet
@@ -87,11 +90,7 @@ module AppOpticsAPM
87
90
  else
88
91
  AppOpticsAPM.logger.level = [4 - debug_level, 0].max
89
92
  end
90
-
91
- # the verbose setting is only relevant for ruby, ENV['APPOPTICS_GEM_VERBOSE'] overrides
92
- if ENV.key?('APPOPTICS_GEM_VERBOSE')
93
- AppOpticsAPM::Config[:verbose] = ENV['APPOPTICS_GEM_VERBOSE'].downcase == 'true'
94
- end
93
+ AppOpticsAPM::Config[:debug_level] = debug_level
95
94
  end
96
95
 
97
96
  ##
@@ -144,9 +143,6 @@ module AppOpticsAPM
144
143
  # no guarantee of completeness in the user's config file
145
144
  load(File.join(File.dirname(File.dirname(__FILE__)),
146
145
  'rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb'))
147
-
148
- # to make sure we include the service_key if it is set as an ENV var
149
- check_env_vars
150
146
  end
151
147
  # rubocop:enable Metrics/AbcSize
152
148
 
@@ -243,11 +239,12 @@ module AppOpticsAPM
243
239
  @@config[i][:log_args] = value
244
240
  end
245
241
 
246
- # Update liboboe if updating :tracing_mode
247
242
  elsif key == :tracing_mode
248
- AppOpticsAPM.set_tracing_mode(value.to_sym) if AppOpticsAPM.loaded
243
+ # CAN'T DO THIS ANYMORE, ALL TRACING COMMUNICATION TO OBOE
244
+ # IS NOW HANDLED BY TransactionSettings
245
+ # AppOpticsAPM.set_tracing_mode(value.to_sym) if AppOpticsAPM.loaded
249
246
 
250
- # Make sure that the mode is stored as a symbol
247
+ # Make sure that the mode is stored as a symbol
251
248
  @@config[key.to_sym] = value.to_sym
252
249
  end
253
250
  end
@@ -35,11 +35,12 @@ module AppOpticsAPM
35
35
  # args: 0: worker, 1: msg, 2: queue
36
36
  report_kvs = collect_kvs(args)
37
37
 
38
+ # TODO remove completely once it is determined that this works without
38
39
  # Something is happening across Celluloid threads where liboboe settings
39
40
  # are being lost. So we re-set the tracing mode to assure
40
41
  # we sample as desired. Setting the tracing mode will re-update
41
42
  # the liboboe settings.
42
- AppOpticsAPM.set_tracing_mode(AppOpticsAPM::Config[:tracing_mode].to_sym)
43
+ # AppOpticsAPM.set_tracing_mode(AppOpticsAPM::Config[:tracing_mode].to_sym)
43
44
 
44
45
  # Continue the trace from the enqueue side?
45
46
  if args[1].is_a?(Hash) && AppOpticsAPM::XTrace.valid?(args[1]['SourceTrace'])
@@ -0,0 +1,180 @@
1
+ # Copyright (c) 2019 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ require 'singleton'
5
+
6
+ module AppOpticsAPM
7
+
8
+ class OboeInitOptions
9
+ include Singleton
10
+
11
+ attr_reader :reporter, :host, :service_name # exposing these mainly for testing
12
+
13
+ # TODO decide if these globals are useful when testing
14
+ # OBOE_HOSTNAME_ALIAS = 0
15
+ # OBOE_DEBUG_LEVEL = 1
16
+ # OBOE_LOGFILE = 2
17
+ #
18
+ # OBOE_MAX_TRANSACTIONS = 3
19
+ # OBOE_FLUSH_MAX_WAIT_TIME = 4
20
+ # OBOE_EVENTS_FLUSH_INTERVAL = 5
21
+ # OBOE_EVENTS_FLUSH_BATCH_SIZE = 6
22
+ #
23
+ # OBOE_REPORTER = 7
24
+ # OBOE_COLLECTOR = 8
25
+ # OBOE_SERVICE_KEY = 9
26
+ # OBOE_TRUSTEDPATH = 10
27
+ #
28
+ # OBOE_BUFSIZE = 11
29
+ # OBOE_TRACE_METRICS = 12
30
+ # OBOE_HISTOGRAM_PRECISION = 13
31
+ # OBOE_TOKEN_BUCKET_CAPACITY = 14
32
+ # OBOE_TOKEN_BUCKET_RATE = 15
33
+ # OBOE_FILE_SINGLE = 16
34
+
35
+ def initialize
36
+ # optional hostname alias
37
+ @hostname_alias = ENV['APPOPTICS_HOSTNAME_ALIAS'] || AppOpticsAPM::Config[:hostname_alias] || ''
38
+ # level at which log messages will be written to log file (0-6)
39
+ @debug_level = (ENV['APPOPTICS_DEBUG_LEVEL'] || AppOpticsAPM::Config[:debug_level] || 3).to_i
40
+ # file name including path for log file
41
+ # TODO eventually find better way to combine ruby and oboe logs
42
+ @log_file_path = ENV['APPOPTICS_LOGFILE'] || ''
43
+ # maximum number of transaction names to track
44
+ @max_transactions = (ENV['APPOPTICS_MAX_TRANSACTIONS'] || -1).to_i
45
+ # maximum wait time for flushing data before terminating in milli seconds
46
+ @max_flush_wait_time = (ENV['APPOPTICS_FLUSH_MAX_WAIT_TIME'] || -1).to_i
47
+ # events flush timeout in seconds (threshold for batching messages before sending off)
48
+ @events_flush_interval = (ENV['APPOPTICS_EVENTS_FLUSH_INTERVAL'] || -1).to_i
49
+ # events flush batch size in KB (threshold for batching messages before sending off)
50
+ @event_flush_batch_size = (ENV['APPOPTICS_EVENTS_FLUSH_BATCH_SIZE'] || -1).to_i
51
+
52
+ # the reporter to be used (ssl, upd, file, null)
53
+ # collector endpoint (reporter=ssl), udp address (reporter=udp), or file path (reporter=file)
54
+ @reporter, @host = reporter_and_host
55
+
56
+ # the service key
57
+ @service_key = read_and_validate_service_key
58
+ # path to the SSL certificate (only for ssl)
59
+ @trusted_path = ENV['APPOPTICS_TRUSTEDPATH'] || ''
60
+ # size of the message buffer
61
+ @buffer_size = (ENV['APPOPTICS_BUFSIZE'] || -1).to_i
62
+ # flag indicating if trace metrics reporting should be enabled (default) or disabled
63
+ @trace_metrics = (ENV['APPOPTICS_TRACE_METRICS'] || -1).to_i
64
+ # the histogram precision (only for ssl)
65
+ @histogram_precision = (ENV['APPOPTICS_HISTOGRAM_PRECISION'] || -1).to_i
66
+ # custom token bucket capacity
67
+ @token_bucket_capacity = (ENV['APPOPTICS_TOKEN_BUCKET_CAPACITY'] || -1).to_i
68
+ # custom token bucket rate
69
+ @token_bucket_rate = (ENV['APPOPTICS_TOKEN_BUCKET_RATE'] || -1).to_i
70
+ # use single files in file reporter for each event
71
+ @file_single = (ENV['APPOPTICS_REPORTER_FILE_SINGLE'].to_s.downcase == 'true') ? 1 : 0
72
+ end
73
+
74
+ def re_init # for testing with changed ENV vars
75
+ initialize
76
+ end
77
+
78
+ def array_for_oboe
79
+ [
80
+ @hostname_alias,
81
+ @debug_level,
82
+ @log_file_path,
83
+ @max_transactions,
84
+ @max_flush_wait_time,
85
+ @events_flush_interval,
86
+ @event_flush_batch_size,
87
+
88
+ @reporter,
89
+ @host,
90
+ @service_key,
91
+ @trusted_path,
92
+ @buffer_size,
93
+ @trace_metrics,
94
+ @histogram_precision,
95
+ @token_bucket_capacity,
96
+ @token_bucket_rate,
97
+ @file_single
98
+ ]
99
+ end
100
+
101
+ def service_key_ok?
102
+ return !@service_key.empty? || @reporter != 'ssl'
103
+ end
104
+
105
+ private
106
+
107
+ def reporter_and_host
108
+
109
+ reporter = ENV['APPOPTICS_REPORTER'] || 'ssl'
110
+ # override with 'file', e.g. when running tests
111
+ reporter = 'file' if ENV.key?('APPOPTICS_GEM_TEST')
112
+
113
+ host = ''
114
+ case reporter
115
+ when 'ssl', 'file'
116
+ host = ENV['APPOPTICS_COLLECTOR'] || ''
117
+ when 'udp'
118
+ host = ENV['APPOPTICS_COLLECTOR'] ||
119
+ "#{AppOpticsAPM::Config[:reporter_host]}:#{AppOpticsAPM::Config[:reporter_port]}"
120
+ # TODO decide what to do
121
+ # ____ AppOpticsAPM::Config[:reporter_host] and
122
+ # ____ AppOpticsAPM::Config[:reporter_port] were moved here from
123
+ # ____ oboe_metal.rb and are not documented anywhere
124
+ when 'null'
125
+ host = ''
126
+ end
127
+
128
+ [reporter, host]
129
+ end
130
+
131
+ def read_and_validate_service_key
132
+ return '' unless @reporter == 'ssl'
133
+
134
+ service_key = ENV['APPOPTICS_SERVICE_KEY'] || AppOpticsAPM::Config[:service_key]
135
+ unless service_key
136
+ AppOpticsAPM.logger.error "[appoptics_apm/oboe_options] APPOPTICS_SERVICE_KEY not configured."
137
+ return ''
138
+ end
139
+
140
+ match = service_key.match( /([^:]+)(:{0,1})(.*)/ )
141
+ token = match[1]
142
+ service_name = match[3]
143
+
144
+ return '' unless validate_token(token)
145
+ return '' unless validate_transform_service_name(service_name)
146
+
147
+ return "#{token}:#{service_name}"
148
+ end
149
+
150
+ def validate_token(token)
151
+ if (token !~ /^[0-9a-fA-F]{64}|[0-9a-zA-Z_\-]{71}$/)
152
+ masked = "#{token[0..3]}...#{token[-4..-1]}"
153
+ AppOpticsAPM.logger.error "[appoptics_apm/oboe_options] APPOPTICS_SERVICE_KEY problem. API Token in wrong format. Masked token: #{masked}"
154
+ return false
155
+ end
156
+
157
+ true
158
+ end
159
+
160
+ def validate_transform_service_name(service_name)
161
+ if service_name.empty?
162
+ AppOpticsAPM.logger.error "[appoptics_apm/oboe_options] APPOPTICS_SERVICE_KEY problem. Service Name is missing"
163
+ return false
164
+ end
165
+
166
+ name = service_name.dup
167
+ name.downcase!
168
+ name.gsub!(/[^a-z0-9.:_-]/, '')
169
+ name = name[0..254]
170
+
171
+ if name != service_name
172
+ AppOpticsAPM.logger.warn "[appoptics_apm/oboe_options] APPOPTICS_SERVICE_KEY problem. Service Name transformed from #{service_name} to #{name}"
173
+ service_name = name
174
+ end
175
+ @service_name = service_name # instance variable used in testing
176
+ true
177
+ end
178
+ end
179
+ end
180
+
@@ -17,7 +17,7 @@ AO_TRACING_DECISIONS_QUEUE_FULL = 5
17
17
 
18
18
  module AppOpticsAPM
19
19
  ##
20
- # This module helps with setting up the filters and applying them
20
+ # This module helps with setting up the transaction filters and applying them
21
21
  #
22
22
  class TransactionSettings
23
23
 
@@ -40,8 +40,9 @@ module AppOpticsAPM
40
40
  return
41
41
  end
42
42
 
43
- if AppOpticsAPM.tracing_disabled? && !tracing_enabled?(url) ||
43
+ if tracing_mode_disabled? && !tracing_enabled?(url) ||
44
44
  tracing_disabled?(url)
45
+
45
46
  tracing_mode = AO_TRACING_DISABLED
46
47
  end
47
48
 
@@ -65,6 +66,14 @@ module AppOpticsAPM
65
66
  end
66
67
 
67
68
  private
69
+
70
+ ##
71
+ # check the config setting for :tracing_mode
72
+ def tracing_mode_disabled?
73
+ AppOpticsAPM::Config[:tracing_mode] &&
74
+ [:disabled, :never].include?(AppOpticsAPM::Config[:tracing_mode])
75
+ end
76
+
68
77
  ##
69
78
  # tracing_enabled?
70
79
  #
@@ -6,9 +6,9 @@ module AppOpticsAPM
6
6
  # The current version of the gem. Used mainly by
7
7
  # appoptics_apm.gemspec during gem build process
8
8
  module Version
9
- MAJOR = 4
10
- MINOR = 7
11
- PATCH = 0
9
+ MAJOR = 4 # breaking,
10
+ MINOR = 8 # feature,
11
+ PATCH = 0 # fix => BFF
12
12
 
13
13
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
14
14
  end
data/lib/oboe_metal.rb CHANGED
@@ -18,25 +18,12 @@ module AppOpticsAPM
18
18
  # Start the AppOpticsAPM Reporter
19
19
  #
20
20
  def start
21
+ AppOpticsAPM.loaded = false unless AppOpticsAPM::OboeInitOptions.instance.service_key_ok?
21
22
  return unless AppOpticsAPM.loaded
22
23
 
23
24
  begin
24
- options = []
25
-
26
- ENV['APPOPTICS_REPORTER'] = 'file' if ENV.key?('APPOPTICS_GEM_TEST')
27
-
28
- case ENV['APPOPTICS_REPORTER']
29
- when 'file'
30
- ENV['APPOPTICS_REPORTER_FILE'] = TRACE_FILE
31
- when 'udp'
32
- ENV['APPOPTICS_REPORTER_UDP'] = "#{AppOpticsAPM::Config[:reporter_host]}:#{AppOpticsAPM::Config[:reporter_port]}"
33
- else # default is ssl, service_key is mandatory
34
- return unless valid_service_key?
35
- # Oboe will override these settings if there are env settings for them
36
- options << AppOpticsAPM::Config[:service_key].to_s
37
- options << AppOpticsAPM::Config[:hostname_alias].to_s
38
- options << AppOpticsAPM::Config[:debug_level] unless AppOpticsAPM::Config[:debug_level].nil?
39
- end
25
+ options = AppOpticsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
26
+
40
27
  AppOpticsAPM.reporter = Oboe_metal::Reporter.new(*options)
41
28
 
42
29
  # Only report __Init from here if we are not instrumenting a framework.
@@ -52,19 +39,6 @@ module AppOpticsAPM
52
39
  end
53
40
  alias :restart :start
54
41
 
55
- def valid_service_key?
56
- service_key = (ENV['APPOPTICS_SERVICE_KEY'] || AppOpticsAPM::Config[:service_key]).to_s
57
- if service_key == ''
58
- AppOpticsAPM.logger.warn '[appoptics_apm/warn] APPOPTICS_SERVICE_KEY not set. Cannot submit data.'
59
- AppOpticsAPM.loaded = false
60
- return false
61
- elsif service_key !~ /^[0-9a-fA-F]{64}:[-.:_?\\\/\w ]{1,255}$/
62
- AppOpticsAPM.logger.warn '[appoptics_apm/warn] APPOPTICS_SERVICE_KEY problem. No service name or api token in wrong format. Cannot submit data.'
63
- AppOpticsAPM.loaded = false
64
- return false
65
- end
66
- true
67
- end
68
42
  ##
69
43
  # sendReport
70
44
  #
@@ -89,7 +63,7 @@ module AppOpticsAPM
89
63
  # Truncates the trace output file to zero
90
64
  #
91
65
  def clear_all_traces
92
- File.truncate(TRACE_FILE, 0)
66
+ File.truncate(AppOpticsAPM::OboeInitOptions.instance.host, 0)
93
67
  end
94
68
 
95
69
  ##
@@ -98,14 +72,14 @@ module AppOpticsAPM
98
72
  # Retrieves all traces written to the trace file
99
73
  #
100
74
  def get_all_traces
101
- io = File.open(TRACE_FILE, 'r')
75
+ io = File.open(AppOpticsAPM::OboeInitOptions.instance.host, 'r')
102
76
  contents = io.readlines(nil)
77
+ io.close
103
78
 
104
79
  return contents if contents.empty?
105
80
 
106
81
  traces = []
107
82
 
108
- #
109
83
  # We use Gem.loaded_spec because older versions of the bson
110
84
  # gem didn't even have a version embedded in the gem. If the
111
85
  # gem isn't in the bundle, it should rightfully error out
@@ -140,49 +114,49 @@ module AppOpticsAPM
140
114
  end
141
115
 
142
116
  class << self
143
- def sample?(opts = {})
144
- # Return false if no-op mode
145
- return false unless AppOpticsAPM.loaded
146
-
147
- # Assure defaults since SWIG enforces Strings
148
- xtrace = opts[:xtrace] ? opts[:xtrace].to_s.strip : APPOPTICS_STR_BLANK
149
-
150
- # the first arg has changed to be the service name, blank means to use the default (from the service key)
151
- rv = AppOpticsAPM::Context.sampleRequest(APPOPTICS_STR_BLANK, xtrace)
152
-
153
- if rv == 0
154
- AppOpticsAPM.sample_rate = -1
155
- AppOpticsAPM.sample_source = -1
156
- false
157
- else
158
- # liboboe version > 1.3.1 returning a bit masked integer with SampleRate and
159
- # source embedded
160
- AppOpticsAPM.sample_rate = (rv & SAMPLE_RATE_MASK)
161
- AppOpticsAPM.sample_source = (rv & SAMPLE_SOURCE_MASK) >> 24
162
- true
163
- end
164
- rescue StandardError => e
165
- AppOpticsAPM.logger.debug "[oboe/error] sample? error: #{e.inspect}"
166
- false
167
- end
168
-
169
- def set_tracing_mode(mode)
170
- return unless AppOpticsAPM.loaded
171
-
172
- value = mode.to_sym
173
-
174
- case value
175
- when :disabled, :never
176
- AppOpticsAPM::Context.setTracingMode(APPOPTICS_TRACE_DISABLED)
177
-
178
- when :enabled, :always
179
- AppOpticsAPM::Context.setTracingMode(APPOPTICS_TRACE_ENABLED)
180
-
181
- else
182
- AppOpticsAPM.logger.fatal "[oboe/error] Invalid tracing mode set: #{mode}"
183
- AppOpticsAPM::Context.setTracingMode(APPOPTICS_TRACE_DISABLED)
184
- end
185
- end
117
+ # def sample?(opts = {})
118
+ # # Return false if no-op mode
119
+ # return false unless AppOpticsAPM.loaded
120
+ #
121
+ # # Assure defaults since SWIG enforces Strings
122
+ # xtrace = opts[:xtrace] ? opts[:xtrace].to_s.strip : APPOPTICS_STR_BLANK
123
+ #
124
+ # # the first arg has changed to be the service name, blank means to use the default (from the service key)
125
+ # rv = AppOpticsAPM::Context.sampleRequest(APPOPTICS_STR_BLANK, xtrace)
126
+ #
127
+ # if rv == 0
128
+ # AppOpticsAPM.sample_rate = -1
129
+ # AppOpticsAPM.sample_source = -1
130
+ # false
131
+ # else
132
+ # # liboboe version > 1.3.1 returning a bit masked integer with SampleRate and
133
+ # # source embedded
134
+ # AppOpticsAPM.sample_rate = (rv & SAMPLE_RATE_MASK)
135
+ # AppOpticsAPM.sample_source = (rv & SAMPLE_SOURCE_MASK) >> 24
136
+ # true
137
+ # end
138
+ # rescue StandardError => e
139
+ # AppOpticsAPM.logger.debug "[oboe/error] sample? error: #{e.inspect}"
140
+ # false
141
+ # end
142
+
143
+ # def set_tracing_mode(mode)
144
+ # return unless AppOpticsAPM.loaded
145
+ #
146
+ # value = mode.to_sym
147
+ #
148
+ # case value
149
+ # when :disabled, :never
150
+ # AppOpticsAPM::Context.setTracingMode(APPOPTICS_TRACE_DISABLED)
151
+ #
152
+ # when :enabled, :always
153
+ # AppOpticsAPM::Context.setTracingMode(APPOPTICS_TRACE_ENABLED)
154
+ #
155
+ # else
156
+ # AppOpticsAPM.logger.fatal "[oboe/error] Invalid tracing mode set: #{mode}"
157
+ # AppOpticsAPM::Context.setTracingMode(APPOPTICS_TRACE_DISABLED)
158
+ # end
159
+ # end
186
160
 
187
161
  def set_sample_rate(rate)
188
162
  return unless AppOpticsAPM.loaded
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appoptics_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maia Engeli
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-23 00:00:00.000000000 Z
13
+ date: 2019-05-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -208,6 +208,7 @@ files:
208
208
  - lib/appoptics_apm/noop/README.md
209
209
  - lib/appoptics_apm/noop/context.rb
210
210
  - lib/appoptics_apm/noop/metadata.rb
211
+ - lib/appoptics_apm/oboe_init_options.rb
211
212
  - lib/appoptics_apm/ruby.rb
212
213
  - lib/appoptics_apm/sdk/current_trace.rb
213
214
  - lib/appoptics_apm/sdk/custom_metrics.rb