oboe 2.7.0.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +51 -0
- data/Appraisals +10 -0
- data/CHANGELOG.md +223 -0
- data/Gemfile +49 -0
- data/LICENSE +199 -0
- data/README.md +380 -0
- data/Rakefile +106 -0
- data/ext/oboe_metal/extconf.rb +61 -0
- data/ext/oboe_metal/noop/noop.c +7 -0
- data/ext/oboe_metal/src/bson/bson.h +221 -0
- data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
- data/ext/oboe_metal/src/oboe.h +275 -0
- data/ext/oboe_metal/src/oboe.hpp +352 -0
- data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
- data/ext/oboe_metal/tests/test.rb +11 -0
- data/gemfiles/mongo.gemfile +33 -0
- data/gemfiles/moped.gemfile +33 -0
- data/get_version.rb +5 -0
- data/init.rb +4 -0
- data/lib/base.rb +99 -0
- data/lib/joboe_metal.rb +185 -0
- data/lib/method_profiling.rb +70 -0
- data/lib/oboe.rb +50 -0
- data/lib/oboe/api.rb +14 -0
- data/lib/oboe/api/layerinit.rb +99 -0
- data/lib/oboe/api/logging.rb +129 -0
- data/lib/oboe/api/memcache.rb +29 -0
- data/lib/oboe/api/profiling.rb +50 -0
- data/lib/oboe/api/tracing.rb +134 -0
- data/lib/oboe/api/util.rb +117 -0
- data/lib/oboe/config.rb +140 -0
- data/lib/oboe/frameworks/grape.rb +74 -0
- data/lib/oboe/frameworks/padrino.rb +66 -0
- data/lib/oboe/frameworks/padrino/templates.rb +59 -0
- data/lib/oboe/frameworks/rails.rb +139 -0
- data/lib/oboe/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
- data/lib/oboe/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
- data/lib/oboe/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
- data/lib/oboe/frameworks/rails/inst/action_controller.rb +123 -0
- data/lib/oboe/frameworks/rails/inst/action_view.rb +56 -0
- data/lib/oboe/frameworks/rails/inst/action_view_2x.rb +54 -0
- data/lib/oboe/frameworks/rails/inst/action_view_30.rb +48 -0
- data/lib/oboe/frameworks/rails/inst/active_record.rb +24 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb +118 -0
- data/lib/oboe/frameworks/sinatra.rb +96 -0
- data/lib/oboe/frameworks/sinatra/templates.rb +56 -0
- data/lib/oboe/inst/cassandra.rb +281 -0
- data/lib/oboe/inst/dalli.rb +75 -0
- data/lib/oboe/inst/http.rb +72 -0
- data/lib/oboe/inst/memcache.rb +105 -0
- data/lib/oboe/inst/memcached.rb +96 -0
- data/lib/oboe/inst/mongo.rb +240 -0
- data/lib/oboe/inst/moped.rb +474 -0
- data/lib/oboe/inst/rack.rb +81 -0
- data/lib/oboe/inst/redis.rb +273 -0
- data/lib/oboe/inst/resque.rb +193 -0
- data/lib/oboe/instrumentation.rb +18 -0
- data/lib/oboe/loading.rb +98 -0
- data/lib/oboe/logger.rb +41 -0
- data/lib/oboe/ruby.rb +11 -0
- data/lib/oboe/util.rb +129 -0
- data/lib/oboe/version.rb +13 -0
- data/lib/oboe/xtrace.rb +52 -0
- data/lib/oboe_metal.rb +140 -0
- data/lib/rails/generators/oboe/install_generator.rb +76 -0
- data/lib/rails/generators/oboe/templates/oboe_initializer.rb +94 -0
- data/oboe.gemspec +29 -0
- data/release.sh +65 -0
- data/test/frameworks/apps/grape_simple.rb +10 -0
- data/test/frameworks/apps/padrino_simple.rb +41 -0
- data/test/frameworks/apps/sinatra_simple.rb +20 -0
- data/test/frameworks/grape_test.rb +27 -0
- data/test/frameworks/padrino_test.rb +25 -0
- data/test/frameworks/sinatra_test.rb +25 -0
- data/test/instrumentation/cassandra_test.rb +381 -0
- data/test/instrumentation/dalli_test.rb +164 -0
- data/test/instrumentation/http_test.rb +97 -0
- data/test/instrumentation/memcache_test.rb +251 -0
- data/test/instrumentation/memcached_test.rb +226 -0
- data/test/instrumentation/mongo_test.rb +462 -0
- data/test/instrumentation/moped_test.rb +473 -0
- data/test/instrumentation/rack_test.rb +73 -0
- data/test/instrumentation/redis_hashes_test.rb +265 -0
- data/test/instrumentation/redis_keys_test.rb +318 -0
- data/test/instrumentation/redis_lists_test.rb +310 -0
- data/test/instrumentation/redis_misc_test.rb +160 -0
- data/test/instrumentation/redis_sets_test.rb +293 -0
- data/test/instrumentation/redis_sortedsets_test.rb +325 -0
- data/test/instrumentation/redis_strings_test.rb +333 -0
- data/test/instrumentation/resque_test.rb +62 -0
- data/test/minitest_helper.rb +148 -0
- data/test/profiling/method_test.rb +198 -0
- data/test/support/config_test.rb +39 -0
- data/test/support/liboboe_settings_test.rb +46 -0
- data/test/support/xtrace_test.rb +35 -0
- metadata +200 -0
data/README.md
ADDED
@@ -0,0 +1,380 @@
|
|
1
|
+
# Welcome to the TraceView Ruby Gem
|
2
|
+
## AKA The oboe gem
|
3
|
+
|
4
|
+
The oboe gem provides AppNeta [TraceView](http://www.appneta.com/application-performance-management/) instrumentation for Ruby.
|
5
|
+
|
6
|
+
![Ruby TraceView](https://s3.amazonaws.com/pglombardo/oboe-ruby-header.png)
|
7
|
+
|
8
|
+
It has the ability to report performance metrics on an array of libraries, databases and frameworks such as Rails, Mongo, Memcache, ActiveRecord, Cassandra, Rack, Resque [and more](https://support.appneta.com/cloud/ruby-instrumentation-release-notes)
|
9
|
+
|
10
|
+
It requires a [TraceView](http://www.appneta.com/products/traceview/) account to view metrics. Get yours, [it's free](http://www.appneta.com/products/traceview-free-account/).
|
11
|
+
|
12
|
+
[![Gem Version](https://badge.fury.io/rb/oboe.png)](http://badge.fury.io/rb/oboe)
|
13
|
+
[![Build Status](https://travis-ci.org/appneta/oboe-ruby.png?branch=master)](https://travis-ci.org/appneta/oboe-ruby)
|
14
|
+
[![Code Climate](https://codeclimate.com/github/appneta/oboe-ruby.png)](https://codeclimate.com/github/appneta/oboe-ruby)
|
15
|
+
|
16
|
+
# Installation
|
17
|
+
|
18
|
+
The oboe gem is [available on Rubygems](https://rubygems.org/gems/oboe) and can be installed with:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
gem install oboe
|
22
|
+
```
|
23
|
+
|
24
|
+
or added to _the end_ of your bundle Gemfile and running `bundle install`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'oboe'
|
28
|
+
```
|
29
|
+
|
30
|
+
On Heroku? Use the `oboe-heroku` gem instead. It wraps some additional functionality specialized for Heroku.
|
31
|
+
|
32
|
+
# Running
|
33
|
+
|
34
|
+
## Rails
|
35
|
+
|
36
|
+
No special steps are needed to instrument Ruby on Rails. Once part of the bundle, the oboe gem will automatically detect Rails and instrument on stack initialization.
|
37
|
+
|
38
|
+
*Note: Unless you are Heroku, you will still need to decide on your `tracing_mode` depending on whether you are running with an instrumented Apache or nginx in front of your Rails stack. See below for more details.*
|
39
|
+
|
40
|
+
### The Install Generator
|
41
|
+
|
42
|
+
The oboe gem provides a Rails generator used to seed an oboe initializer where you can configure and control `tracing_mode`, `sample_rate` and [other options](https://support.appneta.com/cloud/configuring-ruby-instrumentation)
|
43
|
+
|
44
|
+
To run the install generator run:
|
45
|
+
|
46
|
+
```bash
|
47
|
+
bundle exec rails generate oboe:install
|
48
|
+
```
|
49
|
+
|
50
|
+
After the prompts, this will create an initializer: `config/initializers/oboe.rb`.
|
51
|
+
|
52
|
+
## Sinatra
|
53
|
+
|
54
|
+
You can instrument your Sinatra application by adding the following code to your `config.ru` Rackup file:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# If you're not using Bundler.require. Make sure this is done
|
58
|
+
# after the Sinatra require directive.
|
59
|
+
require 'oboe'
|
60
|
+
|
61
|
+
# When traces should be initiated for incoming requests. Valid options are
|
62
|
+
# "always", "through" (when the request is initiated with a tracing header
|
63
|
+
# from upstream) and "never". You must set this directive to "always" in
|
64
|
+
# order to initiate tracing.
|
65
|
+
Oboe::Config[:tracing_mode] = 'through'
|
66
|
+
|
67
|
+
# You may want to replace the Oboe.logger with whichever logger you are using
|
68
|
+
# Oboe.logger = Sinatra.logger
|
69
|
+
```
|
70
|
+
|
71
|
+
Note: If you're on Heroku, you don't need to set `tracing_mode` - it will be automatically configured.
|
72
|
+
|
73
|
+
Make sure that the oboe gem is loaded _after_ Sinatra either by listing `gem 'oboe'` after Sinatra in your Gemfile or calling the `require 'oboe'` directive after Sinatra is loaded.
|
74
|
+
|
75
|
+
With this, the oboe gem will automatically detect Sinatra on boot and instrument key components.
|
76
|
+
|
77
|
+
## Padrino
|
78
|
+
|
79
|
+
As long as the oboe gem is in your `Gemfile` (inserted after the `gem 'padrino'` directive) and you are calling `Bundler.require`, the oboe gem will automatically instrument Padrino applications.
|
80
|
+
|
81
|
+
If you need to set `Oboe::Config` values on stack boot, you can do so by adding the following
|
82
|
+
to your `config/boot.rb` file:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
Padrino.before_load do
|
86
|
+
# When traces should be initiated for incoming requests. Valid options are
|
87
|
+
# "always", "through" (when the request is initiated with a tracing header
|
88
|
+
# from upstream) and "never". You must set this directive to "always" in
|
89
|
+
# order to initiate tracing.
|
90
|
+
Oboe::Config[:tracing_mode] = 'always'
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
Note: If you're on Heroku, you don't need to set `tracing_mode` - it will be automatically configured.
|
95
|
+
|
96
|
+
## Grape
|
97
|
+
|
98
|
+
You can instrument your Grape application by adding the following code to your `config.ru` Rackup file:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# If you're not using Bundler.require. Make sure this is done
|
102
|
+
# after the Grape require directive.
|
103
|
+
require 'oboe'
|
104
|
+
|
105
|
+
# When traces should be initiated for incoming requests. Valid options are
|
106
|
+
# "always", "through" (when the request is initiated with a tracing header
|
107
|
+
# from upstream) and "never". You must set this directive to "always" in
|
108
|
+
# order to initiate tracing.
|
109
|
+
Oboe::Config[:tracing_mode] = 'through'
|
110
|
+
|
111
|
+
...
|
112
|
+
|
113
|
+
class App < Grape::API
|
114
|
+
use Oboe::Rack
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
Note: If you're on Heroku, you don't need to set `tracing_mode` - it will be automatically configured.
|
119
|
+
|
120
|
+
Make sure that the oboe gem is loaded _after_ Grape either by listing `gem 'oboe'` after Grape in your Gemfile or calling the `require 'oboe'` directive after Grape is loaded.
|
121
|
+
|
122
|
+
You must explicitly tell your Grape application to use Oboe::Rack for tracing to occur.
|
123
|
+
|
124
|
+
## Custom Ruby Scripts & Applications
|
125
|
+
|
126
|
+
The oboe gem has the ability to instrument any arbitrary Ruby application or script as long as the gem is initialized with the manual methods:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
require 'rubygems'
|
130
|
+
require 'bundler'
|
131
|
+
|
132
|
+
Bundler.require
|
133
|
+
|
134
|
+
require 'oboe'
|
135
|
+
|
136
|
+
# Tracing mode can be 'never', 'through' (to follow upstream) or 'always'
|
137
|
+
Oboe::Config[:tracing_mode] = 'always'
|
138
|
+
|
139
|
+
Oboe::Ruby.initialize
|
140
|
+
```
|
141
|
+
|
142
|
+
From here, you can use the Tracing API to instrument areas of code using `Oboe::API.start_trace` (see below). If you prefer to instead dive directly into code, take a look at [this example](https://gist.github.com/pglombardo/8550713) of an instrumented Ruby script.
|
143
|
+
|
144
|
+
## Other
|
145
|
+
|
146
|
+
You can send deploy notifications to TraceView and have the events show up on your dashboard. See: [Capistrano Deploy Notifications with tlog](https://support.appneta.com/cloud/capistrano-deploy-notifications-tlog)
|
147
|
+
|
148
|
+
# Custom Tracing
|
149
|
+
|
150
|
+
## The Tracing API
|
151
|
+
|
152
|
+
You can instrument any arbitrary block of code using `Oboe::API.trace`:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
# layer_name will show up in the TraceView app dashboard
|
156
|
+
layer_name = 'subsystemX'
|
157
|
+
|
158
|
+
# report_kvs are a set of information Key/Value pairs that are sent to
|
159
|
+
# TraceView dashboard along with the performance metrics. These KV
|
160
|
+
# pairs are used to report request, environment and/or client specific
|
161
|
+
# information.
|
162
|
+
|
163
|
+
report_kvs = {}
|
164
|
+
report_kvs[:mykey] = @client.id
|
165
|
+
|
166
|
+
Oboe::API.trace(layer_name, report_kvs) do
|
167
|
+
# the block of code to be traced
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
`Oboe::API.trace` is used within the context of a request. It will follow the upstream state of the request being traced. i.e. the block of code will only be traced when the parent request is being traced.
|
172
|
+
|
173
|
+
This tracing state of a request can also be queried by using `Oboe.tracing?`.
|
174
|
+
|
175
|
+
If you need to instrument code outside the context of a request (such as a cron job, background job or an arbitrary ruby script), use `Oboe::API.start_trace` instead which will initiate new traces based on configuration and probability (based on the sample rate).
|
176
|
+
|
177
|
+
Find more details in the [RubyDoc page](http://rdoc.info/gems/oboe/Oboe/API/Tracing) or in [this example](https://gist.github.com/pglombardo/8550713) on how to use the Tracing API in an independent Ruby script.
|
178
|
+
|
179
|
+
## Tracing Methods
|
180
|
+
|
181
|
+
By using class level declarations, it's possible to automatically have certain methods on that class instrumented and reported to your TraceView dashboard automatically.
|
182
|
+
|
183
|
+
The pattern for Method Profiling is as follows:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
# 'profile_name' is similar to a layer name.
|
187
|
+
# It identifies this custom trace in your dashboard.
|
188
|
+
#
|
189
|
+
class Engine
|
190
|
+
include OboeMethodProfiling
|
191
|
+
|
192
|
+
def processor()
|
193
|
+
# body of method
|
194
|
+
end
|
195
|
+
|
196
|
+
# call syntax: profile_method <method>, <profile_name>
|
197
|
+
profile_method :processor, 'processor'
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
201
|
+
This example demonstrates method profiling of instance methods. Class methods are profiled slightly differently. See the TraceView [documentation portal](https://support.appneta.com/cloud/ruby-custom) for full details.
|
202
|
+
|
203
|
+
# Support
|
204
|
+
|
205
|
+
If you find a bug or would like to request an enhancement, feel free to file an issue. For all other support requests, see our [support portal](https://support.appneta.com/cloud) or on IRC @ #appneta on [Freenode](http://freenode.net/).
|
206
|
+
|
207
|
+
# Contributing
|
208
|
+
|
209
|
+
You are obviously a person of great sense and intelligence. We happily appreciate all contributions to the oboe gem whether it is documentation, a bug fix, new instrumentation for a library or framework or anything else we haven't thought of.
|
210
|
+
|
211
|
+
We welcome you to send us PRs. We also humbly request that any new instrumentation submissions have corresponding tests that accompany them. This way we don't break any of your additions when we (and others) make changes after the fact.
|
212
|
+
|
213
|
+
## Developer Resources
|
214
|
+
|
215
|
+
We at AppNeta have made a large effort to expose as much technical information as possible to assist developers wishing to contribute to the oboe gem. Below are the three major sources for information and help for developers:
|
216
|
+
|
217
|
+
* The [TraceView blog](http://www.appneta.com/blog) has a constant stream of great technical articles. (See [A Gentle X-Trace Introduction](http://www.appneta.com/blog/x-trace-introduction/) for details on the basic methodology that TraceView uses to gather structured performance data across hosts and stacks.)
|
218
|
+
|
219
|
+
* The [TraceView Knowledge Base](https://support.tv.appneta.com) has a large collection of technical articles or, if needed, you can submit a support request directly to the team.
|
220
|
+
|
221
|
+
* You can also reach the TraceView team on our IRC channel #appneta on freenode.
|
222
|
+
|
223
|
+
If you have any questions or ideas, don't hesitate to contact us anytime.
|
224
|
+
|
225
|
+
## Layout of the Gem
|
226
|
+
|
227
|
+
The oboe gem uses a standard gem layout. Here are the notable directories.
|
228
|
+
|
229
|
+
lib/oboe/inst # Auto load directory for various instrumented libraries
|
230
|
+
lib/oboe/frameworks # Framework instrumentation directory
|
231
|
+
lib/oboe/frameworks/rails # Files specific to Rails instrumentation
|
232
|
+
lib/rails # A Rails required directory for the Rails install generator
|
233
|
+
lib/api # The TraceView Tracing API: layers, logging, profiling and tracing
|
234
|
+
ext/oboe_metal # The Ruby c extension that links against the system liboboe library
|
235
|
+
|
236
|
+
## Building the Gem
|
237
|
+
|
238
|
+
The oboe gem is built with the standard `gem build` command passing in the gemspec:
|
239
|
+
|
240
|
+
```bash
|
241
|
+
gem build oboe.gemspec
|
242
|
+
```
|
243
|
+
|
244
|
+
## Writing Custom Instrumentation
|
245
|
+
|
246
|
+
Custom instrumentation for a library, database or other service can be authored fairly easily. Generally, instrumentation of a library is done by wrapping select operations of that library and timing their execution using the Oboe Tracing API which then reports the metrics to the users' TraceView dashboard.
|
247
|
+
|
248
|
+
Here, I'll use a stripped down version of the Dalli instrumentation (`lib/oboe/inst/dalli.rb`) as a quick example of how to instrument a client library (the dalli gem).
|
249
|
+
|
250
|
+
The Dalli gem nicely routes all memcache operations through a single `perform` operation. Wrapping this method allows us to capture all Dalli operations called by an application.
|
251
|
+
|
252
|
+
First, we define a module (Oboe::Inst::Dalli) and our own custom `perform_with_oboe` method that we will use as a wrapper around Dalli's `perform` method. We also declare an `included` method which automatically gets called when this module is included by another. See ['included' Ruby reference documentation](http://apidock.com/ruby/Module/included).
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
module Oboe
|
256
|
+
module Inst
|
257
|
+
module Dalli
|
258
|
+
include Oboe::API::Memcache
|
259
|
+
|
260
|
+
def self.included(cls)
|
261
|
+
cls.class_eval do
|
262
|
+
if ::Dalli::Client.private_method_defined? :perform
|
263
|
+
alias perform_without_oboe perform
|
264
|
+
alias perform perform_with_oboe
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def perform_with_oboe(*all_args, &blk)
|
270
|
+
op, key, *args = *all_args
|
271
|
+
|
272
|
+
if Oboe.tracing?
|
273
|
+
opts = {}
|
274
|
+
opts[:KVOp] = op
|
275
|
+
opts[:KVKey] = key
|
276
|
+
|
277
|
+
Oboe::API.trace('memcache', opts || {}) do
|
278
|
+
result = perform_without_oboe(*all_args, &blk)
|
279
|
+
if op == :get and key.class == String
|
280
|
+
Oboe::API.log('memcache', 'info', { :KVHit => memcache_hit?(result) })
|
281
|
+
end
|
282
|
+
result
|
283
|
+
end
|
284
|
+
else
|
285
|
+
perform_without_oboe(*all_args, &blk)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
```
|
292
|
+
|
293
|
+
Second, we tail onto the end of the instrumentation file a simple `::Dalli::Client.module_eval` call to tell the Dalli module to include our newly defined instrumentation module. Doing this will invoke our previously defined `included` method.
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
if defined?(Dalli) and Oboe::Config[:dalli][:enabled]
|
297
|
+
::Dalli::Client.module_eval do
|
298
|
+
include Oboe::Inst::Dalli
|
299
|
+
end
|
300
|
+
end
|
301
|
+
```
|
302
|
+
|
303
|
+
Third, in our wrapper method, we capture the arguments passed in, collect the operation and key information into a local hash and then invoke the `Oboe::API.trace` method to time the execution of the original operation.
|
304
|
+
|
305
|
+
The `Oboe::API.trace` method calls Dalli's native operation and reports the timing metrics and your custom `report_kvs` up to TraceView servers to be shown on the user's dashboard.
|
306
|
+
|
307
|
+
That is a very quick example of a simple instrumentation implementation. If you have any questions, visit us on IRC in #appneta on Freenode.
|
308
|
+
|
309
|
+
Some other tips and guidelines:
|
310
|
+
|
311
|
+
* You can point your Gemfile directly at your cloned oboe source by using `gem 'oboe', :path => '/path/to/oboe-ruby'`
|
312
|
+
|
313
|
+
* If instrumenting a library, database or service, place your new instrumentation file into the `lib/oboe/inst/` directory. From there, the oboe gem will detect it and automatically load the instrumentation file.
|
314
|
+
|
315
|
+
* If instrumenting a new framework, place your instrumentation file in `lib/oboe/frameworks`. Refer to the Rails instrumentation for on ideas on how to load the oboe gem correctly in your framework.
|
316
|
+
|
317
|
+
* Review other existing instrumentation similar to the one you wish to author. `lib/oboe/inst/` is a great place to start.
|
318
|
+
|
319
|
+
* Depending on the configured `:sample_rate`, not all requests will be traced. Use `Oboe.tracing?` to determine of this is a request that is being traced.
|
320
|
+
|
321
|
+
* Performance is paramount. Make sure that your wrapped methods don't slow down users applications.
|
322
|
+
|
323
|
+
* Include tests with your instrumentation. See `test/instrumentation/` for some examples of existing instrumentation tests.
|
324
|
+
|
325
|
+
## Compiling the C extension
|
326
|
+
|
327
|
+
The oboe gem utilizes a C extension to interface with the system `liboboe.so` library. This system library is installed with the TraceView host packages (tracelyzer, liboboe0, liboboe-dev) and is used to report [host](http://www.appneta.com/blog/app-host-metrics/) and performance metrics from multiple sources (Ruby, Apache, Python etc.) back to TraceView servers.
|
328
|
+
|
329
|
+
C extensions are usually built on `gem install` but when working out of a local git repository, it's required that you manually build this C extension for the gem to function.
|
330
|
+
|
331
|
+
To make this simpler, we've included a few rake tasks to automate this process:
|
332
|
+
|
333
|
+
```bash
|
334
|
+
rake compile # Build the gem's c extension
|
335
|
+
rake distclean # Remove all built files and extensions
|
336
|
+
rake recompile # Rebuild the gem's c extension
|
337
|
+
```
|
338
|
+
|
339
|
+
Note: Make sure you have the development package `liboboe0-dev` installed before attempting to compile the C extension.
|
340
|
+
|
341
|
+
```bash
|
342
|
+
>$ dpkg -l | grep liboboe
|
343
|
+
ii liboboe-dev 1.1.1-precise1 Tracelytics common library -- development files
|
344
|
+
ii liboboe0 1.1.1-precise1 Tracelytics common library
|
345
|
+
```
|
346
|
+
|
347
|
+
See [Installing Base Packages on Debian and Ubuntu](https://support.appneta.com/cloud/installing-traceview) in the Knowledge Base for details. Our hacker extraordinaire [Rob Salmond](https://github.com/rsalmond) from the support team has even gotten these packages to [run on Gentoo](http://www.appneta.com/blog/unsupported-doesnt-work/)!
|
348
|
+
|
349
|
+
To see the code related to the C extension, take a look at `ext/oboe_metal/extconf.rb` for details.
|
350
|
+
|
351
|
+
You can read more about Ruby gems with C extensions in the [Rubygems Guides](http://guides.rubygems.org/gems-with-extensions/).
|
352
|
+
|
353
|
+
## Running the Tests
|
354
|
+
|
355
|
+
The tests bundled with the gem are implemented using [Minitest](https://github.com/seattlerb/minitest). The tests are currently used to validate the sanity of the traces generated and basic gem functionality.
|
356
|
+
|
357
|
+
After a bundle install, the tests can be run as:
|
358
|
+
|
359
|
+
```bash
|
360
|
+
bundle exec rake test
|
361
|
+
```
|
362
|
+
|
363
|
+
This will run a full end-to-end test suite that covers all supported libraries and databases. Note that this requires all of the supported software (Cassandra, Memcache, Mongo etc.) to be installed, configured and available.
|
364
|
+
|
365
|
+
Since this is overly burdensome for casual users, you can run just the tests that you're interested in.
|
366
|
+
|
367
|
+
To run just the tests for the dalli gem trace validation:
|
368
|
+
|
369
|
+
```bash
|
370
|
+
bundle exec rake test TEST=test/instrumentation/dalli_test.rb
|
371
|
+
```
|
372
|
+
|
373
|
+
We humbly request that any submitted instrumentation is delivered with corresponding test coverage.
|
374
|
+
|
375
|
+
# License
|
376
|
+
|
377
|
+
Copyright (c) 2014 Appneta
|
378
|
+
|
379
|
+
Released under the [AppNeta Open License](http://www.appneta.com/appneta-license), Version 1.0
|
380
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'appraisal'
|
7
|
+
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
|
+
t.verbose = true
|
12
|
+
if defined?(JRUBY_VERSION)
|
13
|
+
t.ruby_opts = ["-J-javaagent:/usr/local/tracelytics/tracelyticsagent.jar"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
18
|
+
task :default => :appraisal
|
19
|
+
else
|
20
|
+
task :default => :test
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Build the gem's c extension"
|
24
|
+
task :compile do
|
25
|
+
unless defined?(JRUBY_VERSION)
|
26
|
+
puts "== Building the c extension against Ruby #{RUBY_VERSION}"
|
27
|
+
|
28
|
+
pwd = Dir.pwd
|
29
|
+
ext_dir = File.expand_path('ext/oboe_metal')
|
30
|
+
lib_dir = File.expand_path('lib')
|
31
|
+
symlink = File.expand_path('lib/oboe_metal.so')
|
32
|
+
so_file = File.expand_path('ext/oboe_metal/oboe_metal.so')
|
33
|
+
|
34
|
+
Dir.chdir ext_dir
|
35
|
+
cmd = [ Gem.ruby, 'extconf.rb']
|
36
|
+
sh cmd.join(' ')
|
37
|
+
sh '/usr/bin/env make'
|
38
|
+
File.delete symlink if File.exist? symlink
|
39
|
+
|
40
|
+
if File.exists? so_file
|
41
|
+
File.symlink so_file, symlink
|
42
|
+
Dir.chdir pwd
|
43
|
+
puts "== Extension built and symlink'd to #{symlink}"
|
44
|
+
else
|
45
|
+
Dir.chdir pwd
|
46
|
+
puts "!! Extension failed to build (see above). Are the base TraceView packages installed?"
|
47
|
+
puts "!! See https://support.appneta.com/cloud/installing-traceview"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
puts "== Nothing to do under JRuby."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Clean up extension build files"
|
55
|
+
task :clean do
|
56
|
+
unless defined?(JRUBY_VERSION)
|
57
|
+
pwd = Dir.pwd
|
58
|
+
ext_dir = File.expand_path('ext/oboe_metal')
|
59
|
+
lib_dir = File.expand_path('lib')
|
60
|
+
symlink = File.expand_path('lib/oboe_metal.so')
|
61
|
+
so_file = File.expand_path('ext/oboe_metal/oboe_metal.so')
|
62
|
+
|
63
|
+
Dir.chdir ext_dir
|
64
|
+
sh '/usr/bin/env make clean'
|
65
|
+
|
66
|
+
Dir.chdir pwd
|
67
|
+
else
|
68
|
+
puts "== Nothing to do under JRuby."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Remove all built files and extensions"
|
73
|
+
task :distclean do
|
74
|
+
unless defined?(JRUBY_VERSION)
|
75
|
+
pwd = Dir.pwd
|
76
|
+
ext_dir = File.expand_path('ext/oboe_metal')
|
77
|
+
lib_dir = File.expand_path('lib')
|
78
|
+
symlink = File.expand_path('lib/oboe_metal.so')
|
79
|
+
so_file = File.expand_path('ext/oboe_metal/oboe_metal.so')
|
80
|
+
mkmf_log = File.expand_path('ext/oboe_metal/mkmf.log')
|
81
|
+
|
82
|
+
if File.exists? mkmf_log
|
83
|
+
Dir.chdir ext_dir
|
84
|
+
File.delete symlink if File.exist? symlink
|
85
|
+
sh '/usr/bin/env make distclean'
|
86
|
+
|
87
|
+
Dir.chdir pwd
|
88
|
+
else
|
89
|
+
puts "Nothing to distclean. (nothing built yet?)"
|
90
|
+
end
|
91
|
+
else
|
92
|
+
puts "== Nothing to do under JRuby."
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "Rebuild the gem's c extension"
|
97
|
+
task :recompile => [ :distclean, :compile ]
|
98
|
+
|
99
|
+
task :console do
|
100
|
+
require 'pry'
|
101
|
+
require 'oboe'
|
102
|
+
ARGV.clear
|
103
|
+
Pry.start
|
104
|
+
end
|
105
|
+
|
106
|
+
|