traceview 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +5 -0
  4. data/.travis.yml +58 -0
  5. data/Appraisals +10 -0
  6. data/CHANGELOG.md +490 -0
  7. data/CONFIG.md +16 -0
  8. data/Gemfile +95 -0
  9. data/LICENSE +199 -0
  10. data/README.md +380 -0
  11. data/Rakefile +109 -0
  12. data/examples/DNT.md +35 -0
  13. data/examples/carrying_context.rb +225 -0
  14. data/examples/instrumenting_metal_controller.rb +8 -0
  15. data/examples/puma_on_heroku_config.rb +17 -0
  16. data/examples/tracing_async_threads.rb +125 -0
  17. data/examples/tracing_background_jobs.rb +52 -0
  18. data/examples/tracing_forked_processes.rb +100 -0
  19. data/examples/unicorn_on_heroku_config.rb +28 -0
  20. data/ext/oboe_metal/extconf.rb +61 -0
  21. data/ext/oboe_metal/noop/noop.c +7 -0
  22. data/ext/oboe_metal/src/bson/bson.h +221 -0
  23. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  24. data/ext/oboe_metal/src/oboe.h +275 -0
  25. data/ext/oboe_metal/src/oboe.hpp +352 -0
  26. data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
  27. data/ext/oboe_metal/tests/test.rb +11 -0
  28. data/gemfiles/mongo.gemfile +33 -0
  29. data/gemfiles/moped.gemfile +33 -0
  30. data/get_version.rb +5 -0
  31. data/init.rb +4 -0
  32. data/lib/joboe_metal.rb +206 -0
  33. data/lib/oboe.rb +7 -0
  34. data/lib/oboe/README +2 -0
  35. data/lib/oboe/backward_compatibility.rb +59 -0
  36. data/lib/oboe/inst/rack.rb +11 -0
  37. data/lib/oboe_metal.rb +151 -0
  38. data/lib/rails/generators/traceview/install_generator.rb +76 -0
  39. data/lib/rails/generators/traceview/templates/traceview_initializer.rb +159 -0
  40. data/lib/traceview.rb +62 -0
  41. data/lib/traceview/api.rb +18 -0
  42. data/lib/traceview/api/layerinit.rb +51 -0
  43. data/lib/traceview/api/logging.rb +209 -0
  44. data/lib/traceview/api/memcache.rb +31 -0
  45. data/lib/traceview/api/profiling.rb +50 -0
  46. data/lib/traceview/api/tracing.rb +135 -0
  47. data/lib/traceview/api/util.rb +121 -0
  48. data/lib/traceview/base.rb +225 -0
  49. data/lib/traceview/config.rb +238 -0
  50. data/lib/traceview/frameworks/grape.rb +97 -0
  51. data/lib/traceview/frameworks/padrino.rb +64 -0
  52. data/lib/traceview/frameworks/padrino/templates.rb +58 -0
  53. data/lib/traceview/frameworks/rails.rb +145 -0
  54. data/lib/traceview/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
  55. data/lib/traceview/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
  56. data/lib/traceview/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
  57. data/lib/traceview/frameworks/rails/inst/action_controller.rb +216 -0
  58. data/lib/traceview/frameworks/rails/inst/action_view.rb +56 -0
  59. data/lib/traceview/frameworks/rails/inst/action_view_2x.rb +54 -0
  60. data/lib/traceview/frameworks/rails/inst/action_view_30.rb +48 -0
  61. data/lib/traceview/frameworks/rails/inst/active_record.rb +24 -0
  62. data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  63. data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
  64. data/lib/traceview/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
  65. data/lib/traceview/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
  66. data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +117 -0
  67. data/lib/traceview/frameworks/sinatra.rb +95 -0
  68. data/lib/traceview/frameworks/sinatra/templates.rb +56 -0
  69. data/lib/traceview/inst/cassandra.rb +279 -0
  70. data/lib/traceview/inst/dalli.rb +86 -0
  71. data/lib/traceview/inst/em-http-request.rb +99 -0
  72. data/lib/traceview/inst/excon.rb +111 -0
  73. data/lib/traceview/inst/faraday.rb +73 -0
  74. data/lib/traceview/inst/http.rb +87 -0
  75. data/lib/traceview/inst/httpclient.rb +173 -0
  76. data/lib/traceview/inst/memcache.rb +102 -0
  77. data/lib/traceview/inst/memcached.rb +94 -0
  78. data/lib/traceview/inst/mongo.rb +238 -0
  79. data/lib/traceview/inst/moped.rb +474 -0
  80. data/lib/traceview/inst/rack.rb +122 -0
  81. data/lib/traceview/inst/redis.rb +271 -0
  82. data/lib/traceview/inst/resque.rb +192 -0
  83. data/lib/traceview/inst/rest-client.rb +38 -0
  84. data/lib/traceview/inst/sequel.rb +162 -0
  85. data/lib/traceview/inst/typhoeus.rb +102 -0
  86. data/lib/traceview/instrumentation.rb +21 -0
  87. data/lib/traceview/loading.rb +94 -0
  88. data/lib/traceview/logger.rb +41 -0
  89. data/lib/traceview/method_profiling.rb +84 -0
  90. data/lib/traceview/ruby.rb +36 -0
  91. data/lib/traceview/support.rb +113 -0
  92. data/lib/traceview/thread_local.rb +26 -0
  93. data/lib/traceview/util.rb +250 -0
  94. data/lib/traceview/version.rb +16 -0
  95. data/lib/traceview/xtrace.rb +90 -0
  96. data/test/frameworks/apps/grape_nested.rb +30 -0
  97. data/test/frameworks/apps/grape_simple.rb +24 -0
  98. data/test/frameworks/apps/padrino_simple.rb +45 -0
  99. data/test/frameworks/apps/sinatra_simple.rb +24 -0
  100. data/test/frameworks/grape_test.rb +142 -0
  101. data/test/frameworks/padrino_test.rb +30 -0
  102. data/test/frameworks/sinatra_test.rb +30 -0
  103. data/test/instrumentation/cassandra_test.rb +380 -0
  104. data/test/instrumentation/dalli_test.rb +171 -0
  105. data/test/instrumentation/em_http_request_test.rb +86 -0
  106. data/test/instrumentation/excon_test.rb +207 -0
  107. data/test/instrumentation/faraday_test.rb +235 -0
  108. data/test/instrumentation/http_test.rb +140 -0
  109. data/test/instrumentation/httpclient_test.rb +296 -0
  110. data/test/instrumentation/memcache_test.rb +251 -0
  111. data/test/instrumentation/memcached_test.rb +226 -0
  112. data/test/instrumentation/mongo_test.rb +462 -0
  113. data/test/instrumentation/moped_test.rb +496 -0
  114. data/test/instrumentation/rack_test.rb +116 -0
  115. data/test/instrumentation/redis_hashes_test.rb +265 -0
  116. data/test/instrumentation/redis_keys_test.rb +318 -0
  117. data/test/instrumentation/redis_lists_test.rb +310 -0
  118. data/test/instrumentation/redis_misc_test.rb +160 -0
  119. data/test/instrumentation/redis_sets_test.rb +293 -0
  120. data/test/instrumentation/redis_sortedsets_test.rb +325 -0
  121. data/test/instrumentation/redis_strings_test.rb +333 -0
  122. data/test/instrumentation/resque_test.rb +62 -0
  123. data/test/instrumentation/rest-client_test.rb +294 -0
  124. data/test/instrumentation/sequel_mysql2_test.rb +326 -0
  125. data/test/instrumentation/sequel_mysql_test.rb +326 -0
  126. data/test/instrumentation/sequel_pg_test.rb +330 -0
  127. data/test/instrumentation/typhoeus_test.rb +285 -0
  128. data/test/minitest_helper.rb +187 -0
  129. data/test/profiling/method_test.rb +198 -0
  130. data/test/servers/rackapp_8101.rb +22 -0
  131. data/test/support/backcompat_test.rb +269 -0
  132. data/test/support/config_test.rb +128 -0
  133. data/test/support/dnt_test.rb +73 -0
  134. data/test/support/liboboe_settings_test.rb +104 -0
  135. data/test/support/xtrace_test.rb +35 -0
  136. data/traceview.gemspec +29 -0
  137. metadata +250 -0
