signalfx-tracing 1.1.0 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ba2591d862b7c31748ce57e4011d1cf6e810811c
4
- data.tar.gz: 5bd3c7c1d10012b3593f2eb9e474a2c4cd583fb4
2
+ SHA256:
3
+ metadata.gz: e8255be0adcf8bd4fe4412bfed79136715ec13962fa187d08e6e199bba5b3311
4
+ data.tar.gz: 93708387b7486bd4995b0b509f0ba02cb9fa544f963666b5f2d56eb489395735
5
5
  SHA512:
6
- metadata.gz: 1270b6c9d02a08019277233f55f917a3257f05b559c5abaa31d0e10b1a8ea563caed502499a9642ec821d5d6cf33193a1e4cefb49c2c66035028a256660244ac
7
- data.tar.gz: d03c8427a2c07913a447b831a2386150fe637025ce4114bb7dc1b72ec7596c410b0c2ecda3fd41a6082a6c821e7d27fe5edc2d789ba0782fda2fb40c0e928a90
6
+ metadata.gz: 1b1a21c3a139f0accc57cebd68c736112eeae7b9c6c4d63cbad374969f677c8901026ec06acec13d458c34dccb04d541528b395f2f2adb8c2715f5d67187d05f
7
+ data.tar.gz: 61fbd5998c46d0c44551308598da14a92e8a7f1d08a00715ee8ca1e4bfd508c1bd4fad991fe76fa5913e857fab28eed35fa593404524c2b6a15f9f7105892f79
data/.gitignore CHANGED
@@ -1,2 +1,6 @@
1
1
  *.lock
2
- *.gem
2
+ *.gem
3
+ .idea
4
+ .rakeTasks
5
+ .ruby-version
6
+
data/README.md CHANGED
@@ -1,155 +1,163 @@
1
- # SignalFx-Tracing Library for Ruby: An OpenTracing Auto-Instrumentor
1
+ # SignalFx Tracing Library for Ruby
2
2
 
