appoptics_apm 4.2.2 → 4.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -3
- data/Gemfile +0 -2
- data/README.md +119 -95
- data/examples/SDK/01_basic_tracing.rb +67 -0
- data/ext/oboe_metal/src/VERSION +1 -1
- data/lib/appoptics_apm/api.rb +10 -9
- data/lib/appoptics_apm/api/layerinit.rb +1 -1
- data/lib/appoptics_apm/api/logging.rb +41 -14
- data/lib/appoptics_apm/api/metrics.rb +34 -0
- data/lib/appoptics_apm/api/profiling.rb +5 -0
- data/lib/appoptics_apm/api/tracing.rb +33 -148
- data/lib/appoptics_apm/api/util.rb +3 -9
- data/lib/appoptics_apm/base.rb +11 -12
- data/lib/appoptics_apm/frameworks/padrino/templates.rb +1 -1
- data/lib/appoptics_apm/frameworks/rails.rb +1 -1
- data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +1 -1
- data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +1 -1
- data/lib/appoptics_apm/inst/bunny-consumer.rb +1 -2
- data/lib/appoptics_apm/inst/delayed_job.rb +4 -4
- data/lib/appoptics_apm/inst/em-http-request.rb +1 -1
- data/lib/appoptics_apm/inst/rack.rb +1 -0
- data/lib/appoptics_apm/inst/redis.rb +1 -1
- data/lib/appoptics_apm/inst/resque.rb +1 -1
- data/lib/appoptics_apm/inst/sidekiq-worker.rb +1 -3
- data/lib/appoptics_apm/loading.rb +3 -4
- data/lib/appoptics_apm/logger.rb +1 -1
- data/lib/appoptics_apm/sdk.rb +317 -0
- data/lib/appoptics_apm/support.rb +0 -17
- data/lib/appoptics_apm/test.rb +1 -1
- data/lib/appoptics_apm/util.rb +4 -3
- data/lib/appoptics_apm/version.rb +1 -1
- data/lib/appoptics_apm/xtrace.rb +3 -3
- data/lib/joboe_metal.rb +2 -4
- data/lib/oboe_metal.rb +5 -5
- data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +5 -4
- data/run_tests_docker.rb +6 -0
- metadata +5 -9
- data/examples/DNT.md +0 -35
- data/examples/instrumenting_metal_controller.rb +0 -8
- data/examples/puma_on_heroku_config.rb +0 -17
- data/examples/tracing_async_threads.rb +0 -124
- data/examples/tracing_background_jobs.rb +0 -53
- data/examples/tracing_forked_processes.rb +0 -99
- data/examples/unicorn_on_heroku_config.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 984f806c1810b83b4528e75fd4a4e7b48db4bfa7
|
4
|
+
data.tar.gz: 77acebf5def90972f7bbaa165bdcb4fa5d603442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ddf576b6e8d1ee6d638064e9573bf2461fa34fde1140c9eb63eb193d7540e7d383865b9268d96d85285c932a4ebc33d5c6b7178dd2f1164c76e5c54dc9754f0
|
7
|
+
data.tar.gz: bb28f4ca6696d843e9876c32eb277bff52198d90088a680f16468c1e675c1235b09eef5da5432e38ce6c695a01016defb06b92dc3fab0eaa98dfe9290d293d4f
|
data/.yardopts
CHANGED
data/Gemfile
CHANGED
@@ -13,9 +13,7 @@ group :development, :test do
|
|
13
13
|
gem 'rubocop', require: false
|
14
14
|
gem 'ruby-prof'
|
15
15
|
gem 'benchmark-ips'
|
16
|
-
end
|
17
16
|
|
18
|
-
group :development do
|
19
17
|
gem 'ruby-debug', :platforms => [:mri_18, :jruby]
|
20
18
|
gem 'debugger', :platform => :mri_19
|
21
19
|
gem 'byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23, :mri_24]
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# Welcome to the AppOpticsAPM Ruby Gem
|
1
|
+
# Welcome to the AppOpticsAPM Ruby Gem
|
2
2
|
|
3
3
|
The appoptics_apm gem provides [AppOptics APM](https://www.appoptics.com/) performance instrumentation for Ruby.
|
4
4
|
|
5
|
-
![Ruby AppOpticsAPM](
|
5
|
+
![Ruby AppOpticsAPM](https://docs.appoptics.com/_images/ruby_trace.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
|
9
|
-
[and more](
|
9
|
+
[and more](https://docs.appoptics.com/kb/apm_tracing/ruby/support-matrix/).
|
10
10
|
|
11
11
|
It requires an [AppOptics](https://www.appoptics.com/) account to view metrics. Get yours,
|
12
|
-
[it's free](https://
|
12
|
+
[it's free](https://my.appoptics.com/sign_up).
|
13
13
|
|
14
14
|
[![Gem Version](https://badge.fury.io/rb/appoptics_apm.png)](https://badge.fury.io/rb/appoptics_apm)
|
15
15
|
[![Build Status](https://travis-ci.com/librato/ruby-appoptics.png?branch=master)](https://travis-ci.com/librato/ruby-appoptics)
|
@@ -18,6 +18,10 @@ It requires an [AppOptics](https://www.appoptics.com/) account to view metrics.
|
|
18
18
|
_Note: The repository name has been changed to ruby-appoptics. Please update your github remotes with
|
19
19
|
`git remote set-url origin git@github.com:librato/ruby-appoptics.git`._
|
20
20
|
|
21
|
+
# Documentation
|
22
|
+
|
23
|
+
* [AppOptics Knowledge Base](https://docs.appoptics.com/kb/apm_tracing/ruby)
|
24
|
+
|
21
25
|
# Installation
|
22
26
|
|
23
27
|
_Before installing the gem below, make sure that you have the
|
@@ -29,39 +33,26 @@ The appoptics_apm gem is [available on Rubygems](https://rubygems.org/gems/appop
|
|
29
33
|
gem install appoptics_apm
|
30
34
|
```
|
31
35
|
|
32
|
-
or added to
|
36
|
+
or added to **the end** of your Gemfile and running `bundle install`:
|
33
37
|
|
34
38
|
```ruby
|
35
39
|
gem 'appoptics_apm'
|
36
40
|
```
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
source 'https://73bf9c35xxxxxxxxxxb4d26c3:@packagecloud.io/AppOptics/apm-instrumentation/' do
|
42
|
-
gem 'appoptics_apm', '>= 4.0.0'
|
43
|
-
end
|
44
|
-
```
|
45
|
-
Set the env to report to staging (your_app_name can be any string, it is only used as name in the services list):
|
42
|
+
# Running
|
43
|
+
|
44
|
+
Make sure to set `APPOPTICS_SERVICE_KEY` in the environment from where the app or service is run, e.g:
|
46
45
|
```
|
47
|
-
unset APPOPTICS_TRUSTEDPATH
|
48
|
-
export APPOPTICS_COLLECTOR=collector-stg.appoptics.com
|
49
46
|
export APPOPTICS_SERVICE_KEY=795fb4947d15275d208c49cfd2412d4a5bf38742045b47236c94c4fe5f5b17c7:<your_app_name>
|
50
47
|
```
|
51
|
-
If you're reporting to production, only set `APPOPTICS_SERVICE_KEY`
|
52
|
-
|
53
|
-
# Running
|
54
48
|
|
55
49
|
## Rails
|
56
50
|
|
57
|
-
![Ruby on Rails](
|
51
|
+
![Ruby on Rails](https://docs.appoptics.com/_images/rails.png)
|
58
52
|
|
59
53
|
No special steps are needed to instrument Ruby on Rails. Once part of the bundle, the appoptics gem will automatically
|
60
54
|
detect Rails and instrument on stack initialization.
|
61
55
|
|
62
|
-
*Note: You will still need to decide on your `tracing_mode` depending on whether you are running with an instrumented
|
63
|
-
Apache or nginx in front of your Rails stack. See below for more details.*
|
64
|
-
|
65
56
|
### The Install Generator
|
66
57
|
|
67
58
|
The appoptics_apm gem provides a Rails generator used to seed an initializer where you can configure and control
|
@@ -77,7 +68,7 @@ After the prompts, this will create an initializer: `config/initializers/appopti
|
|
77
68
|
|
78
69
|
## Sinatra
|
79
70
|
|
80
|
-
![Sinatra](
|
71
|
+
![Sinatra](https://docs.appoptics.com/_images/sinatra.png)
|
81
72
|
|
82
73
|
You can instrument your Sinatra application by adding the following code to your `config.ru` Rackup file:
|
83
74
|
|
@@ -85,9 +76,6 @@ You can instrument your Sinatra application by adding the following code to your
|
|
85
76
|
# If you're not using Bundler.require. Make sure this is done
|
86
77
|
# after the Sinatra require directive.
|
87
78
|
require 'appoptics_apm'
|
88
|
-
|
89
|
-
AppOpticsAPM
|
90
|
-
AppOpticsAPM
|
91
79
|
```
|
92
80
|
|
93
81
|
Make sure that the appoptics_apm gem is loaded _after_ Sinatra either by listing `gem 'appoptics_apm'` after Sinatra in
|
@@ -97,7 +85,7 @@ With this, the appoptics_apm gem will automatically detect Sinatra on boot and i
|
|
97
85
|
|
98
86
|
## Padrino
|
99
87
|
|
100
|
-
![Padrino](
|
88
|
+
![Padrino](https://docs.appoptics.com/_images/padrino.svg)
|
101
89
|
|
102
90
|
As long as the appoptics_apm gem is in your `Gemfile` (inserted after the `gem 'padrino'` directive) and you are calling
|
103
91
|
`Bundler.require`, the appoptics_apm gem will automatically instrument Padrino applications.
|
@@ -114,7 +102,7 @@ end
|
|
114
102
|
|
115
103
|
## Grape
|
116
104
|
|
117
|
-
![Grape](
|
105
|
+
![Grape](https://docs.appoptics.com/_images/grape.png)
|
118
106
|
|
119
107
|
You can instrument your Grape application by adding the following code to your `config.ru` Rackup file:
|
120
108
|
|
@@ -135,7 +123,8 @@ Gemfile or calling the `require 'appoptics_apm'` directive after Grape is loaded
|
|
135
123
|
|
136
124
|
You must explicitly tell your Grape application to use AppOpticsAPM::Rack for tracing to occur.
|
137
125
|
|
138
|
-
|
126
|
+
|
127
|
+
# SDK for Custom Tracing
|
139
128
|
|
140
129
|
The appoptics_apm gem has the ability to instrument any arbitrary Ruby application or script.
|
141
130
|
|
@@ -148,22 +137,10 @@ Bundler.require
|
|
148
137
|
require 'appoptics_apm'
|
149
138
|
```
|
150
139
|
|
151
|
-
|
152
|
-
If you prefer to instead dive directly into code, take a look at
|
153
|
-
[this example](https://gist.github.com/pglombardo/8550713) of an instrumented Ruby script.
|
154
|
-
|
155
|
-
Once inside of the `AppOpticsAPM::API.start_trace` block, performance metrics will be automatically collected for all
|
156
|
-
supported libraries and gems (Redis, Mongo, ActiveRecord etc..).
|
157
|
-
|
158
|
-
# Custom Tracing
|
140
|
+
You can add even more visibility into any part of your application or scripts by adding custom instrumentation.
|
159
141
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
## The Tracing API
|
164
|
-
|
165
|
-
You can instrument any arbitrary block of code using `AppOpticsAPM::API.trace`. The code and any supported calls for
|
166
|
-
libraries that we support, will automatically get traced and reported to your dashboard.
|
142
|
+
## AppOpticsAPM::SDK.trace
|
143
|
+
You can instrument any arbitrary block of code using `AppOpticsAPM::SDK.trace`.
|
167
144
|
|
168
145
|
```ruby
|
169
146
|
# layer_name will show up in the AppOptics app dashboard
|
@@ -177,41 +154,87 @@ layer_name = 'subsystemX'
|
|
177
154
|
report_kvs = {}
|
178
155
|
report_kvs[:mykey] = @client.id
|
179
156
|
|
180
|
-
AppOpticsAPM::
|
157
|
+
AppOpticsAPM::SDK.trace(layer_name, report_kvs) do
|
181
158
|
# the block of code to be traced
|
182
159
|
end
|
183
160
|
```
|
184
161
|
|
185
|
-
`AppOpticsAPM::
|
162
|
+
`AppOpticsAPM::SDK.trace` is used within the context of a request. It will follow the upstream state of the request
|
186
163
|
being traced. i.e. the block of code will only be traced when the parent request is being traced.
|
187
164
|
|
188
165
|
This tracing state of a request can also be queried by using `AppOpticsAPM.tracing?`.
|
189
166
|
|
167
|
+
## AppOpticsAPM::SDK.start_trace
|
168
|
+
|
190
169
|
If you need to instrument code outside the context of a request (such as a cron job, background job or an arbitrary
|
191
|
-
ruby script), use `AppOpticsAPM::
|
170
|
+
ruby script), use `AppOpticsAPM::SDK.start_trace` instead which will initiate a new trace based on configuration and
|
171
|
+
probability (based on the sample rate).
|
192
172
|
|
193
|
-
Find more details in the [RubyDoc page](http://rdoc.info/gems/appoptics/AppOpticsAPM/API/Tracing) or in
|
194
|
-
[this example](https://gist.github.com/pglombardo/8550713) on how to use the Tracing API in an independent Ruby script.
|
195
173
|
|
196
|
-
## Tracing Methods
|
197
174
|
|
198
|
-
|
199
|
-
`AppOpticsAPM::API.profile_method`.
|
175
|
+
### Example
|
200
176
|
|
201
|
-
|
202
|
-
|
177
|
+
```ruby
|
178
|
+
require 'rubygems'
|
179
|
+
require 'bundler'
|
203
180
|
|
204
|
-
|
205
|
-
AppOpticsAPM::API.profile_method(Array, :sort)
|
206
|
-
```
|
181
|
+
Bundler.require
|
207
182
|
|
208
|
-
|
209
|
-
|
183
|
+
# Make sure appoptics_apm is at the bottom of your Gemfile.
|
184
|
+
# This is likely redundant but just in case.
|
185
|
+
require 'appoptics_apm'
|
186
|
+
|
187
|
+
|
188
|
+
# Tracing mode can be 'never', 'through' (to follow upstream) or 'always'
|
189
|
+
AppOpticsAPM::Config[:tracing_mode] = 'always'
|
190
|
+
|
191
|
+
#
|
192
|
+
# Update April 9, 2015 - this is done automagically now
|
193
|
+
# and doesn't have to be called manually
|
194
|
+
#
|
195
|
+
# Load library instrumentation to auto-capture stuff we know about...
|
196
|
+
# e.g. ActiveRecord, Cassandra, Dalli, Redis, memcache, mongo
|
197
|
+
# TraceView::Ruby.load
|
198
|
+
|
199
|
+
# Some KVs to report to the dashboard
|
200
|
+
report_kvs = {}
|
201
|
+
report_kvs[:command_line_params] = ARGV.to_s
|
202
|
+
report_kvs[:user_id] = `whoami`
|
203
|
+
|
204
|
+
AppOpticsAPM::SDK.start_trace('my_background_job', nil, report_kvs ) do
|
205
|
+
#
|
206
|
+
# Initialization code
|
207
|
+
#
|
208
|
+
|
209
|
+
tasks = get_all_tasks
|
210
|
+
|
211
|
+
tasks.each do |t|
|
212
|
+
# Optional: Here we embed another 'trace' to separate actual
|
213
|
+
# work for each task. In the traces dashboard this will show
|
214
|
+
# up as a large 'my_background_job' parent layer with many
|
215
|
+
# child 'task' layers.
|
216
|
+
AppOpticsAPM::SDK.trace('task', { :task_id => t.id }) do
|
217
|
+
t.perform
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
#
|
222
|
+
# cleanup code
|
223
|
+
#
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
# Note that we use 'start_trace' in the outer block and 'trace' for
|
228
|
+
# any sub-blocks of code we wish to instrument. The arguments for
|
229
|
+
# both methods vary slightly.
|
230
|
+
```
|
231
|
+
|
232
|
+
Find more details in the [RubyDoc page](https://www.rubydoc.info/gems/appoptics_apm/AppOpticsAPM/SDK) on how to use the Tracing SDK in an independent Ruby script.
|
210
233
|
|
211
234
|
# Support
|
212
235
|
|
213
|
-
If you find a bug or would like to request an enhancement, feel free to
|
214
|
-
|
236
|
+
If you find a bug or would like to request an enhancement, feel free to contact our tech support
|
237
|
+
[support@appoptics.com](support@appoptics.com).
|
215
238
|
|
216
239
|
# Contributing
|
217
240
|
|
@@ -222,15 +245,6 @@ thought of.
|
|
222
245
|
We welcome you to send us PRs. We also humbly request that any new instrumentation submissions have corresponding tests
|
223
246
|
that accompany them. This way we don't break any of your additions when we (and others) make changes after the fact.
|
224
247
|
|
225
|
-
## Developer Resources
|
226
|
-
|
227
|
-
We have made a large effort to expose as much technical information as possible to assist developers wishing to
|
228
|
-
contribute to the appoptics gem. Below is a good source for information and help for developers:
|
229
|
-
|
230
|
-
* The [AppOptics Knowledge Base](https://docs.appoptics.com/kb/apm_tracing) has a large collection of technical articles
|
231
|
-
or, if needed, you can submit a support request directly to the team.
|
232
|
-
|
233
|
-
If you have any questions or ideas, don't hesitate to contact us anytime.
|
234
248
|
|
235
249
|
## Layout of the Gem
|
236
250
|
|
@@ -240,7 +254,7 @@ The appoptics gem uses a standard gem layout. Here are the notable directories.
|
|
240
254
|
lib/appoptics/frameworks # Framework instrumentation directory
|
241
255
|
lib/appoptics/frameworks/rails # Files specific to Rails instrumentation
|
242
256
|
lib/rails # A Rails required directory for the Rails install generator
|
243
|
-
lib/api # The AppOpticsAPM Tracing API: layers, logging,
|
257
|
+
lib/api # The AppOpticsAPM Tracing API: layers, logging, tracing
|
244
258
|
ext/oboe_metal # The Ruby c extension that links against the system liboboe library
|
245
259
|
|
246
260
|
## Building the Gem
|
@@ -255,7 +269,7 @@ gem build appoptics_apm.gemspec
|
|
255
269
|
|
256
270
|
Custom instrumentation for a library, database or other service can be authored fairly easily. Generally,
|
257
271
|
instrumentation of a library is done by wrapping select operations of that library and timing their execution using the
|
258
|
-
AppOpticsAPM Tracing
|
272
|
+
AppOpticsAPM Tracing SDK which then reports the metrics to the users' AppOptics dashboard.
|
259
273
|
|
260
274
|
Here, I'll use a stripped down version of the Dalli instrumentation (`lib/appoptics/inst/dalli.rb`) as a quick example
|
261
275
|
of how to instrument a client library (the dalli gem).
|
@@ -266,14 +280,14 @@ us to capture all Dalli operations called by an application.
|
|
266
280
|
First, we define a module (AppOpticsAPM::Inst::Dalli) and our own custom `perform_with_appoptics` method that we will
|
267
281
|
use as a wrapper around Dalli's `perform` method. We also declare an `included` method which automatically gets called
|
268
282
|
when this module is included by another.
|
269
|
-
See [
|
283
|
+
See [`Module#included` Ruby reference documentation](https://devdocs.io/ruby~2.5/module#method-i-included).
|
270
284
|
|
271
285
|
```ruby
|
272
286
|
module AppOpticsAPM
|
273
287
|
module Inst
|
274
288
|
module Dalli
|
275
289
|
include AppOpticsAPM::API::Memcache
|
276
|
-
|
290
|
+
|
277
291
|
def self.included(cls)
|
278
292
|
cls.class_eval do
|
279
293
|
if ::Dalli::Client.private_method_defined? :perform
|
@@ -282,19 +296,19 @@ module AppOpticsAPM
|
|
282
296
|
end
|
283
297
|
end
|
284
298
|
end
|
285
|
-
|
299
|
+
|
286
300
|
def perform_with_appoptics(*all_args, &blk)
|
287
301
|
op, key, *args = *all_args
|
288
|
-
|
302
|
+
|
289
303
|
if AppOpticsAPM.tracing?
|
290
304
|
opts = {}
|
291
305
|
opts[:KVOp] = op
|
292
306
|
opts[:KVKey] = key
|
293
|
-
|
294
|
-
AppOpticsAPM::
|
307
|
+
|
308
|
+
AppOpticsAPM::SDK.trace('memcache', opts || {}) do
|
295
309
|
result = perform_without_appoptics(*all_args, &blk)
|
296
310
|
if op == :get and key.class == String
|
297
|
-
AppOpticsAPM::API.
|
311
|
+
AppOpticsAPM::API.log_info('memcache', { :KVHit => memcache_hit?(result) })
|
298
312
|
end
|
299
313
|
result
|
300
314
|
end
|
@@ -302,6 +316,7 @@ module AppOpticsAPM
|
|
302
316
|
perform_without_appoptics(*all_args, &blk)
|
303
317
|
end
|
304
318
|
end
|
319
|
+
|
305
320
|
end
|
306
321
|
end
|
307
322
|
end
|
@@ -319,9 +334,9 @@ end
|
|
319
334
|
```
|
320
335
|
|
321
336
|
Third, in our wrapper method, we capture the arguments passed in, collect the operation and key information into a local
|
322
|
-
hash and then invoke the `AppOpticsAPM::
|
337
|
+
hash and then invoke the `AppOpticsAPM::SDK.trace` method to time the execution of the original operation.
|
323
338
|
|
324
|
-
The `AppOpticsAPM::
|
339
|
+
The `AppOpticsAPM::SDK.trace` method calls Dalli's native operation and reports the timing metrics and your custom
|
325
340
|
`report_kvs` up to AppOptics servers to be shown on the user's dashboard.
|
326
341
|
|
327
342
|
Some other tips and guidelines:
|
@@ -369,32 +384,41 @@ You can read more about Ruby gems with C extensions in the
|
|
369
384
|
|
370
385
|
## Running the Tests
|
371
386
|
|
372
|
-
|
387
|
+
There are few caveats with the tests:
|
388
|
+
1. They only run on Linux systems, because of the c-lib used by the appoptics-apm gem.
|
389
|
+
1. The are split up, different suites can be run with `bundle exec rake test` depending on the Gemfile set in the
|
390
|
+
environment variable `BUNDLE_GEMFILE`.
|
391
|
+
1. Some are integration tests that depend on external services and databases.
|
373
392
|
|
374
|
-
|
375
|
-
currently
|
393
|
+
Unless you are developing on a linux system it may be easiest to run the tests using docker. The docker test setup is
|
394
|
+
currently being improved to become more comprehensive.
|
376
395
|
|
377
|
-
|
396
|
+
The command `./run_tests_docker.rb` will run the tests and dump the output to a file in the log folder.
|
397
|
+
In the shell it will print the commands to run a single test suite, e.g.
|
378
398
|
|
379
399
|
```bash
|
380
|
-
|
400
|
+
docker-compose run --rm --service-ports ruby_appoptics_apm /code/ruby-appoptics_apm/ruby_setup.sh 2.5.1 gemfiles/libraries.gemfile DBTYPE=postgresql
|
381
401
|
```
|
382
402
|
|
383
|
-
|
384
|
-
all of the supported software (Cassandra, Memcache, Mongo etc.) to be installed, configured and available.
|
385
|
-
|
386
|
-
Since this is overly burdensome for casual users, you can run just the tests that you're interested in.
|
387
|
-
|
388
|
-
To run just the tests for the dalli gem trace validation:
|
403
|
+
If `true` is added to that command line it will stop in a sheel in the docker container, which is great for debugging.
|
389
404
|
|
390
405
|
```bash
|
391
|
-
|
406
|
+
docker-compose run --rm --service-ports ruby_appoptics_apm /code/ruby-appoptics_apm/ruby_setup.sh 2.5.1 gemfiles/libraries.gemfile DBTYPE=postgresql true
|
392
407
|
```
|
393
408
|
|
394
|
-
|
409
|
+
The gem is setup to be debugged with `pry` and `pry-byebug`, add the following lines in the code for a break:
|
410
|
+
```ruby
|
411
|
+
require 'pry'
|
412
|
+
require 'pry-byebug'
|
413
|
+
byebug
|
414
|
+
```
|
415
|
+
|
416
|
+
If you need further assistance running tests feel free to get in touch with the main developer.
|
417
|
+
|
418
|
+
|
395
419
|
|
396
420
|
# License
|
397
421
|
|
398
422
|
Copyright (c) 2018 SolarWinds, LLC
|
399
423
|
|
400
|
-
Released under the [Librato Open License](
|
424
|
+
Released under the [Librato Open License](https://docs.appoptics.com/kb/apm_tracing/librato-open-license/)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
###############################################################
|
3
|
+
# BASIC TRACING EXAMPLES
|
4
|
+
###############################################################
|
5
|
+
|
6
|
+
# set APPOPTICS_SERVICE_KEY and run with
|
7
|
+
# `bundle exec ruby 01_basic_tracing.rb`
|
8
|
+
|
9
|
+
require 'appoptics_apm'
|
10
|
+
unless AppopticsAPM::SDK.appoptics_ready(10_000)
|
11
|
+
puts "aborting!!! Agent not ready after 10 seconds"
|
12
|
+
exit false
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
###############################################################
|
17
|
+
# Starting a trace and adding a span
|
18
|
+
###############################################################
|
19
|
+
|
20
|
+
# USE CASE:
|
21
|
+
# You may want to either trace a piece of your own code or a
|
22
|
+
# call to a method from a gem that isn't auto-instrumented by
|
23
|
+
# appoptics_apm
|
24
|
+
|
25
|
+
# The first example will not create a span, because no trace has
|
26
|
+
# been started, but the second and third ones will.
|
27
|
+
|
28
|
+
# The string argument is the name for the span
|
29
|
+
|
30
|
+
##
|
31
|
+
# AppOpticsAPM::SDK.trace()
|
32
|
+
# most of the time this is the method you need. It adds a span
|
33
|
+
# to a trace that has probably been started by rack.
|
34
|
+
|
35
|
+
# Example 1
|
36
|
+
def do_work
|
37
|
+
42
|
38
|
+
end
|
39
|
+
|
40
|
+
AppOpticsAPM::SDK.trace('simple_span') do
|
41
|
+
do_work
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# AppOpticsAPM::SDK.start_trace()
|
46
|
+
# This method starts a trace. It is handy for background jobs,
|
47
|
+
# workers, or scripts, that are not part of a rack application
|
48
|
+
|
49
|
+
# Example 2
|
50
|
+
AppOpticsAPM::SDK.start_trace('outer_span') do
|
51
|
+
|
52
|
+
AppOpticsAPM::SDK.trace('simple_span') do
|
53
|
+
do_work
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# Example 3
|
59
|
+
def do_traced_work
|
60
|
+
AppOpticsAPM::SDK.trace('simple_span_2') do
|
61
|
+
do_work
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
AppOpticsAPM::SDK.start_trace('outer_span_2') do
|
66
|
+
do_traced_work
|
67
|
+
end
|