data/CONFIG.md ADDED
@@ -0,0 +1,16 @@
1
+ # TraceView Gem Configuration
2
+
3
+ ## Environment Variables
4
+
5
+ The following environment variables are detected by the traceview gem:
6
+
7
+ * `IGNORE_TRACEVIEW_WARNING` - tells the traceview gem to __not__ output the _missing TraceView libraries_ message on stack initialization
8
+
9
+ * `TRACEVIEW_GEM_VERBOSE` - sets the verbose flag (`TraceView::Config[:verbose]`) early in the gem loading process which may output valuable information
10
+
11
+ ## TraceView::Config
12
+
13
+ `TraceView::Config` is a nested hash used by the traceview gem to store preferences and switches.
14
+
15
+ See [this Rails generator template file](https://github.com/appneta/oboe-ruby/blob/master/lib/rails/generators/traceview/templates/traceview_initializer.rb) for documentation on all of the supported values.
16
+
data/Gemfile ADDED
@@ -0,0 +1,95 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'minitest', "5.5.1"
5
+ gem 'minitest-reporters'
6
+ gem 'minitest-debugger', :require => false
7
+ gem 'rack-test'
8
+ gem 'puma'
9
+ if RUBY_VERSION < '1.9.3'
10
+ # i18n 0.7.0 dropped support for Ruby 1.9.2 and older. ActiveSupport
11
+ # depends on i18n 0.7.0 since v 4.0.5. For < 1.9.2 Ruby support, lock
12
+ # down to these versions to maintain functionality.
13
+ gem 'i18n', '< 0.7.0'
14
+ gem 'activesupport', '< 4.0.5'
15
+ gem 'appraisal'
16
+ else
17
+ gem 'appraisal'
18
+ end
19
+ end
20
+
21
+ group :development do
22
+ gem 'ruby-debug', :platforms => [ :mri_18, :jruby ]
23
+ gem 'debugger', :platform => :mri_19
24
+ gem 'byebug', :platforms => [ :mri_20, :mri_21, :mri_22 ]
25
+ # gem 'perftools.rb', :platforms => [ :mri_20, :mri_21 ], :require => 'perftools'
26
+ if RUBY_VERSION > '1.8.7'
27
+ gem 'pry'
28
+ gem 'pry-byebug', :platforms => [ :mri_20, :mri_21, :mri_22 ]
29
+ else
30
+ gem 'pry', '0.9.12.4'
31
+ end
32
+ end
33
+
34
+ # Instrumented gems
35
+ gem 'dalli'
36
+ gem 'memcache-client'
37
+ gem 'cassandra'
38
+ gem 'mongo'
39
+ gem 'resque'
40
+ gem 'redis'
41
+ gem 'faraday'
42
+ gem 'httpclient'
43
+ gem 'excon'
44
+ gem 'typhoeus'
45
+ gem 'sequel'
46
+ if RUBY_VERSION >= '1.9.3'
47
+ # rest-client depends on mime-types gem which only supports
48
+ # ruby 1.9.3 and up
49
+ gem 'rest-client'
50
+ end
51
+
52
+ # Database adapter gems needed by sequel
53
+ if defined?(JRUBY_VERSION)
54
+ gem 'jdbc-postgresql'
55
+ gem 'jdbc-mysql'
56
+ else
57
+ gem 'mysql'
58
+ gem 'mysql2'
59
+ if RUBY_VERSION < '1.9.3'
60
+ gem 'pg', '0.17.1'
61
+ else
62
+ gem 'pg'
63
+ end
64
+ end
65
+
66
+ if RUBY_VERSION >= '1.9'
67
+ gem 'moped'
68
+ gem 'eventmachine'
69
+ gem 'em-synchrony'
70
+ gem 'em-http-request'
71
+ end
72
+
73
+ unless defined?(JRUBY_VERSION)
74
+ gem 'memcached', '1.7.2' if RUBY_VERSION < '2.0.0'
75
+ gem 'bson_ext' # For Mongo, Yours Truly
76
+ end
77
+
78
+ # Instrumented Frameworks
79
+
80
+ if defined?(JRUBY_VERSION)
81
+ gem 'sinatra', :require => false
82
+ else
83
+ gem 'sinatra'
84
+ end
85
+
86
+ if RUBY_VERSION >= '1.9.3'
87
+ gem 'padrino', '0.12.0'
88
+ gem 'grape'
89
+ gem 'bson'
90
+ else
91
+ gem 'bson', '1.10.2'
92
+ end
93
+
94
+ gemspec
95
+
data/LICENSE ADDED
@@ -0,0 +1,199 @@
1
+ AppNeta Open License, Version 1.0
2
+
3
+ AppNeta Open License
4
+ Version 1.0, April, 2013
5
+
6
+ http://www.appneta.com/appneta-license
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction, and
13
+ distribution as defined by Sections 1 through 11 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
16
+ owner that is granting the License. Licensor can include AppNeta as an
17
+ original contributor to the Work as defined below.
18
+
19
+ "Legal Entity" shall mean the union of the acting entity and all other entities
20
+ that control, are controlled by, or are under common control with that entity.
21
+ For the purposes of this definition, "control" means (i) the power, direct or
22
+ indirect, to cause the direction or management of such entity, whether by
23
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
27
+ permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications, including
30
+ but not limited to software source code, documentation source, and
31
+ configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical transformation or
34
+ translation of a Source form, including but not limited to compiled object
35
+ code, generated documentation, and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or Object form,
38
+ made available under the License, as indicated by a copyright notice that is
39
+ included in or attached to the work (an example is provided in the Appendix
40
+ below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
43
+ is based on (or derived from) the Work and for which the editorial revisions,
44
+ annotations, elaborations, or other modifications represent, as a whole, an
45
+ original work of authorship. For the purposes of this License, Derivative Works
46
+ shall not include works that remain separable from, or merely link (or bind by
47
+ name) to the interfaces of, the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including the original
50
+ version of the Work and any modifications or additions to that Work or
51
+ Derivative Works thereof, that is intentionally submitted to Licensor for
52
+ inclusion in the Work by the copyright owner or by an individual or Legal
53
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
54
+ of this definition, "submitted" means any form of electronic, verbal, or
55
+ written communication sent to the Licensor or its representatives, including
56
+ but not limited to communication on electronic mailing lists, source code
57
+ control systems, and issue tracking systems that are managed by, or on behalf
58
+ of, the Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise designated in
60
+ writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
63
+ of whom a Contribution has been received by Licensor and subsequently
64
+ incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License.
67
+
68
+ Subject to the terms and conditions of this License, each Contributor hereby
69
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
70
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the Work and
72
+ such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License.
75
+
76
+ Subject to the terms and conditions of this License, each Contributor hereby
77
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
78
+ irrevocable (except as stated in this section) patent license to make, have
79
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
80
+ such license applies only to those patent claims licensable by such Contributor
81
+ that are necessarily infringed by their Contribution(s) alone or by combination
82
+ of their Contribution(s) with the Work to which such Contribution(s) was
83
+ submitted. If You institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
85
+ Contribution incorporated within the Work constitutes direct or contributory
86
+ patent infringement, then any patent licenses granted to You under this License
87
+ for that Work shall terminate as of the date such litigation is filed.
88
+
89
+ Each time You convey a covered Work, the recipient automatically receives a
90
+ license from the original Licensor(s), to run, modify and propagate that work,
91
+ subject to this License. You are not responsible for enforcing compliance by
92
+ third parties with this License.
93
+
94
+ You may not impose any further restrictions on the exercise of the rights
95
+ granted or affirmed under this License. For example, you may not impose a
96
+ license fee, royalty, or other charge for exercise of rights granted under this
97
+ License, and you may not initiate litigation (including a cross-claim or
98
+ counterclaim in a lawsuit) alleging that any patent claim is infringed by
99
+ making, using, selling, offering for sale, or importing the Work or any portion
100
+ of it.
101
+
102
+ 4. Redistribution.
103
+
104
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
105
+ in any medium, with or without modifications, and in Source or Object form,
106
+ provided that You meet the following conditions:
107
+
108
+ 1. You must give any other recipients of the Work or Derivative Works a copy
109
+ of this License; and
110
+ 2. You must cause any modified files to carry prominent notices stating that
111
+ You changed the files; and
112
+ 3. You must retain, in the Source form of any Derivative Works that You
113
+ distribute, all copyright, patent, trademark, and attribution notices from the
114
+ Source form of the Work, excluding those notices that do not pertain to any
115
+ part of the Derivative Works; and
116
+ 4. If the Work includes a "NOTICE" text file as part of its distribution,
117
+ then any Derivative Works that You distribute must include a readable copy of
118
+ the attribution notices contained within such NOTICE file, excluding those
119
+ notices that do not pertain to any part of the Derivative Works, in at least
120
+ one of the following places: within a NOTICE text file distributed as part of
121
+ the Derivative Works; within the Source form or documentation, if provided
122
+ along with the Derivative Works; or, within a display generated by the
123
+ Derivative Works, if and wherever such third-party notices normally appear. The
124
+ contents of the NOTICE file are for informational purposes only and do not
125
+ modify the License. You may add Your own attribution notices within Derivative
126
+ Works that You distribute, alongside or as an addendum to the NOTICE text from
127
+ the Work, provided that such additional attribution notices cannot be construed
128
+ as modifying the License.
129
+
130
+ You may add Your own copyright statement to Your modifications and may provide
131
+ additional or different license terms and conditions for use, reproduction, or
132
+ distribution of Your modifications, or for any such Derivative Works as a
133
+ whole, provided Your use, reproduction, and distribution of the Work otherwise
134
+ complies with the conditions stated in this License.
135
+
136
+ 5. Submission of Contributions.
137
+
138
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
139
+ for inclusion in the Work by You to the Licensor shall be under the terms and
140
+ conditions of this License, without any additional terms or conditions.
141
+ Notwithstanding the above, nothing herein shall supersede or modify the terms
142
+ of any separate license agreement you may have executed with Licensor regarding
143
+ such Contributions.
144
+
145
+ 6. Trademarks.
146
+
147
+ This License does not grant permission to use the trade names, trademarks,
148
+ service marks, or product names of the Licensor, except as required for
149
+ reasonable and customary use in describing the origin of the Work and
150
+ reproducing the content of the NOTICE file.
151
+
152
+ 7. Disclaimer of Warranty.
153
+
154
+ Unless required by applicable law or agreed to in writing, Licensor provides
155
+ the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
156
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
157
+ including, without limitation, any warranties or conditions of TITLE,
158
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
159
+ solely responsible for determining the appropriateness of using or
160
+ redistributing the Work and assume any risks associated with Your exercise of
161
+ permissions under this License.
162
+
163
+ 8. Limitation of Liability.
164
+
165
+ In no event and under no legal theory, whether in tort (including negligence),
166
+ contract, or otherwise, unless required by applicable law (such as deliberate
167
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
168
+ liable to You for damages, including any direct, indirect, special, incidental,
169
+ or consequential damages of any character arising as a result of this License
170
+ or out of the use or inability to use the Work (including but not limited to
171
+ damages for loss of goodwill, work stoppage, computer failure or malfunction,
172
+ or any and all other commercial damages or losses), even if such Contributor
173
+ has been advised of the possibility of such damages.
174
+
175
+ 9. Accepting Warranty or Additional Liability.
176
+
177
+ While redistributing the Work or Derivative Works thereof, You may choose to
178
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
179
+ other liability obligations and/or rights consistent with this License.
180
+ However, in accepting such obligations, You may act only on Your own behalf and
181
+ on Your sole responsibility, not on behalf of any other Contributor, and only
182
+ if You agree to indemnify, defend, and hold each Contributor harmless for any
183
+ liability incurred by, or claims asserted against, such Contributor by reason
184
+ of your accepting any such warranty or additional liability.
185
+
186
+ 10. Noncompetition
187
+
188
+ You may install and execute the Work only in conjunction with the direct use of
189
+ AppNeta software. This Work, any file or any derivative thereof shall not be
190
+ used in conjunction with any product that competes with any AppNeta software.
191
+
192
+ 11. Termination
193
+
194
+ The License stated above is automatically terminated and revoked if you exceed
195
+ its scope or violate any of the terms of this License or any related License or
196
+ notice.
197
+
198
+ END OF TERMS AND CONDITIONS
199
+
data/README.md ADDED
@@ -0,0 +1,380 @@
1
+ # Welcome to the TraceView Ruby Gem
2
+
3
+ The traceview gem provides AppNeta [TraceView](http://www.appneta.com/application-performance-management/) performance instrumentation for Ruby.
4
+
5
+ ![Ruby TraceView](https://s3.amazonaws.com/pglombardo/oboe-ruby-header.png)
6
+
7
+ 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://docs.appneta.com/ruby-instrumentation-supported-components)
8
+
9
+ 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/).
10
+
11
+ [![Oboe API Documentation](https://www.omniref.com/ruby/gems/oboe.png)](https://www.omniref.com/ruby/gems/oboe)
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 traceview gem is [available on Rubygems](https://rubygems.org/gems/traceview) and can be installed with:
19
+
20
+ ```bash
21
+ gem install traceview
22
+ ```
23
+
24
+ or added to _the end_ of your bundle Gemfile and running `bundle install`:
25
+
26
+ ```ruby
27
+ gem 'traceview'
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 traceview 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 traceview gem provides a Rails generator used to seed an initializer where you can configure and control `tracing_mode` and [other options](https://docs.appneta.com/configuring-ruby-instrumentation)
43
+
44
+ To run the install generator run:
45
+
46
+ ```bash
47
+ bundle exec rails generate traceview:install
48
+ ```
49
+
50
+ After the prompts, this will create an initializer: `config/initializers/traceview.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 'traceview'
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
+ TraceView::Config[:tracing_mode] = 'through'
66
+
67
+ # You may want to replace the TraceView.logger with whichever logger you are using
68
+ # TraceView.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 traceview gem is loaded _after_ Sinatra either by listing `gem 'traceview'` after Sinatra in your Gemfile or calling the `require 'traceview'` directive after Sinatra is loaded.
74
+
75
+ With this, the traceview gem will automatically detect Sinatra on boot and instrument key components.
76
+
77
+ ## Padrino
78
+
79
+ As long as the traceview gem is in your `Gemfile` (inserted after the `gem 'padrino'` directive) and you are calling `Bundler.require`, the traceview gem will automatically instrument Padrino applications.
80
+
81
+ If you need to set `TraceView::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
+ TraceView::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 'traceview'
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
+ TraceView::Config[:tracing_mode] = 'through'
110
+
111
+ ...
112
+
113
+ class App < Grape::API
114
+ use TraceView::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 traceview gem is loaded _after_ Grape either by listing `gem 'traceview'` after Grape in your Gemfile or calling the `require 'traceview'` directive after Grape is loaded.
121
+
122
+ You must explicitly tell your Grape application to use TraceView::Rack for tracing to occur.
123
+
124
+ ## Custom Ruby Scripts & Applications
125
+
126
+ The traceview gem has the ability to instrument any arbitrary Ruby application or script. Only the `tracing_mode` needs to be set to tell the traceview gem to initiate performance metric collection.
127
+
128
+ ```ruby
129
+ require 'rubygems'
130
+ require 'bundler'
131
+
132
+ Bundler.require
133
+
134
+ require 'traceview'
135
+
136
+ # Tracing mode can be 'never', 'through' (to follow upstream) or 'always'
137
+ TraceView::Config[:tracing_mode] = 'always'
138
+ ```
139
+
140
+ From here, you can use the Tracing API to instrument areas of code using `TraceView::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.
141
+
142
+ Once inside of the `TraceView::API.start_trace` block, performance metrics will be automatically collected for all supported libraries and gems (Redis, Mongo, ActiveRecord etc..).
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://docs.appneta.com/capistrano-deploy-notifications-tlog)
147
+
148
+ # Custom Tracing
149
+
150
+ ## The Tracing API
151
+
152
+ You can instrument any arbitrary block of code using `TraceView::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
+ TraceView::API.trace(layer_name, report_kvs) do
167
+ # the block of code to be traced
168
+ end
169
+ ```
170
+
171
+ `TraceView::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 `TraceView.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 `TraceView::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/TraceView/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 TraceViewMethodProfiling
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://docs.appneta.com/custom-ruby-instrumentation) 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://tickets.appneta.com) 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 traceview 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 traceview 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 Documentation Portal](https://docs.appneta.com/ruby) has a large collection of technical articles or, if needed, you can [submit a support request](https://tickets.appneta.com) 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 traceview gem uses a standard gem layout. Here are the notable directories.
228
+
229
+ lib/traceview/inst # Auto load directory for various instrumented libraries
230
+ lib/traceview/frameworks # Framework instrumentation directory
231
+ lib/traceview/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 traceview gem is built with the standard `gem build` command passing in the gemspec:
239
+
240
+ ```bash
241
+ gem build traceview.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 TraceView 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/traceview/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 (TraceView::Inst::Dalli) and our own custom `perform_with_traceview` 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](https://www.omniref.com/ruby/2.2.1/symbols/Module/included).
253
+
254
+ ```ruby
255
+ module TraceView
256
+ module Inst
257
+ module Dalli
258
+ include TraceView::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_traceview perform
264
+ alias perform perform_with_traceview
265
+ end
266
+ end
267
+ end
268
+
269
+ def perform_with_traceview(*all_args, &blk)
270
+ op, key, *args = *all_args
271
+
272
+ if TraceView.tracing?
273
+ opts = {}
274
+ opts[:KVOp] = op
275
+ opts[:KVKey] = key
276
+
277
+ TraceView::API.trace('memcache', opts || {}) do
278
+ result = perform_without_traceview(*all_args, &blk)
279
+ if op == :get and key.class == String
280
+ TraceView::API.log('memcache', 'info', { :KVHit => memcache_hit?(result) })
281
+ end
282
+ result
283
+ end
284
+ else
285
+ perform_without_traceview(*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 TraceView::Config[:dalli][:enabled]
297
+ ::Dalli::Client.module_eval do
298
+ include TraceView::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 `TraceView::API.trace` method to time the execution of the original operation.
304
+
305
+ The `TraceView::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 traceview gem source by using `gem 'traceview', :path => '/path/to/oboe-ruby'`
312
+
313
+ * If instrumenting a library, database or service, place your new instrumentation file into the `lib/traceview/inst/` directory. From there, the traceview gem will detect it and automatically load the instrumentation file.
314
+
315
+ * If instrumenting a new framework, place your instrumentation file in `lib/traceview/frameworks`. Refer to the Rails instrumentation for on ideas on how to load the traceview gem correctly in your framework.
316
+
317
+ * Review other existing instrumentation similar to the one you wish to author. `lib/traceview/inst/` is a great place to start.
318
+
319
+ * Depending on the configured `:sample_rate`, not all requests will be traced. Use `TraceView.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 traceview 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://docs.appneta.com/installation-overview) 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
+