3
- This utility provides users with the ability of automatically configuring OpenTracing community-contributed [instrumentation libraries](https://github.com/opentracing-contrib) for their Ruby application via a single function.
3
+ The SignalFx Tracing Library for Ruby helps you instrument Ruby applications
4
+ with the OpenTracing API to capture and report distributed traces to SignalFx.
4
5
 
5
- ```ruby
6
- require 'signalfx/tracing'
7
-
8
- SignalFx::Tracing::Instrumenter.configure(auto_instrument:true)
9
- ```
6
+ The library consists of an auto-instrumentor that works with OpenTracing
7
+ community-provided instrumentations, and provides a bootstrap utility to help
8
+ install instrumentations. It also configures and uses a
9
+ [Jaeger tracer](https://github.com/salemove/jaeger-client-ruby) to send trace
10
+ data to SignalFx.
10
11
 
11
- ## Installation
12
+ ## Requirements and supported software
12
13
 
13
- ### General installation
14
+ Here are the requirements and supported software for the library.
14
15
 
15
- ```bash
16
- $ gem install signalfx-tracing
17
- ```
18
-
19
- The SignalFx Tracing Library for Ruby requires just enough dependencies to allow custom instrumentation for your application, with target library instrumentations needing to be installed manually.
20
- The basic installation provides an `sfx-rb-trace-bootstrap` executable to assist with this process, which allows you to specify the desired libraries for instrumentation as a comma-separated list:
21
-
22
- ```bash
23
- $ sfx-rb-trace-bootstrap --install-deps rack,rails,activerecord,restclient
24
- $ # use the --list option to see all available instrumentations
25
- $ sfx-rb-trace-bootstrap --list
26
- Available target libraries:
27
- {"activerecord"=>["activerecord-opentracing", "~> 0.2.1"],
28
- < ... >
29
- "sinatra"=>["sinatra-instrumentation", "~> 0.1.2"]}
30
- ```
16
+ ### Supported runtimes
31
17
 
32
- If you'd prefer to install all the available instrumentations without the assistance of the `sfx-rb-trace-bootstrap` utility, please install the provided [gem dependencies](./gem.deps.rb).
18
+ - MRI Ruby (CRuby) 2.0+
33
19
 
34
- ```bash
35
- $ # Run from a cloned and updated https://github.com/signalfx/signalfx-ruby-tracing.git
36
- $ cd signalfx-ruby-tracing
37
- $ bundle install
38
- $ gem install -g
39
- ```
20
+ ### Supported servers
40
21
 
41
- ### Installation in existing application
22
+ - Puma >= 3.0.0
23
+ - Passenger >= 5.0.25
42
24
 
43
- Specify the desired dependency by adding this line to your application's Gemfile:
25
+ ### Supported libraries
26
+
27
+ | Library | Instrumentation name | Versions Supported |
28
+ | ------------------------------- | -------------------------------------- | ------------------ |
29
+ | [ActiveRecord](#active-record) | activerecord-opentracing | ~> 5.0 |
30
+ | [Elasticsearch](#elasticsearch) | signalfx-elasticsearch-instrumentation | >= 6.0.2 |
31
+ | [Faraday](#faraday) | signalfx-faraday-instrumentation | >= 0.9.0 |
32
+ | [Grape](#grape) | grape-instrumentation | >= 0.13.0 |
33
+ | [Mongo](#mongo) | mongodb-instrumentation | >= 2.1.0 |
34
+ | [Mysql2](#mysql2) | mysql2-instrumentation | >= 0.4.0 |
35
+ | [Net::HTTP](#nethttp) | nethttp-instrumentation | Ruby >= 2.0 |
36
+ | [Pg](#pg) | pg-instrumentation | >= 0.18.0 |
37
+ | [Rack](#rack) | rack-tracer | >= 0.1 |
38
+ | [Rails](#rails) | rails-instrumentation | >= 3.0.0 |
39
+ | [Redis](#redis) | redis-instrumentation | >= 4.0.0 |
40
+ | [RestClient](#restclient) | restclient-instrumentation | >= 1.5.0 |
41
+ | [Sequel](#sequel) | sequel-instrumentation | >= 3.47.0 |
42
+ | [Sidekiq](#sidekiq) | sfx-sidekiq-opentracing | >= 0.7.0 |
43
+ | [Sinatra](#sinatra) | sinatra-instrumentation | >= 1.0.0 |
44
+
45
+ Instrumentation for routes using Puma or Passenger is provided through
46
+ Rack. If you use a framework that builds on top of Rack, such as Rails or
47
+ Sinatra, install the `rack-tracer` instrumentation with your dependency manager
48
+ or with the bootstrap utility. In these cases, the routes through the web
49
+ server are automatically traced.
50
+
51
+ ## Install the SignalFx Tracing Library for Ruby
52
+
53
+ Follow these steps to install the tracing library. You can either use the
54
+ bootstrap utility to install the tracing library and its dependencies or
55
+ manually install everything.
56
+
57
+ The bootstrap utility updates your Gemfile and installs the required
58
+ dependencies for you. For information about the bootstrap utility, see the
59
+ [sfx-rb-trace-bootstrap](bin/sfx-rb-trace-bootstrap) file.
60
+
61
+ The steps assume you have RubyGems and Bundler.
62
+
63
+ ### Install the library with the bootstrap utility
64
+
65
+ 1. Install the tracing library:
66
+ ```bash
67
+ $ gem install signalfx-tracing
68
+ ```
69
+ 2. View the list of instrumentations you can install with the bootstrap utility:
70
+ ```bash
71
+ $ sfx-rb-trace-bootstrap --list
72
+ ```
73
+ 3. Use the bootstrap utility to install applicable instrumentations for your
74
+ application. For example, this is how you add Rails and Redis:
75
+ ```bash
76
+ $ sfx-rb-trace-bootstrap --install-deps rails,redis
77
+ ```
78
+ For information about instrumentation names, see supported libraries and their
79
+ current versions in `gem.deps.rb`. If you configure Rails instrumentation, it
80
+ also configures Active Record instrumentation, so you don't need to instrument both.
81
+
82
+ ### Manually install the library
83
+
84
+ 1. Download the [latest release](https://github.com/signalfx/signalfx-ruby-tracing/releases/latest) of the tracing library.
85
+ 2. Add `signalfx-tracing` to your application's Gemfile:
86
+ ```bash
87
+ $ gem 'signalfx-tracing'
88
+ ```
89
+ 3. Add each applicable instrumentation to your application's Gemfile. For
90
+ example, this is how you add Rails and Redis:
91
+ ```bash
92
+ $ gem 'rails-instrumentation'
93
+ $ gem 'redis-instrumentation'
94
+ ```
95
+ For information about instrumentation names, see supported libraries and their
96
+ current versions in `gem.deps.rb`. If you configure Rails instrumentation, it
97
+ also configures Active Record instrumentation, so you don't need to instrument both.
98
+ 4. Install the gems for the tracing library and instrumentations:
99
+ ```bash
100
+ $ bundle install
101
+ ```
102
+
103
+ ## Configure instrumentation for a Ruby application
104
+
105
+ Configure the instrumentation anywhere in the setup portion of your code or
106
+ before importing and using any libraries that need to be traced.
107
+
108
+ For example, with Rails, configure instrumentation in `config/initializer/tracing.rb`.
109
+
110
+ You can configure instrumentation automatically or manually. Manual
111
+ instrumentation is convenient when you want to trace only some libraries.
112
+
113
+ ### Set configuration values
114
+
115
+ If the default configuration values don't apply for your environment, override them before running the process you instrument.
116
+
117
+ | `configure` parameter | Environment variable | Default | Notes |
118
+ | ------------------- | -------------------- | -------------------------------- | ----- |
119
+ | tracer | N/A | `nil` | The OpenTracing global tracer. |
120
+ | ingest_url | SIGNALFX_ENDPOINT_URL | `http://localhost:9080/v1/trace` | The endpoint the tracer sends spans to. Send spans to a Smart Agent, OpenTelemetry Collector, or a SignalFx ingest endpoint. |
121
+ | service_name | SIGNALFX_SERVICE_NAME | `signalfx-ruby-tracing` | The name to identify the service in SignalFx. |
122
+ | access_token | SIGNALFX_ACCESS_TOKEN | `''` | The SignalFx organization access token. |
123
+
124
+ ### Automatically instrument code:
125
+
126
+ Configure the auto-instrumentor to check for modules defined in the code and
127
+ instrument them if available:
44
128
 
45
129
  ```ruby
46
- gem 'signalfx-tracing'
47
- ```
48
-
49
- Then execute the following (or use your desired installation method for your application).
130
+ require 'signalfx/tracing'
50
131
 
51
- ```bash
52
- $ bundle install
132
+ SignalFx::Tracing::Instrumenter.configure(auto_instrument:true)
53
133
  ```
54
134
 
55
- ## Usage
56
-
57
- Configure the instrumentation anywhere in the setup portion of your code or before doing anything
58
- that needs to be traced.
59
-
60
- For Rails, this would go in `config/initializer/tracing.rb`.
135
+ ### Manually specify which libraries to instrument
61
136
 
62
- The instrumentation can be done automatically, where the auto-instrumenter will
63
- check for modules defined in the code and instrument them if available:
137
+ Specify which libraries to instrument:
64
138
 
65
139
  ```ruby
66
140
  require 'signalfx/tracing'
67
141
 
68
- SignalFx::Tracing::Instrumenter.configure(auto_instrument:true)
69
- ```
70
-
71
- Manual configuration may be desirable when only some libraries should be traced.
72
- These instrumentations to can be selected in a block:
73
-
74
- ```ruby
75
- SignalFx::Tracing::Instrumenter.configure do |patcher|
76
- patcher.instrument(:LibName)
142
+ SignalFx::Tracing::Instrumenter.configure do |p|
143
+ p.instrument(<:myLibName>)
77
144
  ...
78
145
  end
79
146
  ```
80
147
 
81
- Valid lib names are listed below with the instrumentation documentation.
82
-
83
- `configure` accepts several optional parameters:
84
- - `tracer`: a preconfigured OpenTracing tracer to use. If one is not provided,
85
- a new tracer will be initialized.
86
- - Default: `nil`
87
- - `ingest_url`: this is the Smart Agent or Smart Gateway endpoint to which spans are sent by the tracer.
88
- - Default: `http://localhost:9080/v1/trace`
89
- - `service_name`: service name to send spans under.
90
- - Default: `signalfx-ruby-tracing`
91
- - `access_token`: SignalFx access token for authentication. Unnecessary for most deployments.
92
- - Default: `''`
93
-
94
- Environment variables can be used to configure `service_name` and `access_token`
95
- if not given to the `configure` method.
96
-
97
- ```bash
98
- export SIGNALFX_SERVICE_NAME="<service_name>"
99
- export SIGNALFX_ENDPOINT_URL="<url>"
100
- export SIGNALFX_ACCESS_TOKEN="<token>"
101
- ```
102
-
103
- If these environment variables are not set, the values will default to the ones
104
- listed above.
105
-
106
- # Instrumentation
107
-
108
- This section contains details and configuration for specific frameworks.
109
-
110
- ### Runtimes
111
-
112
- - MRI Ruby (CRuby) 2.0+
148
+ ## Usage information for each library
113
149
 
114
- ### Web servers
150
+ Here's information about instrumenting each supported library.
115
151
 
116
- - Puma >= 3.0.0
117
- - Passenger >= 5.0.25
118
-
119
- Instrumentation for routes using these web servers is provided through Rack.
120
- If using a framework that builds on top of Rack, such as Rails or Sinatra, our
121
- instrumentation includes Rack instrumentation. In these cases, the routes
122
- through the web server will be automatically traced.
123
-
124
- When interfacing with these web servers as a Rack application, please configure
125
- [Rack instrumentation](#rack) and insert it as middleware.
126
-
127
- ### Libraries/Frameworks
128
-
129
- | Library | Versions Supported |
130
- | ----------------------------------- | ------------------ |
131
- | [ActiveRecord](#active-record) | ~> 5.0 |
132
- | [Elasticsearch](#elasticsearch) | >= 6.0.2 |
133
- | [Faraday](#faraday) | >= 0.9.0 |
134
- | [Grape](#grape) | >= 0.13.0 |
135
- | [Mongo](#mongo) | >= 2.1.0 |
136
- | [Mysql2](#mysql2) | >= 0.4.0 |
137
- | [Net::HTTP](#nethttp) | Ruby >= 2.0 |
138
- | [Rack](#rack) | >= 0.1 |
139
- | [Rails](#rails) | >= 3.0.0 |
140
- | [Redis](#redis) | >= 4.0.0 |
141
- | [RestClient](#restclient) | >= 1.5.0 |
142
- | [Sequel](#sequel) | >= 3.47.0 |
143
- | [Sinatra](#sinatra) | >= 1.0.0 |
144
-
145
- ## Active Record
152
+ ### Active Record
146
153
 
147
154
  This instrumentation creates spans for each Active Record query using the Active
148
- Support notifications framework.
155
+ Support notifications framework. If you configure Rails instrumentation, it also configures Active Record instrumentation, so you don't need to instrument both.
149
156
 
150
- The source for this instrumentation is located [here](https://github.com/salemove/ruby-activerecord-opentracing).
157
+ The source for this instrumentation is located
158
+ [here](https://github.com/salemove/ruby-activerecord-opentracing).
151
159
 
152
- ### Usage
160
+ #### Usage
153
161
 
154
162
  ```bash
155
163
  $ # install the instrumentation if not done previously
@@ -162,14 +170,15 @@ SignalFx::Tracing::Instrumenter.configure do |p|
162
170
  end
163
171
  ```
164
172
 
165
- ## Elasticsearch
173
+ ### Elasticsearch
166
174
 
167
175
  Elasticsearch queries through the Ruby client are traced using a wrapper around
168
176
  the transport.
169
177
 
170
- The forked source for the instrumentation is located [here](https://github.com/signalfx/ruby-elasticsearch-tracer).
178
+ The forked source for the instrumentation is located
179
+ [here](https://github.com/signalfx/ruby-elasticsearch-tracer).
171
180
 
172
- ### Usage
181
+ #### Usage
173
182
 
174
183
  ```bash
175
184
  $ # install the instrumentation if not done previously
@@ -199,15 +208,16 @@ client.transport = Elasticsearch::Tracer::Transport.new(tracer: OpenTracing.glob
199
208
  transport: client.transport)
200
209
  ```
201
210
 
202
- ## Faraday
211
+ ### Faraday
203
212
 
204
213
  Faraday HTTP client instrumentation automatically creates spans for outgoing
205
214
  requests. If the remote service has instrumentation that is aware of Rack,
206
215
  those spans will be automatically nested with Faraday's spans.
207
216
 
208
- The source for this instrumentation is located [here](https://github.com/opentracing-contrib/ruby-faraday-tracer).
217
+ The source for this instrumentation is located
218
+ [here](https://github.com/opentracing-contrib/ruby-faraday-tracer).
209
219
 
210
- ### Usage
220
+ #### Usage
211
221
 
212
222
  ```bash
213
223
  $ # install the instrumentation if not done previously
@@ -230,15 +240,16 @@ end
230
240
 
231
241
  For more detailed usage, please check the instrumentation's page.
232
242
 
233
- ## Grape
243
+ ### Grape
234
244
 
235
245
  This instrumentation subscribes to ActiveSupport notifications emitted by the
236
246
  Grape API. It patches `Grape::API` to automatically insert the `Rack::Tracer`
237
247
  middleware and trace requests.
238
248
 
239
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-grape-instrumentation)
249
+ The source for this instrumentation is located
250
+ [here](https://github.com/signalfx/ruby-grape-instrumentation)
240
251
 
241
- ### Usage
252
+ #### Usage
242
253
 
243
254
  ```bash
244
255
  $ # install the instrumentation if not done previously
@@ -253,8 +264,10 @@ end
253
264
 
254
265
  `instrument` takes these optional arguments:
255
266
  - `tracer`: custom tracer to use. Defaults to `OpenTracing.global_tracer`
256
- - `parent_span`: parent span to group spans or block that returns a span. Default: `nil`
257
- - `disable_patching`: disable patching if managing the middleware stack manually. Default: `false`
267
+ - `parent_span`: parent span to group spans or block that returns a span.
268
+ Default: `nil`
269
+ - `disable_patching`: disable patching if managing the middleware stack
270
+ manually. Default: `false`
258
271
 
259
272
  If patching is disabled, but spans nested by request are still desired, then the
260
273
  Rack middleware must be manually added to the API class.
@@ -275,13 +288,15 @@ end
275
288
 
276
289
  Please see the instrumentation's page for more details.
277
290
 
278
- ## Mongo
291
+ ### Mongo
279
292
 
280
- Mongo driver instrumentation traces queries performed through the Ruby Mongodb driver.
293
+ Mongo driver instrumentation traces queries performed through the Ruby Mongodb
294
+ driver.
281
295
 
282
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-mongodb-instrumentation)
296
+ The source for this instrumentation is located
297
+ [here](https://github.com/signalfx/ruby-mongodb-instrumentation)
283
298
 
284
- ### Usage
299
+ #### Usage
285
300
 
286
301
  ```bash
287
302
  $ # install the instrumentation if not done previously
@@ -294,13 +309,14 @@ SignalFx::Tracing::Instrumenter.configure do |p|
294
309
  end
295
310
  ```
296
311
 
297
- ## Mysql2
312
+ ### Mysql2
298
313
 
299
314
  Mysql2 instrumentation traces all queries performed with the Mysql2 client.
300
315
 
301
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-mysql2-instrumentation)
316
+ The source for this instrumentation is located
317
+ [here](https://github.com/signalfx/ruby-mysql2-instrumentation)
302
318
 
303
- ### Usage
319
+ #### Usage
304
320
 
305
321
  ```bash
306
322
  $ # install the instrumentation if not done previously
@@ -313,13 +329,14 @@ SignalFx::Tracing::Instrumenter.configure do |p|
313
329
  end
314
330
  ```
315
331
 
316
- ## Net::HTTP
332
+ ### Net::HTTP
317
333
 
318
334
  This automatically traces all requests using Net::HTTP.
319
335
 
320
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-net-http-instrumentation).
336
+ The source for this instrumentation is located
337
+ [here](https://github.com/signalfx/ruby-net-http-instrumentation).
321
338
 
322
- ### Usage
339
+ #### Usage
323
340
 
324
341
  ```ruby
325
342
  SignalFx::Tracing::Instrumenter.configure do |p|
@@ -327,17 +344,38 @@ SignalFx::Tracing::Instrumenter.configure do |p|
327
344
  end
328
345
  ```
329
346
 
330
- An optional `tracer` named argument can be provided to use a custom tracer. It will default to `OpenTracing.global_tracer` if not provided.
347
+ An optional `tracer` named argument can be provided to use a custom tracer.
348
+ It will default to `OpenTracing.global_tracer` if not provided.
349
+
350
+ ### Pg
331
351
 
332
- ## Rack
352
+ Pg instrumentation traces all queries performed with the pg client.
353
+
354
+ The source for this instrumentation is located
355
+ [here](https://github.com/signalfx/ruby-pg-instrumentation)
356
+
357
+ #### Usage
358
+
359
+ ```bash
360
+ $ # install the instrumentation if not done previously
361
+ $ sfx-rb-trace-bootstrap -i pg
362
+ ```
363
+
364
+ ```ruby
365
+ SignalFx::Tracing::Instrumenter.configure do |p|
366
+ p.instrument(:pg)
367
+ end
368
+ ```
369
+ ### Rack
333
370
 
334
371
  Rack spans are created using the `rack-tracer` gem. This is enabled
335
372
  automatically for other frameworks that are built on top of Rack, but it can
336
373
  also be separately enabled.
337
374
 
338
- The source for this instrumentation is located [here](https://github.com/opentracing-contrib/ruby-rack-tracer).
375
+ The source for this instrumentation is located
376
+ [here](https://github.com/opentracing-contrib/ruby-rack-tracer).
339
377
 
340
- ### Usage
378
+ #### Usage
341
379
 
342
380
  ```bash
343
381
  $ # install the instrumentation if not done previously
@@ -352,14 +390,15 @@ end
352
390
  use Rack::Tracer
353
391
  ```
354
392
 
355
- ## Rails
393
+ ### Rails
356
394
 
357
395
  Rails applications can be traced using the notifications provided by ActiveSupport.
358
396
  It will use `rack-tracer` to trace by requests.
359
397
 
360
- The forked source for this instrumentation is located [here](https://github.com/signalfx/ruby-rails-instrumentation).
398
+ The forked source for this instrumentation is located
399
+ [here](https://github.com/signalfx/ruby-rails-instrumentation).
361
400
 
362
- ### Usage
401
+ #### Usage
363
402
 
364
403
  ```bash
365
404
  $ # install the instrumentation if not done previously
@@ -388,13 +427,15 @@ Note that if `rack_tracer` is set to `false`, requests propagated to the Rails
388
427
  app will not be extracted. For example, if a traced service makes a request to
389
428
  an endpoint served by the Rails app, it will not be automatically nested.
390
429
 
391
- ## Redis
430
+ ### Redis
392
431
 
393
- This instrumentation traces commands performed using the [Redis client](https://github.com/redis/redis-rb).
432
+ This instrumentation traces commands performed using the
433
+ [Redis client](https://github.com/redis/redis-rb).
394
434
 
395
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-redis-instrumentation).
435
+ The source for this instrumentation is located
436
+ [here](https://github.com/signalfx/ruby-redis-instrumentation).
396
437
 
397
- ### Usage
438
+ #### Usage
398
439
 
399
440
  ```bash
400
441
  $ # install the instrumentation if not done previously
@@ -411,14 +452,15 @@ Arguments:
411
452
  - `tracer`: Optional custom tracer to use for this instrumentation
412
453
  - Default: `OpenTracing.global_tracer`
413
454
 
414
- ## RestClient
455
+ ### RestClient
415
456
 
416
457
  RestClient requests can be patched to automatically be wrapped in a span. It
417
458
  will also inject the span context so remote services can extract it.
418
459
 
419
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-restclient-instrumentation).
460
+ The source for this instrumentation is located
461
+ [here](https://github.com/signalfx/ruby-restclient-instrumentation).
420
462
 
421
- ### Usage
463
+ #### Usage
422
464
 
423
465
  ```bash
424
466
  $ # install the instrumentation if not done previously
@@ -437,13 +479,15 @@ Arguments:
437
479
  - `propagate`: Propagate spans to the request endpoint.
438
480
  - Default: `false`
439
481
 
440
- ## Sequel
482
+ ### Sequel
441
483
 
442
- Sequel instrumentation adds extensions to the Database and Dataset to trace queries.
484
+ Sequel instrumentation adds extensions to the Database and Dataset to trace
485
+ queries.
443
486
 
444
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-sequel-instrumentation).
487
+ The source for this instrumentation is located
488
+ [here](https://github.com/signalfx/ruby-sequel-instrumentation).
445
489
 
446
- ### Usage
490
+ #### Usage
447
491
 
448
492
  ```bash
449
493
  $ # install the instrumentation if not done previously
@@ -460,16 +504,50 @@ Arguments:
460
504
  - `tracer`: Optional custom tracer for this instrumentation
461
505
  - Default: `OpenTracing.global_tracer`
462
506
 
463
- ## Sinatra
507
+ ### Sidekiq
508
+
509
+ Sidekiq instrumentation traces worker job submissions and execution via
510
+ [Sidekiq middleware](https://github.com/mperham/sidekiq/wiki/Middleware).
511
+ The instrumenter registers both client and server middleware that use job
512
+ metadata to represent all job submissions and their invocations. Trace
513
+ context propagation adds to this job metadata to unifiy distributed client
514
+ and server requests and processing.
515
+
516
+ The source for this instrumentation is located
517
+ [here](https://github.com/signalfx/ruby-sidekiq-tracer).
518
+
519
+ #### Usage
520
+
521
+ ```bash
522
+ $ # install the instrumentation if not done previously
523
+ $ sfx-rb-trace-bootstrap -i sidekiq
524
+ ```
525
+
526
+ ```ruby
527
+ SignalFx::Tracing::Instrumenter.configure do |p|
528
+ p.instrument(:Sidekiq, propagate: false)
529
+ end
530
+ ```
531
+
532
+ Arguments:
533
+ - `tracer`: Optional custom tracer for this instrumentation
534
+ - Default: `OpenTracing.global_tracer`
535
+ - `propagate`: Optional boolean to enable/disable trace context injection via
536
+ job metadata
537
+ - Default: `true`
538
+
539
+
540
+ ### Sinatra
464
541
 
465
542
  Sinatra instrumentation traces requests and template rendering. The instrumenter
466
543
  registers a Sinatra extension that uses `rack-tracer` to trace requests and
467
544
  monkey-patches to trace view rendering. Rack instrumentation is automatically
468
545
  enabled when using Sinatra instrumentation.
469
546
 
470
- The source for this instrumentation is located [here](https://github.com/signalfx/ruby-sinatra-instrumentation).
547
+ The source for this instrumentation is located
548
+ [here](https://github.com/signalfx/ruby-sinatra-instrumentation).
471
549
 
472
- ### Usage
550
+ #### Usage
473
551
 
474
552
  ```bash
475
553
  $ # install the instrumentation if not done previously
@@ -482,3 +560,25 @@ SignalFx::Tracing::Instrumenter.configure do |p|
482
560
  end
483
561
  ```
484
562
 
563
+ ## Configure the logger
564
+
565
+ The logger, based on the [Ruby Logger](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html),
566
+ can be configured by setting the following environment variables:
567
+
568
+ | Environmental Variable Name | Description | Default |
569
+ |:------------------------------|:----------------------|:-------------------- |
570
+ | `SIGNALFX_LOG_PATH` | The path to the desired file where the instrumentation logs will be written. Besides customized paths, output options also include `STDOUT` and `STDERR`.| `/var/log/signalfx/signalfx-ruby-tracing.log` |
571
+ | `SIGNALFX_LOG_SHIFT_AGE` | The desired number of old log files to keep, or frequency of rotation. Options include: `daily`, `weekly` or `monthly`) | `0` |
572
+ | `SIGNALFX_LOG_SHIFT_SIZE` | The desired maximum size of log files (this only applies when. A new one would be created when the maximum is reached. | `1048576` (1 MB) |
573
+ | `SIGNALFX_LOG_LEVEL` | The severity criteria for recording logs (from least to most severe). Options: `debug`, `info`, `warn`, `error`, `fatal`, `unknown` | `warn` |
574
+
575
+ More information regarding the logging configuration may be found
576
+ [here](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html).
577
+
578
+ **NB**:
579
+ - If the default path for `SIGNALFX_LOG_PATH` (that is, `/var/log/signalfx/signalfx-ruby-tracing.log`)
580
+ is to be used, then please create the directory and or file (if necessary)
581
+ and grant the relevant access permissions to the instrumentation user process.
582
+ If there are permission issues, the instrumentation will default to logging to
583
+ the standard error (STDERR) handle, until the path is provided to which logs
584
+ can be written without any access issues.
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby -rubygems
1
+ #!/usr/bin/env ruby -rrubygems
2
2
  require 'optparse'
3
3
  require 'ostruct'
4
4
  require 'pp'
@@ -11,11 +11,13 @@ instrumentations = {
11
11
  "mongodb" => ["mongodb-instrumentation", "~> 0.1.1"],
12
12
  "mysql2" => ["mysql2-instrumentation", "~> 0.2.1"],
13
13
  "nethttp" => ["nethttp-instrumentation", "~> 0.1.2"],
14
+ "pg" => ["pg-instrumentation", "~> 0.1.0"],
14
15
  "rack" => ["rack-tracer", { git: 'git://github.com/signalfx/ruby-rack-tracer.git', branch: 'sfx_release' }],
15
16
  "rails" => ["rails-instrumentation", "~> 0.1.3"],
16
- "redis" => ["redis-instrumentation", "~> 0.1.1"],
17
+ "redis" => ["redis-instrumentation", "~> 0.2.0"],
17
18
  "restclient" => ["restclient-instrumentation", "~> 0.1.1"],
18
19
  "sequel" => ["sequel-instrumentation", "~> 0.1.0"],
20
+ "sidekiq" => ["sfx-sidekiq-opentracing", "~> 0.0.3"],
19
21
  "sinatra" => ["sinatra-instrumentation", "~> 0.1.2"]
20
22
  }
21
23
 
@@ -65,4 +67,4 @@ def install_from_git(target, options)
65
67
  end
66
68
 
67
69
  parser.parse(ARGV)
68
- install_instrumentors(instrumentations, options.target_libraries)
70
+ install_instrumentors(instrumentations, options.target_libraries)
@@ -4,11 +4,13 @@ group :instrumentations do
4
4
  gem 'mongodb-instrumentation', '~> 0.1.1'
5
5
  gem 'mysql2-instrumentation', '~> 0.2.1'
6
6
  gem 'nethttp-instrumentation', '~> 0.1.2'
7
+ gem 'pg-instrumentation', '~> 0.1.0'
7
8
  gem 'rack-tracer', git: 'git://github.com/signalfx/ruby-rack-tracer.git', branch: 'sfx_release'
8
9
  gem 'rails-instrumentation', '0.1.3'
9
- gem 'redis-instrumentation', '~> 0.1.1'
10
+ gem 'redis-instrumentation', '~> 0.2.0'
10
11
  gem 'restclient-instrumentation', '~> 0.1.1'
11
12
  gem 'sequel-instrumentation', '~> 0.1.0'
13
+ gem 'sfx-sidekiq-opentracing', '~> 0.0.3'
12
14
  gem 'signalfx-elasticsearch-instrumentation', '~> 0.1.0'
13
15
  gem 'signalfx-faraday-instrumentation', '~> 0.1.1'
14
16
  gem 'sinatra-instrumentation', '~> 0.1.2'
@@ -2,6 +2,7 @@ require 'jaeger/client'
2
2
  require 'signalfx/tracing/http_sender'
3
3
  require 'signalfx/tracing/register'
4
4
  require 'signalfx/tracing/compat'
5
+ require 'signalfx/tracing/sfx_logger'
5
6
  require 'thread'
6
7
 
7
8
  module SignalFx
@@ -21,11 +22,16 @@ module SignalFx
21
22
  @ingest_url = ingest_url
22
23
  @service_name = service_name
23
24
  @access_token = access_token
24
- set_tracer(tracer: tracer, service_name: service_name, access_token: access_token)
25
+ set_tracer(tracer: tracer, service_name: service_name, access_token: access_token) if @tracer.nil?
25
26
 
26
27
  if auto_instrument
27
28
  Register.available_libs.each_pair do |key, value|
28
- value.instrument
29
+ begin
30
+ value.instrument
31
+ rescue Exception => e
32
+ logger.error { "failed to initialize instrumentation '#{key}': #{e.inspect}" }
33
+ logger.error { e.backtrace }
34
+ end
29
35
  end
30
36
  else
31
37
  yield self
@@ -36,9 +42,14 @@ module SignalFx
36
42
 
37
43
  def instrument(to_patch, **args)
38
44
  if Register.available_libs[to_patch].nil?
39
- puts "instrumentation not found"
45
+ logger.error { "instrumentation not found: #{to_patch}" }
40
46
  else
41
- Register.available_libs[to_patch].instrument(**args)
47
+ begin
48
+ Register.available_libs[to_patch].instrument(**args)
49
+ rescue Exception => e
50
+ logger.error { "failed to initialize instrumentation '#{to_patch}': #{e.inspect}" }
51
+ logger.error { e.backtrace }
52
+ end
42
53
  end
43
54
  end
44
55
 
@@ -55,10 +66,12 @@ module SignalFx
55
66
  @reporter = Jaeger::Client::Reporters::RemoteReporter.new(sender: @http_sender, flush_interval: 1)
56
67
 
57
68
  injectors = {
58
- OpenTracing::FORMAT_RACK => [Jaeger::Client::Injectors::B3RackCodec]
69
+ OpenTracing::FORMAT_RACK => [Jaeger::Client::Injectors::B3RackCodec],
70
+ OpenTracing::FORMAT_TEXT_MAP => [Jaeger::Client::Injectors::B3RackCodec]
59
71
  }
60
72
  extractors = {
61
- OpenTracing::FORMAT_RACK => [Jaeger::Client::Extractors::B3RackCodec]
73
+ OpenTracing::FORMAT_RACK => [Jaeger::Client::Extractors::B3RackCodec],
74
+ OpenTracing::FORMAT_TEXT_MAP => [Jaeger::Client::Extractors::B3TextMapCodec]
62
75
  }
63
76
 
64
77
  @tracer = Jaeger::Client.build(
@@ -76,6 +89,13 @@ module SignalFx
76
89
  def revive
77
90
  set_tracer(service_name: @service_name, access_token: @access_token)
78
91
  end
92
+
93
+ def logger()
94
+ if @_logger == nil
95
+ @_logger = Logging.logger
96
+ end
97
+ return @_logger
98
+ end
79
99
  end
80
100
  end
81
101
 
@@ -0,0 +1,41 @@
1
+ require_relative '../sfx_logger'
2
+
3
+ module SignalFx
4
+ module Tracing
5
+ module Instrumenter
6
+ module PG
7
+
8
+ @logger = Logging.logger
9
+ @logger.debug('SFx pg-instrumentation') { "Initializing instrumentation ..." }
10
+
11
+ Register.add_lib :PG, self
12
+
13
+ class << self
14
+
15
+ def instrument(opts = {})
16
+ return if @instrumented
17
+
18
+ # check for required gems
19
+ begin
20
+ require 'pg'
21
+ rescue LoadError
22
+ return
23
+ end
24
+
25
+ begin
26
+ require 'pg/instrumentation'
27
+ rescue LoadError => e
28
+ @logger.error { e.message }
29
+ return
30
+ end
31
+
32
+ tracer = opts.fetch(:tracer, OpenTracing.global_tracer)
33
+
34
+ ::PG::Instrumentation.instrument(tracer: tracer) if !@instrumented
35
+ @instrumented = true
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -21,7 +21,7 @@ module SignalFx
21
21
  end
22
22
 
23
23
  tracer = opts.fetch(:tracer, OpenTracing.global_tracer)
24
- ::Redis::Instrumentation.instrument(tracer: tracer)
24
+ ::Redis::Instrumentation.instrument(tracer: tracer, db_statement_length: 1024)
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,35 @@
1
+ module SignalFx
2
+ module Tracing
3
+ module Instrumenter
4
+ module Sidekiq
5
+
6
+ Register.add_lib :Sidekiq, self
7
+
8
+ class << self
9
+ def instrument(opts = {})
10
+ return if @instrumented
11
+ begin
12
+ require 'sidekiq'
13
+ rescue LoadError
14
+ return
15
+ end
16
+
17
+ begin
18
+ require 'sidekiq/tracer'
19
+ rescue LoadError => e
20
+ puts e.message
21
+ return
22
+ end
23
+
24
+ ::Sidekiq::Tracer.instrument(
25
+ tracer: opts.fetch(:tracer, OpenTracing.global_tracer),
26
+ opts: { propagate_context: opts.fetch(:propagate, true) }
27
+ )
28
+ @instrumented = true
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -42,3 +42,5 @@ require 'signalfx/tracing/instrumentation/mysql2'
42
42
  require 'signalfx/tracing/instrumentation/redis'
43
43
  require 'signalfx/tracing/instrumentation/sequel'
44
44
  require 'signalfx/tracing/instrumentation/grape'
45
+ require 'signalfx/tracing/instrumentation/sidekiq'
46
+ require 'signalfx/tracing/instrumentation/pg'
@@ -0,0 +1,57 @@
1
+ require 'logger'
2
+
3
+ module SignalFx
4
+ module Tracing
5
+ module Logging
6
+
7
+ LOG_LEVELS = {
8
+ 'unknown' => Logger::UNKNOWN,
9
+ 'fatal' => Logger::FATAL,
10
+ 'error' => Logger::ERROR,
11
+ 'warn' => Logger::WARN,
12
+ 'info' => Logger::INFO,
13
+ 'debug' => Logger::DEBUG
14
+ }.freeze
15
+
16
+ DEFAULT_LOG_PATH = '/var/log/signalfx/signalfx-ruby-tracing.log'
17
+ DEFAULT_SHIFT_AGE = 5
18
+ DEFAULT_SHIFT_SIZE = 1048576
19
+
20
+ def self.create (log_path = ENV['SIGNALFX_LOG_PATH'] || DEFAULT_LOG_PATH,
21
+ sfx_shift_age = ENV['SIGNALFX_LOG_SHIFT_AGE'] || DEFAULT_SHIFT_AGE,
22
+ sfx_shift_size = ENV['SIGNALFX_LOG_SHIFT_SIZE'] || DEFAULT_SHIFT_SIZE)
23
+
24
+ if log_path.upcase == 'STDOUT'
25
+ @logger = Logger.new(STDOUT)
26
+ elsif log_path.upcase == 'STDERR'
27
+ self.create_stderr_logger()
28
+ else
29
+ begin
30
+ @logger = Logger.new("#{log_path}", shift_age = sfx_shift_age, shift_size = sfx_shift_size)
31
+ rescue Errno::EACCES, Errno::ENOENT => e
32
+ self.create_stderr_logger(log_path, e)
33
+ end
34
+ end
35
+
36
+ log_level = ENV['SIGNALFX_LOG_LEVEL'].downcase if ENV['SIGNALFX_LOG_LEVEL']
37
+ @logger.level = LOG_LEVELS.fetch(log_level, Logger::WARN)
38
+ @logger.datetime_format = '%Y-%m-%d %H:%M:%S'
39
+ @logger.formatter = proc do | severity, datetime, progname, msg |
40
+ "#{datetime}, #{severity}: #{msg} --- #{progname} \n"
41
+ end
42
+ @logger
43
+ end
44
+
45
+ def self.logger
46
+ @logger ||= self.create
47
+ end
48
+
49
+ def self.create_stderr_logger(logpath=nil, error=nil)
50
+ @logger = Logger.new(STDERR)
51
+ if error
52
+ @logger.error { "LOG FILE ACCESS ERROR:\n*** Failed to write to '#{logpath}': #{error.message}\n--> Please manually create the required resources and/or grant relevant access permissions to this user process.\n*** Defaulting to sending log statements to the standard error (STDERR) handle.\n"}
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  module Signalfx
2
2
  module Tracing
3
- VERSION = "1.1.0"
3
+ VERSION = "1.3.3"
4
4
  end
5
5
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  # TODO pin versions once consistent across all dependencies
27
27
  spec.add_dependency "opentracing", "> 0.3.0"
28
- spec.add_dependency "jaeger-client", "~> 0.10.0"
28
+ spec.add_dependency "jaeger-client", "~> 1.0.0"
29
29
 
30
30
  # We are no longer setting all available instrumentations as dependencies.
31
31
  # Manual installation via bootstrapper or gem.deps.rb is now required.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signalfx-tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SignalFx, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-24 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.0
61
+ version: 1.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.0
68
+ version: 1.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: nethttp-instrumentation
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.1.2
83
- description:
83
+ description:
84
84
  email:
85
85
  - info@signalfx.com
86
86
  executables:
@@ -107,14 +107,17 @@ files:
107
107
  - lib/signalfx/tracing/instrumentation/mysql2.rb
108
108
  - lib/signalfx/tracing/instrumentation/net_http.rb
109
109
  - lib/signalfx/tracing/instrumentation/patching-test.rb
110
+ - lib/signalfx/tracing/instrumentation/pg.rb
110
111
  - lib/signalfx/tracing/instrumentation/rack.rb
111
112
  - lib/signalfx/tracing/instrumentation/rails.rb
112
113
  - lib/signalfx/tracing/instrumentation/redis.rb
113
114
  - lib/signalfx/tracing/instrumentation/restclient.rb
114
115
  - lib/signalfx/tracing/instrumentation/sequel.rb
116
+ - lib/signalfx/tracing/instrumentation/sidekiq.rb
115
117
  - lib/signalfx/tracing/instrumentation/sinatra.rb
116
118
  - lib/signalfx/tracing/register.rb
117
119
  - lib/signalfx/tracing/reporter/auto_reviving_async_reporter.rb
120
+ - lib/signalfx/tracing/sfx_logger.rb
118
121
  - lib/signalfx/tracing/tracer.rb
119
122
  - lib/signalfx/tracing/version.rb
120
123
  - signalfx-tracing.gemspec
@@ -122,7 +125,7 @@ homepage: https://github.com/signalfx/signalfx-ruby-tracing
122
125
  licenses:
123
126
  - Apache-2.0
124
127
  metadata: {}
125
- post_install_message:
128
+ post_install_message:
126
129
  rdoc_options: []
127
130
  require_paths:
128
131
  - lib
@@ -137,9 +140,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
140
  - !ruby/object:Gem::Version
138
141
  version: '0'
139
142
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.2.0
142
- signing_key:
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.6.2
145
+ signing_key:
143
146
  specification_version: 4
144
147
  summary: Auto-instrumentation framework for Ruby
145
148
  test_files: []