appoptics_apm-zearn 4.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +5 -0
  3. data/.github/ISSUE_TEMPLATE/bug-or-feature-request.md +16 -0
  4. data/.github/workflows/build_and_release_gem.yml +103 -0
  5. data/.github/workflows/build_for_packagecloud.yml +70 -0
  6. data/.github/workflows/docker-images.yml +47 -0
  7. data/.github/workflows/run_cpluplus_tests.yml +73 -0
  8. data/.github/workflows/run_tests.yml +168 -0
  9. data/.github/workflows/scripts/test_install.rb +23 -0
  10. data/.github/workflows/swig/swig-v4.0.2.tar.gz +0 -0
  11. data/.github/workflows/test_on_4_linux.yml +159 -0
  12. data/.gitignore +36 -0
  13. data/.rubocop.yml +29 -0
  14. data/.travis.yml +130 -0
  15. data/.yardopts +6 -0
  16. data/CHANGELOG.md +769 -0
  17. data/CONFIG.md +33 -0
  18. data/Gemfile +14 -0
  19. data/LICENSE +202 -0
  20. data/README.md +393 -0
  21. data/appoptics_apm.gemspec +70 -0
  22. data/bin/appoptics_apm_config +15 -0
  23. data/examples/prepend.rb +13 -0
  24. data/examples/sdk_examples.rb +158 -0
  25. data/ext/oboe_metal/README.md +69 -0
  26. data/ext/oboe_metal/extconf.rb +151 -0
  27. data/ext/oboe_metal/lib/.keep +0 -0
  28. data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.0.0.0.sha256 +1 -0
  29. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.0.0.0.sha256 +1 -0
  30. data/ext/oboe_metal/noop/noop.c +8 -0
  31. data/ext/oboe_metal/src/README.md +6 -0
  32. data/ext/oboe_metal/src/VERSION +2 -0
  33. data/ext/oboe_metal/src/bson/bson.h +220 -0
  34. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  35. data/ext/oboe_metal/src/frames.cc +246 -0
  36. data/ext/oboe_metal/src/frames.h +40 -0
  37. data/ext/oboe_metal/src/init_appoptics_apm.cc +21 -0
  38. data/ext/oboe_metal/src/logging.cc +95 -0
  39. data/ext/oboe_metal/src/logging.h +35 -0
  40. data/ext/oboe_metal/src/oboe.h +1156 -0
  41. data/ext/oboe_metal/src/oboe_api.cpp +652 -0
  42. data/ext/oboe_metal/src/oboe_api.hpp +431 -0
  43. data/ext/oboe_metal/src/oboe_debug.h +59 -0
  44. data/ext/oboe_metal/src/oboe_swig_wrap.cc +7329 -0
  45. data/ext/oboe_metal/src/profiling.cc +435 -0
  46. data/ext/oboe_metal/src/profiling.h +78 -0
  47. data/ext/oboe_metal/test/CMakeLists.txt +53 -0
  48. data/ext/oboe_metal/test/FindGMock.cmake +43 -0
  49. data/ext/oboe_metal/test/README.md +56 -0
  50. data/ext/oboe_metal/test/frames_test.cc +164 -0
  51. data/ext/oboe_metal/test/profiling_test.cc +93 -0
  52. data/ext/oboe_metal/test/ruby_inc_dir.rb +8 -0
  53. data/ext/oboe_metal/test/ruby_prefix.rb +8 -0
  54. data/ext/oboe_metal/test/ruby_test_helper.rb +67 -0
  55. data/ext/oboe_metal/test/test.h +11 -0
  56. data/ext/oboe_metal/test/test_main.cc +32 -0
  57. data/init.rb +4 -0
  58. data/lib/appoptics_apm/api/layerinit.rb +41 -0
  59. data/lib/appoptics_apm/api/logging.rb +381 -0
  60. data/lib/appoptics_apm/api/memcache.rb +37 -0
  61. data/lib/appoptics_apm/api/metrics.rb +63 -0
  62. data/lib/appoptics_apm/api/tracing.rb +57 -0
  63. data/lib/appoptics_apm/api/util.rb +120 -0
  64. data/lib/appoptics_apm/api.rb +21 -0
  65. data/lib/appoptics_apm/base.rb +231 -0
  66. data/lib/appoptics_apm/config.rb +299 -0
  67. data/lib/appoptics_apm/frameworks/grape.rb +98 -0
  68. data/lib/appoptics_apm/frameworks/padrino.rb +78 -0
  69. data/lib/appoptics_apm/frameworks/rails/inst/action_controller.rb +104 -0
  70. data/lib/appoptics_apm/frameworks/rails/inst/action_controller4.rb +48 -0
  71. data/lib/appoptics_apm/frameworks/rails/inst/action_controller5.rb +50 -0
  72. data/lib/appoptics_apm/frameworks/rails/inst/action_controller6.rb +50 -0
  73. data/lib/appoptics_apm/frameworks/rails/inst/action_controller_api.rb +50 -0
  74. data/lib/appoptics_apm/frameworks/rails/inst/action_view.rb +88 -0
  75. data/lib/appoptics_apm/frameworks/rails/inst/active_record.rb +27 -0
  76. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  77. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +29 -0
  78. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +31 -0
  79. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +119 -0
  80. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +114 -0
  81. data/lib/appoptics_apm/frameworks/rails/inst/logger_formatters.rb +27 -0
  82. data/lib/appoptics_apm/frameworks/rails.rb +100 -0
  83. data/lib/appoptics_apm/frameworks/sinatra.rb +96 -0
  84. data/lib/appoptics_apm/inst/bunny-client.rb +148 -0
  85. data/lib/appoptics_apm/inst/bunny-consumer.rb +89 -0
  86. data/lib/appoptics_apm/inst/curb.rb +332 -0
  87. data/lib/appoptics_apm/inst/dalli.rb +85 -0
  88. data/lib/appoptics_apm/inst/delayed_job.rb +92 -0
  89. data/lib/appoptics_apm/inst/em-http-request.rb +101 -0
  90. data/lib/appoptics_apm/inst/excon.rb +125 -0
  91. data/lib/appoptics_apm/inst/faraday.rb +106 -0
  92. data/lib/appoptics_apm/inst/graphql.rb +240 -0
  93. data/lib/appoptics_apm/inst/grpc_client.rb +159 -0
  94. data/lib/appoptics_apm/inst/grpc_server.rb +120 -0
  95. data/lib/appoptics_apm/inst/http.rb +81 -0
  96. data/lib/appoptics_apm/inst/httpclient.rb +174 -0
  97. data/lib/appoptics_apm/inst/logger_formatter.rb +50 -0
  98. data/lib/appoptics_apm/inst/logging_log_event.rb +28 -0
  99. data/lib/appoptics_apm/inst/lumberjack_formatter.rb +13 -0
  100. data/lib/appoptics_apm/inst/memcached.rb +86 -0
  101. data/lib/appoptics_apm/inst/mongo.rb +246 -0
  102. data/lib/appoptics_apm/inst/mongo2.rb +225 -0
  103. data/lib/appoptics_apm/inst/moped.rb +466 -0
  104. data/lib/appoptics_apm/inst/rack.rb +182 -0
  105. data/lib/appoptics_apm/inst/rack_cache.rb +35 -0
  106. data/lib/appoptics_apm/inst/redis.rb +274 -0
  107. data/lib/appoptics_apm/inst/resque.rb +151 -0
  108. data/lib/appoptics_apm/inst/rest-client.rb +48 -0
  109. data/lib/appoptics_apm/inst/sequel.rb +178 -0
  110. data/lib/appoptics_apm/inst/sidekiq-client.rb +55 -0
  111. data/lib/appoptics_apm/inst/sidekiq-worker.rb +66 -0
  112. data/lib/appoptics_apm/inst/twitter-cassandra.rb +294 -0
  113. data/lib/appoptics_apm/inst/typhoeus.rb +108 -0
  114. data/lib/appoptics_apm/instrumentation.rb +22 -0
  115. data/lib/appoptics_apm/loading.rb +65 -0
  116. data/lib/appoptics_apm/logger.rb +14 -0
  117. data/lib/appoptics_apm/noop/README.md +9 -0
  118. data/lib/appoptics_apm/noop/context.rb +27 -0
  119. data/lib/appoptics_apm/noop/metadata.rb +25 -0
  120. data/lib/appoptics_apm/noop/profiling.rb +21 -0
  121. data/lib/appoptics_apm/oboe_init_options.rb +211 -0
  122. data/lib/appoptics_apm/ruby.rb +35 -0
  123. data/lib/appoptics_apm/sdk/current_trace.rb +77 -0
  124. data/lib/appoptics_apm/sdk/custom_metrics.rb +94 -0
  125. data/lib/appoptics_apm/sdk/logging.rb +37 -0
  126. data/lib/appoptics_apm/sdk/tracing.rb +434 -0
  127. data/lib/appoptics_apm/support/profiling.rb +18 -0
  128. data/lib/appoptics_apm/support/transaction_metrics.rb +67 -0
  129. data/lib/appoptics_apm/support/transaction_settings.rb +219 -0
  130. data/lib/appoptics_apm/support/x_trace_options.rb +110 -0
  131. data/lib/appoptics_apm/support_report.rb +119 -0
  132. data/lib/appoptics_apm/test.rb +95 -0
  133. data/lib/appoptics_apm/thread_local.rb +26 -0
  134. data/lib/appoptics_apm/util.rb +326 -0
  135. data/lib/appoptics_apm/version.rb +16 -0
  136. data/lib/appoptics_apm/xtrace.rb +115 -0
  137. data/lib/appoptics_apm.rb +77 -0
  138. data/lib/joboe_metal.rb +212 -0
  139. data/lib/oboe.rb +7 -0
  140. data/lib/oboe_metal.rb +172 -0
  141. data/lib/rails/generators/appoptics_apm/install_generator.rb +47 -0
  142. data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +425 -0
  143. data/log/.keep +0 -0
  144. data/yardoc_frontpage.md +26 -0
  145. metadata +231 -0
