appoptics_apm-zearn 4.13.1

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 (145) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +5 -0
  3. data/.github/ISSUE_TEMPLATE/bug-or-feature-request.md +16 -0
  4. data/.github/workflows/build_and_release_gem.yml +103 -0
  5. data/.github/workflows/build_for_packagecloud.yml +70 -0
  6. data/.github/workflows/docker-images.yml +47 -0
  7. data/.github/workflows/run_cpluplus_tests.yml +73 -0
  8. data/.github/workflows/run_tests.yml +168 -0
  9. data/.github/workflows/scripts/test_install.rb +23 -0
  10. data/.github/workflows/swig/swig-v4.0.2.tar.gz +0 -0
  11. data/.github/workflows/test_on_4_linux.yml +159 -0
  12. data/.gitignore +36 -0
  13. data/.rubocop.yml +29 -0
  14. data/.travis.yml +130 -0
  15. data/.yardopts +6 -0
  16. data/CHANGELOG.md +769 -0
  17. data/CONFIG.md +33 -0
  18. data/Gemfile +14 -0
  19. data/LICENSE +202 -0
  20. data/README.md +393 -0
  21. data/appoptics_apm.gemspec +70 -0
  22. data/bin/appoptics_apm_config +15 -0
  23. data/examples/prepend.rb +13 -0
  24. data/examples/sdk_examples.rb +158 -0
  25. data/ext/oboe_metal/README.md +69 -0
  26. data/ext/oboe_metal/extconf.rb +151 -0
  27. data/ext/oboe_metal/lib/.keep +0 -0
  28. data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.0.0.0.sha256 +1 -0
  29. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.0.0.0.sha256 +1 -0
  30. data/ext/oboe_metal/noop/noop.c +8 -0
  31. data/ext/oboe_metal/src/README.md +6 -0
  32. data/ext/oboe_metal/src/VERSION +2 -0
  33. data/ext/oboe_metal/src/bson/bson.h +220 -0
  34. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  35. data/ext/oboe_metal/src/frames.cc +246 -0
  36. data/ext/oboe_metal/src/frames.h +40 -0
  37. data/ext/oboe_metal/src/init_appoptics_apm.cc +21 -0
  38. data/ext/oboe_metal/src/logging.cc +95 -0
  39. data/ext/oboe_metal/src/logging.h +35 -0
  40. data/ext/oboe_metal/src/oboe.h +1156 -0
  41. data/ext/oboe_metal/src/oboe_api.cpp +652 -0
  42. data/ext/oboe_metal/src/oboe_api.hpp +431 -0
  43. data/ext/oboe_metal/src/oboe_debug.h +59 -0
  44. data/ext/oboe_metal/src/oboe_swig_wrap.cc +7329 -0
  45. data/ext/oboe_metal/src/profiling.cc +435 -0
  46. data/ext/oboe_metal/src/profiling.h +78 -0
  47. data/ext/oboe_metal/test/CMakeLists.txt +53 -0
  48. data/ext/oboe_metal/test/FindGMock.cmake +43 -0
  49. data/ext/oboe_metal/test/README.md +56 -0
  50. data/ext/oboe_metal/test/frames_test.cc +164 -0
  51. data/ext/oboe_metal/test/profiling_test.cc +93 -0
  52. data/ext/oboe_metal/test/ruby_inc_dir.rb +8 -0
  53. data/ext/oboe_metal/test/ruby_prefix.rb +8 -0
  54. data/ext/oboe_metal/test/ruby_test_helper.rb +67 -0
  55. data/ext/oboe_metal/test/test.h +11 -0
  56. data/ext/oboe_metal/test/test_main.cc +32 -0
  57. data/init.rb +4 -0
  58. data/lib/appoptics_apm/api/layerinit.rb +41 -0
  59. data/lib/appoptics_apm/api/logging.rb +381 -0
  60. data/lib/appoptics_apm/api/memcache.rb +37 -0
  61. data/lib/appoptics_apm/api/metrics.rb +63 -0
  62. data/lib/appoptics_apm/api/tracing.rb +57 -0
  63. data/lib/appoptics_apm/api/util.rb +120 -0
  64. data/lib/appoptics_apm/api.rb +21 -0
  65. data/lib/appoptics_apm/base.rb +231 -0
  66. data/lib/appoptics_apm/config.rb +299 -0
  67. data/lib/appoptics_apm/frameworks/grape.rb +98 -0
  68. data/lib/appoptics_apm/frameworks/padrino.rb +78 -0
  69. data/lib/appoptics_apm/frameworks/rails/inst/action_controller.rb +104 -0
  70. data/lib/appoptics_apm/frameworks/rails/inst/action_controller4.rb +48 -0
  71. data/lib/appoptics_apm/frameworks/rails/inst/action_controller5.rb +50 -0
  72. data/lib/appoptics_apm/frameworks/rails/inst/action_controller6.rb +50 -0
  73. data/lib/appoptics_apm/frameworks/rails/inst/action_controller_api.rb +50 -0
  74. data/lib/appoptics_apm/frameworks/rails/inst/action_view.rb +88 -0
  75. data/lib/appoptics_apm/frameworks/rails/inst/active_record.rb +27 -0
  76. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  77. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +29 -0
  78. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +31 -0
  79. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +119 -0
  80. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +114 -0
  81. data/lib/appoptics_apm/frameworks/rails/inst/logger_formatters.rb +27 -0
  82. data/lib/appoptics_apm/frameworks/rails.rb +100 -0
  83. data/lib/appoptics_apm/frameworks/sinatra.rb +96 -0
  84. data/lib/appoptics_apm/inst/bunny-client.rb +148 -0
  85. data/lib/appoptics_apm/inst/bunny-consumer.rb +89 -0
  86. data/lib/appoptics_apm/inst/curb.rb +332 -0
  87. data/lib/appoptics_apm/inst/dalli.rb +85 -0
  88. data/lib/appoptics_apm/inst/delayed_job.rb +92 -0
  89. data/lib/appoptics_apm/inst/em-http-request.rb +101 -0
  90. data/lib/appoptics_apm/inst/excon.rb +125 -0
  91. data/lib/appoptics_apm/inst/faraday.rb +106 -0
  92. data/lib/appoptics_apm/inst/graphql.rb +240 -0
  93. data/lib/appoptics_apm/inst/grpc_client.rb +159 -0
  94. data/lib/appoptics_apm/inst/grpc_server.rb +120 -0
  95. data/lib/appoptics_apm/inst/http.rb +81 -0
  96. data/lib/appoptics_apm/inst/httpclient.rb +174 -0
  97. data/lib/appoptics_apm/inst/logger_formatter.rb +50 -0
  98. data/lib/appoptics_apm/inst/logging_log_event.rb +28 -0
  99. data/lib/appoptics_apm/inst/lumberjack_formatter.rb +13 -0
  100. data/lib/appoptics_apm/inst/memcached.rb +86 -0
  101. data/lib/appoptics_apm/inst/mongo.rb +246 -0
  102. data/lib/appoptics_apm/inst/mongo2.rb +225 -0
  103. data/lib/appoptics_apm/inst/moped.rb +466 -0
  104. data/lib/appoptics_apm/inst/rack.rb +182 -0
  105. data/lib/appoptics_apm/inst/rack_cache.rb +35 -0
  106. data/lib/appoptics_apm/inst/redis.rb +274 -0
  107. data/lib/appoptics_apm/inst/resque.rb +151 -0
  108. data/lib/appoptics_apm/inst/rest-client.rb +48 -0
  109. data/lib/appoptics_apm/inst/sequel.rb +178 -0
  110. data/lib/appoptics_apm/inst/sidekiq-client.rb +55 -0
  111. data/lib/appoptics_apm/inst/sidekiq-worker.rb +66 -0
  112. data/lib/appoptics_apm/inst/twitter-cassandra.rb +294 -0
  113. data/lib/appoptics_apm/inst/typhoeus.rb +108 -0
  114. data/lib/appoptics_apm/instrumentation.rb +22 -0
  115. data/lib/appoptics_apm/loading.rb +65 -0
  116. data/lib/appoptics_apm/logger.rb +14 -0
  117. data/lib/appoptics_apm/noop/README.md +9 -0
  118. data/lib/appoptics_apm/noop/context.rb +27 -0
  119. data/lib/appoptics_apm/noop/metadata.rb +25 -0
  120. data/lib/appoptics_apm/noop/profiling.rb +21 -0
  121. data/lib/appoptics_apm/oboe_init_options.rb +211 -0
  122. data/lib/appoptics_apm/ruby.rb +35 -0
  123. data/lib/appoptics_apm/sdk/current_trace.rb +77 -0
  124. data/lib/appoptics_apm/sdk/custom_metrics.rb +94 -0
  125. data/lib/appoptics_apm/sdk/logging.rb +37 -0
  126. data/lib/appoptics_apm/sdk/tracing.rb +434 -0
  127. data/lib/appoptics_apm/support/profiling.rb +18 -0
  128. data/lib/appoptics_apm/support/transaction_metrics.rb +67 -0
  129. data/lib/appoptics_apm/support/transaction_settings.rb +219 -0
  130. data/lib/appoptics_apm/support/x_trace_options.rb +110 -0
  131. data/lib/appoptics_apm/support_report.rb +119 -0
  132. data/lib/appoptics_apm/test.rb +95 -0
  133. data/lib/appoptics_apm/thread_local.rb +26 -0
  134. data/lib/appoptics_apm/util.rb +326 -0
  135. data/lib/appoptics_apm/version.rb +16 -0
  136. data/lib/appoptics_apm/xtrace.rb +115 -0
  137. data/lib/appoptics_apm.rb +77 -0
  138. data/lib/joboe_metal.rb +212 -0
  139. data/lib/oboe.rb +7 -0
  140. data/lib/oboe_metal.rb +172 -0
  141. data/lib/rails/generators/appoptics_apm/install_generator.rb +47 -0
  142. data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +425 -0
  143. data/log/.keep +0 -0
  144. data/yardoc_frontpage.md +26 -0
  145. metadata +231 -0
@@ -0,0 +1,212 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ module Oboe_metal
5
+ include_package 'com.tracelytics.joboe'
6
+ java_import 'com.tracelytics.joboe.LayerUtil'
7
+ java_import 'com.tracelytics.joboe.SettingsReader'
8
+ java_import 'com.tracelytics.joboe.Context'
9
+ java_import 'com.tracelytics.joboe.Event'
10
+ java_import 'com.tracelytics.agent.Agent'
11
+
12
+ class Context
13
+ class << self
14
+ def toString
15
+ getMetadata.toHexString
16
+ end
17
+
18
+ def fromString(xtrace)
19
+ Context.setMetadata(xtrace)
20
+ end
21
+
22
+ def clear
23
+ clearMetadata
24
+ end
25
+
26
+ def get
27
+ getMetadata
28
+ end
29
+ end
30
+ end
31
+
32
+ module EventUtil
33
+ def self.metadataString(evt)
34
+ evt.getMetadata.toHexString
35
+ end
36
+ end
37
+
38
+ def UdpReporter
39
+ Java::ComTracelyticsJoboe
40
+ end
41
+
42
+ module Metadata
43
+ Java::ComTracelyticsJoboeMetaData
44
+ end
45
+
46
+ module Reporter
47
+ class << self
48
+ ##
49
+ # start
50
+ #
51
+ # Start the AppOpticsAPM Reporter
52
+ #
53
+ def start
54
+ return unless AppOpticsAPM.loaded
55
+
56
+ if ENV.key?('APPOPTICS_GEM_TEST')
57
+ AppOpticsAPM.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance.buildTestReporter(false)
58
+ else
59
+ AppOpticsAPM.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance.buildUdpReporter
60
+ end
61
+
62
+ begin
63
+ # Import the tracing mode and sample rate settings
64
+ # from the Java agent (user configured in
65
+ # /usr/local/tracelytics/javaagent.json when under JRuby)
66
+ cfg = LayerUtil.getLocalSampleRate(nil, nil)
67
+
68
+ if cfg.hasSampleStartFlag
69
+ AppOpticsAPM::Config.tracing_mode = :enabled
70
+ else
71
+ AppOpticsAPM::Config.tracing_mode = :disabled
72
+ end
73
+
74
+ AppOpticsAPM.sample_rate = cfg.getSampleRate
75
+ AppOpticsAPM::Config.sample_rate = cfg.sampleRate
76
+ AppOpticsAPM::Config.sample_source = cfg.sampleRateSourceValue
77
+ rescue => e
78
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] Couldn't retrieve/acces joboe sampleRateCfg"
79
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{e.message}"
80
+ end
81
+
82
+ # Only report __Init from here if we are not instrumenting a framework.
83
+ # Otherwise, frameworks will handle reporting __Init after full initialization
84
+ unless defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
85
+ AppOpticsAPM::API.report_init unless ENV.key?('APPOPTICS_GEM_TEST')
86
+ end
87
+ end
88
+
89
+ ##
90
+ # restart
91
+ #
92
+ # This is a nil method for AppOpticsAPM under Java. It is maintained only
93
+ # for compability across interfaces.
94
+ #
95
+ def restart
96
+ AppOpticsAPM.logger.warn "[appoptics_apm/reporter] Reporter.restart isn't supported under JRuby"
97
+ end
98
+
99
+ ##
100
+ # clear_all_traces
101
+ #
102
+ # Truncates the trace output file to zero
103
+ #
104
+ def clear_all_traces
105
+ AppOpticsAPM.reporter.reset if AppOpticsAPM.loaded
106
+ end
107
+
108
+ ##
109
+ # get_all_traces
110
+ #
111
+ # Retrieves all traces written to the trace file
112
+ #
113
+ def get_all_traces
114
+ return [] unless AppOpticsAPM.loaded
115
+
116
+ # Joboe TestReporter returns a Java::ComTracelyticsExtEbson::DefaultDocument
117
+ # document for traces which doesn't correctly support things like has_key? which
118
+ # raises an unhandled exception on non-existent key (duh). Here we convert
119
+ # the Java::ComTracelyticsExtEbson::DefaultDocument doc to a pure array of Ruby
120
+ # hashes
121
+ traces = []
122
+ AppOpticsAPM.reporter.getSentEventsAsBsonDocument.to_a.each do |e|
123
+ t = {}
124
+ e.each_pair { |k, v|
125
+ t[k] = v
126
+ }
127
+ traces << t
128
+ end
129
+ traces
130
+ end
131
+
132
+ def sendReport(evt)
133
+ evt.report(AppOpticsAPM.reporter)
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ module AppOpticsAPM
140
+ extend AppOpticsAPMBase
141
+ include Oboe_metal
142
+
143
+ class << self
144
+ def sample?(opts = {})
145
+ begin
146
+ # Return false if no-op mode
147
+ return false unless AppOpticsAPM.loaded
148
+
149
+ return true if ENV.key?('APPOPTICS_GEM_TEST')
150
+
151
+ # Validation to make Joboe happy. Assure that we have the KVs and that they
152
+ # are not empty strings.
153
+ opts[:xtrace] = nil if opts[:xtrace].is_a?(String) && opts[:xtrace].empty?
154
+
155
+ opts[:xtrace] ||= nil
156
+
157
+ sr_cfg = Java::ComTracelyticsJoboe::LayerUtil.shouldTraceRequest(APPOPTICS_STR_BLANK, { 'X-Trace' => opts[:xtrace] })
158
+
159
+ # Store the returned SampleRateConfig into AppOpticsAPM::Config
160
+ if sr_cfg
161
+ begin
162
+ AppOpticsAPM::Config.sample_rate = sr_cfg.sampleRate
163
+ AppOpticsAPM::Config.sample_source = sr_cfg.sampleRateSourceValue
164
+ # If we fail here, we do so quietly. This was we don't spam logs
165
+ # on every request
166
+ end
167
+ else
168
+ AppOpticsAPM.sample_rate = -1
169
+ AppOpticsAPM.sample_source = -1
170
+ end
171
+
172
+ sr_cfg ? true : false
173
+ rescue => e
174
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{e.message}"
175
+ false
176
+ end
177
+ end
178
+
179
+ def set_tracing_mode(_mode)
180
+ AppOpticsAPM.logger.warn '[appoptics_apm/joboe] When using JRuby set the tracing mode in /usr/local/tracelytics/javaagent.json instead'
181
+ end
182
+
183
+ def set_sample_rate(_rate)
184
+ # N/A
185
+ end
186
+ end
187
+ end
188
+
189
+ # Assure that the Joboe Java Agent was loaded via premain
190
+ case Java::ComTracelyticsAgent::Agent.getStatus
191
+ when Java::ComTracelyticsAgent::Agent::AgentStatus::INITIALIZED_SUCCESSFUL
192
+ AppOpticsAPM.loaded = true
193
+
194
+ when Java::ComTracelyticsAgent::Agent::AgentStatus::INITIALIZED_FAILED
195
+ AppOpticsAPM.loaded = false
196
+ $stderr.puts '=============================================================='
197
+ $stderr.puts 'AppOpticsAPM Java Agent not initialized properly.'
198
+ $stderr.puts 'Possibly misconfigured? Going into no-op mode.'
199
+ $stderr.puts 'http://docs.appoptics.solarwinds.com/Instrumentation/other-instrumentation-modules.html#jruby'
200
+ $stderr.puts '=============================================================='
201
+
202
+ when Java::ComTracelyticsAgent::Agent::AgentStatus::UNINITIALIZED
203
+ AppOpticsAPM.loaded = false
204
+ $stderr.puts '=============================================================='
205
+ $stderr.puts 'AppOpticsAPM Java Agent not loaded. Going into no-op mode.'
206
+ $stderr.puts 'To preload the AppOpticsAPM java agent see:'
207
+ $stderr.puts 'http://docs.appoptics.solarwinds.com/Instrumentation/other-instrumentation-modules.html#jruby'
208
+ $stderr.puts '=============================================================='
209
+
210
+ else
211
+ AppOpticsAPM.loaded = false
212
+ end
data/lib/oboe.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ # This module is provided for backward compatibility.
5
+ # It simply redirects to the appoptics_apm module which will
6
+ # also load backward compatibility support.
7
+ require 'appoptics_apm'
data/lib/oboe_metal.rb ADDED
@@ -0,0 +1,172 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ require 'thread'
5
+
6
+ # Disable docs and Camelcase warns since we're implementing
7
+ # an interface here. See OboeBase for details.
8
+ # rubocop:disable Style/Documentation, Naming/MethodName
9
+ module AppOpticsAPM
10
+ extend AppOpticsAPMBase
11
+ include Oboe_metal
12
+
13
+ class Reporter
14
+ class << self
15
+ ##
16
+ # start
17
+ #
18
+ # Start the AppOpticsAPM Reporter
19
+ #
20
+ def start
21
+ AppOpticsAPM.loaded = false unless AppOpticsAPM::OboeInitOptions.instance.service_key_ok?
22
+ return unless AppOpticsAPM.loaded
23
+
24
+ begin
25
+ options = AppOpticsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
26
+
27
+ AppOpticsAPM.reporter = Oboe_metal::Reporter.new(*options)
28
+
29
+ # Only report __Init from here if we are not instrumenting a framework.
30
+ # Otherwise, frameworks will handle reporting __Init after full initialization
31
+ unless defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
32
+ AppOpticsAPM::API.report_init
33
+ end
34
+
35
+ rescue => e
36
+ $stderr.puts e.message
37
+ raise
38
+ end
39
+ end
40
+ alias :restart :start
41
+
42
+ ##
43
+ # sendReport
44
+ #
45
+ # Send the report for the given event
46
+ #
47
+ def sendReport(evt)
48
+ AppOpticsAPM.reporter.sendReport(evt)
49
+ end
50
+
51
+ ##
52
+ # sendStatus
53
+ #
54
+ # Send the report for the given event
55
+ #
56
+ def sendStatus(evt, context = nil)
57
+ AppOpticsAPM.reporter.sendStatus(evt, context)
58
+ end
59
+
60
+ ##
61
+ # clear_all_traces
62
+ #
63
+ # Truncates the trace output file to zero
64
+ #
65
+ def clear_all_traces
66
+ File.truncate(AppOpticsAPM::OboeInitOptions.instance.host, 0)
67
+ end
68
+
69
+ ##
70
+ # get_all_traces
71
+ #
72
+ # Retrieves all traces written to the trace file
73
+ #
74
+ def get_all_traces
75
+ io = File.open(AppOpticsAPM::OboeInitOptions.instance.host, 'r')
76
+ contents = io.readlines(nil)
77
+ io.close
78
+
79
+ return contents if contents.empty?
80
+
81
+ traces = []
82
+
83
+ # We use Gem.loaded_spec because older versions of the bson
84
+ # gem didn't even have a version embedded in the gem. If the
85
+ # gem isn't in the bundle, it should rightfully error out
86
+ # anyways.
87
+ #
88
+ if Gem.loaded_specs['bson'] && Gem.loaded_specs['bson'].version.to_s < '4.0'
89
+ s = StringIO.new(contents[0])
90
+
91
+ until s.eof?
92
+ traces << if ::BSON.respond_to? :read_bson_document
93
+ BSON.read_bson_document(s)
94
+ else
95
+ BSON::Document.from_bson(s)
96
+ end
97
+ end
98
+ else
99
+ bbb = ::BSON::ByteBuffer.new(contents[0])
100
+ until bbb.length == 0
101
+ traces << Hash.from_bson(bbb)
102
+ end
103
+ end
104
+
105
+ traces
106
+ end
107
+ end
108
+ end
109
+
110
+ module EventUtil
111
+ def self.metadataString(evt)
112
+ evt.metadataString
113
+ end
114
+ end
115
+
116
+ class << self
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
160
+
161
+ def set_sample_rate(rate)
162
+ return unless AppOpticsAPM.loaded
163
+
164
+ # Update liboboe with the new SampleRate value
165
+ AppOpticsAPM::Context.setDefaultSampleRate(rate.to_i)
166
+ end
167
+ end
168
+ end
169
+ # rubocop:enable Style/Documentation
170
+
171
+ AppOpticsAPM.loaded = true
172
+ AppOpticsAPM.config_lock = Mutex.new
@@ -0,0 +1,47 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ module AppOpticsAPM
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ source_root File.join(File.dirname(__FILE__), 'templates')
7
+ desc "Copies a AppOpticsAPM gem initializer file to your application."
8
+
9
+ @namespace = "appoptics_apm:install"
10
+
11
+ def copy_initializer
12
+ # Set defaults
13
+ @verbose = 'false'
14
+
15
+ print_header
16
+ print_footer
17
+
18
+ template "appoptics_apm_initializer.rb", "config/initializers/appoptics_apm.rb"
19
+ end
20
+
21
+ private
22
+
23
+ # rubocop:disable Metrics/MethodLength
24
+ def print_header
25
+ say ""
26
+ say shell.set_color "Welcome to the AppOpticsAPM Ruby instrumentation setup.", :green, :bold
27
+ say ""
28
+ say shell.set_color "Documentation Links", :magenta
29
+ say "-------------------"
30
+ say ""
31
+ say "AppOpticsAPM Installation Overview:"
32
+ say "http://docs.appoptics.solarwinds.com/AppOpticsAPM/install-instrumentation.html"
33
+ say ""
34
+ say "More information on instrumenting Ruby applications can be found here:"
35
+ say "http://docs.appoptics.solarwinds.com/Instrumentation/ruby.html#installing-ruby-instrumentation"
36
+ end
37
+ # rubocop:enable Metrics/MethodLength
38
+
39
+ def print_footer
40
+ say ""
41
+ say "You can change configuration values in the future by modifying config/initializers/appoptics_apm.rb"
42
+ say ""
43
+ say "Thanks! Creating the AppOpticsAPM initializer..."
44
+ say ""
45
+ end
46
+ end
47
+ end