data/CONFIG.md ADDED
@@ -0,0 +1,33 @@
1
+ # AppOpticsAPM Gem Configuration
2
+
3
+ ## Environment Variables
4
+
5
+ The following environment variables are detected by the appoptics_apm gem and affect how the gem functions.
6
+
7
+ ### General
8
+
9
+ Name | Description | Default
10
+ ---- | ----------- | -------
11
+ `APPOPTICS_SERVICE_KEY` | API token + service name combination, mandatory for metrics and traces to show in my.appoptics.com |
12
+ `IGNORE_APPOPTICS_WARNING` | tells the appoptics_apm gem to __not__ output the _missing AppOpticsAPM libraries_ message on stack initialization | `false`
13
+ `APPOPTICS_GEM_VERBOSE` | sets the verbose flag (`AppOpticsAPM::Config[:verbose]`) early in the gem loading process which may output valuable information | `false`
14
+ `APPOPTICS_CUUID` | Allows specifying the customer ID via environment variable to override/bypass the value in `/etc/tracelytics.conf` | `nil`
15
+
16
+ # Related to Tests
17
+
18
+ Name | Description | Default
19
+ ---- | ----------- | -------
20
+ `APPOPTICS_GEM_TEST` | puts the gem in test mode to avoid restarting certain background services used in testing. `false`
21
+ `DBTYPE` | For tests on Ruby on Rails, specifies the database type to test against. `postgres`, `mysql` and `mysql2` are valid options. | `postgres`
22
+ `APPOPTICS_CASSANDRA_SERVER` | specifies the Cassandra server to test against. | `127.0.0.1:9160`
23
+ `APPOPTICS_MONGO_SERVER` | specifies the Mongo server to test against. | `127.0.0.1:27017`
24
+ `APPOPTICS_RABBITMQ_SERVER` | specifies the RabbitMQ server to test against. | `127.0.0.1`
25
+ `APPOPTICS_RABBITMQ_PORT` | port for the RabbitMQ connection. | `5672`
26
+ `APPOPTICS_RABBITMQ_USERNAME` | username for the RabbitMQ connection | `guest`
27
+ `APPOPTICS_RABBITMQ_PASSWORD` | password for the RabbitMQ connection | `guest`
28
+
29
+ ## AppOpticsAPM::Config
30
+
31
+ `AppOpticsAPM::Config` is a nested hash used by the appoptics_apm gem to store preferences and switches.
32
+
33
+ See [this Rails generator template file](https://github.com/librato/ruby-appoptics/blob/master/lib/rails/generators/appoptics_apm/templates/appoptics_initializer.rb) for documentation on all of the supported values.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # this Gemfile is very minimal
4
+ # use rake commands or gemfiles in the gemfiles directory for testing
5
+
6
+ gem 'rake', '>= 0.9.0'
7
+
8
+ group :development, :test do
9
+ gem 'byebug', '>= 8.0.0'
10
+ gem 'irb', '>= 1.0.0' # if RUBY_VERSION >= '2.6.0'
11
+ gem 'memory_profiler'
12
+ end
13
+
14
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,393 @@
1
+ # Welcome to the AppOpticsAPM Ruby Gem
2
+
3
+ The appoptics_apm gem provides [AppOptics APM](https://www.appoptics.com/) performance instrumentation for Ruby.
4
+
5
+ ![Ruby AppOpticsAPM](https://docs.appoptics.com/_images/ruby_trace_smaller.png)
6
+
7
+ It has the ability to report performance metrics on an array of libraries, databases and frameworks such as Rails,
8
+ Mongo, Memcache, ActiveRecord, Cassandra, Rack, Resque
9
+ [and more](https://docs.appoptics.com/kb/apm_tracing/ruby/support-matrix/).
10
+
11
+ It requires an [AppOptics](https://www.appoptics.com/) account to view metrics. Get yours,
12
+ [it's free](https://my.appoptics.com/sign_up).
13
+
14
+ [![Gem Version](https://badge.fury.io/rb/appoptics_apm.svg)](https://badge.fury.io/rb/appoptics_apm)
15
+
16
+ [![Run all Tests](https://github.com/appoptics/appoptics-apm-ruby/actions/workflows/run_tests.yml/badge.svg)](https://github.com/appoptics/appoptics-apm-ruby/actions/workflows/run_tests.yml)
17
+ [![C++ Tests](https://github.com/appoptics/appoptics-apm-ruby/actions/workflows/run_cpluplus_tests.yml/badge.svg)](https://github.com/appoptics/appoptics-apm-ruby/actions/workflows/run_cpluplus_tests.yml)
18
+
19
+ [comment]: <> ([![Maintainability]&#40;https://api.codeclimate.com/v1/badges/ac7f36241a23a3a82fc5/maintainability&#41;]&#40;https://codeclimate.com/github/appoptics/appoptics-apm-ruby/maintainability&#41;)
20
+
21
+ # Documentation
22
+
23
+ * [AppOptics Knowledge Base](https://docs.appoptics.com/kb/apm_tracing/ruby)
24
+
25
+ # Installation
26
+
27
+ _Before installing the gem below, make sure that you have the
28
+ [dependencies](http://docs.appoptics.com/kb/apm_tracing/ruby/install#dependencies) installed on your host first._
29
+
30
+ The appoptics_apm gem is [available on Rubygems](https://rubygems.org/gems/appoptics_apm) and can be installed with:
31
+
32
+ ```bash
33
+ gem install appoptics_apm
34
+ ```
35
+
36
+ or added to **the end** of your Gemfile and running `bundle install`:
37
+
38
+ ```ruby
39
+ gem 'appoptics_apm'
40
+ ```
41
+
42
+ # Running
43
+
44
+ Make sure to set `APPOPTICS_SERVICE_KEY` in the environment from where the app or service is run, e.g:
45
+ ```
46
+ export APPOPTICS_SERVICE_KEY=795fb4947d15275d208c49cfd2412d4a5bf38742045b47236c94c4fe5f5b17c7:<your_app_name>
47
+ ```
48
+
49
+ ## Rails
50
+
51
+ ![Ruby on Rails](https://docs.appoptics.com/_images/rails.png)
52
+
53
+ No special steps are needed to instrument Ruby on Rails. Once part of the bundle, the appoptics gem will automatically
54
+ detect Rails and instrument on stack initialization.
55
+
56
+ ### The Install Generator
57
+
58
+ The appoptics_apm gem provides a Rails generator used to seed an initializer where you can configure and control
59
+ `tracing_mode` and [other options](http://docs.appoptics.com/kb/apm_tracing/ruby/configure).
60
+
61
+ To run the install generator run:
62
+
63
+ ```bash
64
+ bundle exec rails generate appoptics_apm:install
65
+ ```
66
+
67
+ After the prompts, this will create an initializer: `config/initializers/appoptics_apm.rb`.
68
+
69
+ ## Sinatra
70
+
71
+ ![Sinatra](https://docs.appoptics.com/_images/sinatra.png)
72
+
73
+ You can instrument your Sinatra application by adding the following code to your `config.ru` Rackup file:
74
+
75
+ ```ruby
76
+ # If you're not using Bundler.require. Make sure this is done
77
+ # after the Sinatra require directive.
78
+ require 'appoptics_apm'
79
+ ```
80
+
81
+ Make sure that the appoptics_apm gem is loaded _after_ Sinatra either by listing `gem 'appoptics_apm'` after Sinatra in
82
+ your Gemfile or calling the `require 'appoptics_gem'` directive after Sinatra is loaded.
83
+
84
+ With this, the appoptics_apm gem will automatically detect Sinatra on boot and instrument key components.
85
+
86
+ ## Padrino
87
+
88
+ ![Padrino](https://docs.appoptics.com/_images/padrino.svg)
89
+
90
+ As long as the appoptics_apm gem is in your `Gemfile` (inserted after the `gem 'padrino'` directive) and you are calling
91
+ `Bundler.require`, the appoptics_apm gem will automatically instrument Padrino applications.
92
+
93
+ If you need to set `AppOpticsAPM::Config` values on stack boot, you can do so by adding the following
94
+ to your `config/boot.rb` file:
95
+
96
+ ```ruby
97
+ Padrino.before_load do
98
+ # Verbose output of instrumentation initialization
99
+ AppOpticsAPM
100
+ end
101
+ ```
102
+
103
+ ## Grape
104
+
105
+ ![Grape](https://docs.appoptics.com/_images/grape.png)
106
+
107
+ You can instrument your Grape application by adding the following code to your `config.ru` Rackup file:
108
+
109
+ ```ruby
110
+ # If you're not using Bundler.require. Make sure this is done
111
+ # after the Grape require directive.
112
+ require 'appoptics_apm'
113
+
114
+ ...
115
+
116
+ class App < Grape::API
117
+ use AppOpticsAPM::Rack
118
+ end
119
+ ```
120
+
121
+ Make sure that the appoptics gem is loaded _after_ Grape either by listing `gem 'appoptics_apm'` after Grape in your
122
+ Gemfile or calling the `require 'appoptics_apm'` directive after Grape is loaded.
123
+
124
+ You must explicitly tell your Grape application to use AppOpticsAPM::Rack for tracing to occur.
125
+
126
+
127
+ # SDK for Custom Tracing
128
+
129
+ The appoptics_apm gem has the ability to instrument any arbitrary Ruby application or script.
130
+
131
+ ```ruby
132
+ require 'rubygems'
133
+ require 'bundler'
134
+
135
+ Bundler.require
136
+
137
+ require 'appoptics_apm'
138
+ ```
139
+
140
+ You can add even more visibility into any part of your application or scripts by adding custom instrumentation.
141
+
142
+ ## AppOpticsAPM::SDK.trace
143
+ You can instrument any arbitrary block of code using `AppOpticsAPM::SDK.trace`.
144
+
145
+ ```ruby
146
+ # layer_name will show up in the AppOptics app dashboard
147
+ layer_name = 'subsystemX'
148
+
149
+ # report_kvs are a set of information Key/Value pairs that are sent to
150
+ # AppOptics dashboard along with the performance metrics. These KV
151
+ # pairs are used to report request, environment and/or client specific
152
+ # information.
153
+
154
+ report_kvs = {}
155
+ report_kvs[:mykey] = @client.id
156
+
157
+ AppOpticsAPM::SDK.trace(layer_name, report_kvs) do
158
+ # the block of code to be traced
159
+ end
160
+ ```
161
+
162
+ `AppOpticsAPM::SDK.trace` is used within the context of a request. It will follow the upstream state of the request
163
+ being traced. i.e. the block of code will only be traced when the parent request is being traced.
164
+
165
+ This tracing state of a request can also be queried by using `AppOpticsAPM.tracing?`.
166
+
167
+ ## AppOpticsAPM::SDK.start_trace
168
+
169
+ If you need to instrument code outside the context of a request (such as a cron job, background job or an arbitrary
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).
172
+
173
+
174
+
175
+ ### Example
176
+
177
+ ```ruby
178
+ require 'rubygems'
179
+ require 'bundler'
180
+
181
+ Bundler.require
182
+
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 :enabled or :disabled
189
+ AppOpticsAPM::Config[:tracing_mode] = :enabled
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.
233
+
234
+ # Support
235
+
236
+ If you run into a problem, find a bug, or would like to request an enhancement, feel free to contact our tech support
237
+ [technicalsupport@solarwinds.com](technicalsupport@solarwinds.com).
238
+
239
+ # Contributing
240
+
241
+ You are obviously a person of great sense and intelligence. We happily appreciate all contributions to the appoptics
242
+ gem whether it is documentation, a bug fix, new instrumentation for a library or framework or anything else we haven't
243
+ thought of.
244
+
245
+ We welcome you to send us PRs. We also humbly request that any new instrumentation submissions have corresponding tests
246
+ that accompany them. This way we don't break any of your additions when we (and others) make changes after the fact.
247
+
248
+
249
+ ## Layout of the Gem
250
+
251
+ The appoptics gem uses a standard gem layout. Here are the notable directories.
252
+
253
+ lib/appoptics/inst # Auto load directory for various instrumented libraries
254
+ lib/appoptics/frameworks # Framework instrumentation directory
255
+ lib/appoptics/frameworks/rails # Files specific to Rails instrumentation
256
+ lib/rails # A Rails required directory for the Rails install generator
257
+ lib/api # The AppOpticsAPM Tracing API: layers, logging, tracing
258
+ ext/oboe_metal # The Ruby c extension that links against the system liboboe library
259
+
260
+ ## Building the Gem
261
+
262
+ The appoptics gem is built with the standard `gem build` command passing in the gemspec:
263
+
264
+ ```bash
265
+ gem build appoptics_apm.gemspec
266
+ ```
267
+
268
+ ## Writing Custom Instrumentation
269
+
270
+ Custom instrumentation for a library, database or other service can be authored fairly easily. Generally,
271
+ instrumentation of a library is done by wrapping select operations of that library and timing their execution using the
272
+ AppOpticsAPM Tracing SDK which then reports the metrics to the users' AppOptics dashboard.
273
+
274
+ Here, I'll use a stripped down version of the Dalli instrumentation (`lib/appoptics/inst/dalli.rb`) as a quick example
275
+ of how to instrument a client library (the dalli gem).
276
+
277
+ The Dalli gem nicely routes all memcache operations through a single `perform` operation. Wrapping this method allows
278
+ us to capture all Dalli operations called by an application.
279
+
280
+ First, we define a module (AppOpticsAPM::Inst::Dalli) and our own custom `perform_with_appoptics` method that we will
281
+ use as a wrapper around Dalli's `perform` method. We also declare an `included` method which automatically gets called
282
+ when this module is included by another.
283
+ See [`Module#included` Ruby reference documentation](https://devdocs.io/ruby~2.5/module#method-i-included).
284
+
285
+ ```ruby
286
+ module AppOpticsAPM
287
+ module Inst
288
+ module Dalli
289
+ include AppOpticsAPM::API::Memcache
290
+
291
+ def self.included(cls)
292
+ cls.class_eval do
293
+ if ::Dalli::Client.private_method_defined? :perform
294
+ alias perform_without_appoptics perform
295
+ alias perform perform_with_appoptics
296
+ end
297
+ end
298
+ end
299
+
300
+ def perform_with_appoptics(*all_args, &blk)
301
+ op, key, *args = *all_args
302
+
303
+ if AppOpticsAPM.tracing?
304
+ opts = {}
305
+ opts[:KVOp] = op
306
+ opts[:KVKey] = key
307
+
308
+ AppOpticsAPM::SDK.trace('memcache', opts || {}) do
309
+ result = perform_without_appoptics(*all_args, &blk)
310
+ if op == :get and key.class == String
311
+ AppOpticsAPM::API.log_info('memcache', { :KVHit => memcache_hit?(result) })
312
+ end
313
+ result
314
+ end
315
+ else
316
+ perform_without_appoptics(*all_args, &blk)
317
+ end
318
+ end
319
+
320
+ end
321
+ end
322
+ end
323
+ ```
324
+
325
+ Second, we tail onto the end of the instrumentation file a simple `::Dalli::Client.module_eval` call to tell the Dalli
326
+ module to include our newly defined instrumentation module. Doing this will invoke our previously defined `included` method.
327
+
328
+ ```ruby
329
+ if defined?(Dalli) and AppOpticsAPM::Config[:dalli][:enabled]
330
+ ::Dalli::Client.module_eval do
331
+ include AppOpticsAPM::Inst::Dalli
332
+ end
333
+ end
334
+ ```
335
+
336
+ Third, in our wrapper method, we capture the arguments passed in, collect the operation and key information into a local
337
+ hash and then invoke the `AppOpticsAPM::SDK.trace` method to time the execution of the original operation.
338
+
339
+ The `AppOpticsAPM::SDK.trace` method calls Dalli's native operation and reports the timing metrics and your custom
340
+ `report_kvs` up to AppOptics servers to be shown on the user's dashboard.
341
+
342
+ Some other tips and guidelines:
343
+
344
+ * You can point your Gemfile directly at your cloned appoptics gem source by using
345
+ `gem 'appoptics', :path => '/path/to/ruby-appoptics'`
346
+
347
+ * If instrumenting a library, database or service, place your new instrumentation file into the `lib/appoptics/inst/`
348
+ directory. From there, the appoptics gem will detect it and automatically load the instrumentation file.
349
+
350
+ * If instrumenting a new framework, place your instrumentation file in `lib/appoptics/frameworks`. Refer to the Rails
351
+ instrumentation for on ideas on how to load the appoptics gem correctly in your framework.
352
+
353
+ * Review other existing instrumentation similar to the one you wish to author. `lib/appoptics/inst/` is a great place
354
+ to start.
355
+
356
+ * Depending on the configured `:sample_rate`, not all requests will be traced. Use `AppOpticsAPM.tracing?` to determine
357
+ of this is a request that is being traced.
358
+
359
+ * Performance is paramount. Make sure that your wrapped methods don't slow down users applications.
360
+
361
+ * Include tests with your instrumentation. See `test/instrumentation/` for some examples of existing instrumentation
362
+ tests.
363
+
364
+ ## Compiling the C extension
365
+
366
+ The appoptics gem utilizes a C extension to interface with a core library bundled in with the gem which handles
367
+ reporting the trace and performance data back to AppOptics servers.
368
+
369
+ C extensions are usually built on `gem install` but when working out of a local git repository, it's required that you
370
+ manually build this C extension for the gem to function.
371
+
372
+ To make this simpler, we've included a few rake tasks to automate this process:
373
+
374
+ ```bash
375
+ rake clean # make sure no old stuff is around
376
+ rake fetch_ext_deps # download c-files
377
+ rake compile # Build the gem's c extension
378
+ ```
379
+
380
+ To see the code related to the C extension, take a look at `ext/oboe_metal/extconf.rb` for details.
381
+
382
+ You can read more about Ruby gems with C extensions in the
383
+ [Rubygems Guides](http://guides.rubygems.org/gems-with-extensions/).
384
+
385
+ ## Running the Tests
386
+
387
+ See the README in the test directory.
388
+
389
+ # License
390
+
391
+ Copyright (c) 2018 SolarWinds, LLC
392
+
393
+ Released under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)