traceview 3.0.5 → 3.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +10 -0
- data/gemfiles/libraries.gemfile +7 -6
- data/lib/oboe_metal.rb +3 -0
- data/lib/rails/generators/traceview/templates/traceview_initializer.rb +18 -0
- data/lib/traceview/base.rb +32 -0
- data/lib/traceview/config.rb +19 -2
- data/lib/traceview/inst/curb.rb +281 -0
- data/lib/traceview/instrumentation.rb +1 -0
- data/lib/traceview/util.rb +1 -0
- data/lib/traceview/version.rb +2 -2
- data/test/instrumentation/curb_test.rb +542 -0
- data/test/support/config_test.rb +3 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23616dd3b74eff90644377a443782578be720cc
|
4
|
+
data.tar.gz: de6efded21b36d8e26bb1672733d63bfd787ee04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46089ca6acc965c2d37bce5e3ef70e6118b0ede1535cc141b28bd611e264656f7f8c22a4a073160b539da216d0352a2e9a0deb9400c77ab50e7a59df69c4d3a1
|
7
|
+
data.tar.gz: 8f4b317abde4c3c262ba3adfeeeea3e2c9829d6d22e9ee757d6c7f59bbb99a3a71b4bb1ca7707d6a606d209aee8ea40861346d9a1e64cf69863fef9da373f576
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,29 @@ https://github.com/appneta/oboe-ruby/releases
|
|
4
4
|
|
5
5
|
Dates in this file are in the format MM/DD/YYYY.
|
6
6
|
|
7
|
+
# traceview 3.1.0
|
8
|
+
|
9
|
+
This minor release adds the following:
|
10
|
+
|
11
|
+
* New Curb HTTP client instrumentation: #132
|
12
|
+
|
13
|
+
Pushed to Rubygems:
|
14
|
+
|
15
|
+
https://rubygems.org/gems/traceview/versions/3.1.0
|
16
|
+
https://rubygems.org/gems/traceview/versions/3.1.0-java
|
17
|
+
|
18
|
+
# traceview 3.0.5
|
19
|
+
|
20
|
+
This patch release includes the following fixes:
|
21
|
+
|
22
|
+
* Fix "undefined method" in httpclient instrumentation: #134
|
23
|
+
* Fix Redis set operation to work with array versus hash: #133
|
24
|
+
|
25
|
+
Pushed to Rubygems:
|
26
|
+
|
27
|
+
https://rubygems.org/gems/traceview/versions/3.0.5
|
28
|
+
https://rubygems.org/gems/traceview/versions/3.0.5-java
|
29
|
+
|
7
30
|
# traceview 3.0.4
|
8
31
|
|
9
32
|
This patch release includes the following fixes:
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ On Heroku? Use the `oboe-heroku` gem instead. It wraps some additional functio
|
|
32
32
|
|
33
33
|
## Rails
|
34
34
|
|
35
|
+

|
36
|
+
|
35
37
|
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.
|
36
38
|
|
37
39
|
*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.*
|
@@ -50,6 +52,8 @@ After the prompts, this will create an initializer: `config/initializers/tracevi
|
|
50
52
|
|
51
53
|
## Sinatra
|
52
54
|
|
55
|
+

|
56
|
+
|
53
57
|
You can instrument your Sinatra application by adding the following code to your `config.ru` Rackup file:
|
54
58
|
|
55
59
|
```ruby
|
@@ -75,6 +79,8 @@ With this, the traceview gem will automatically detect Sinatra on boot and instr
|
|
75
79
|
|
76
80
|
## Padrino
|
77
81
|
|
82
|
+

|
83
|
+
|
78
84
|
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.
|
79
85
|
|
80
86
|
If you need to set `TraceView::Config` values on stack boot, you can do so by adding the following
|
@@ -94,6 +100,8 @@ Note: If you're on Heroku, you don't need to set `tracing_mode` - it will be aut
|
|
94
100
|
|
95
101
|
## Grape
|
96
102
|
|
103
|
+

|
104
|
+
|
97
105
|
You can instrument your Grape application by adding the following code to your `config.ru` Rackup file:
|
98
106
|
|
99
107
|
```ruby
|
@@ -351,6 +359,8 @@ You can read more about Ruby gems with C extensions in the [Rubygems Guides](htt
|
|
351
359
|
|
352
360
|
## Running the Tests
|
353
361
|
|
362
|
+

|
363
|
+
|
354
364
|
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.
|
355
365
|
|
356
366
|
After a bundle install, the tests can be run as:
|
data/gemfiles/libraries.gemfile
CHANGED
@@ -43,17 +43,18 @@ else
|
|
43
43
|
gem 'sinatra'
|
44
44
|
end
|
45
45
|
|
46
|
+
gem 'cassandra'
|
47
|
+
gem 'curb'
|
46
48
|
gem 'dalli'
|
49
|
+
gem 'excon'
|
50
|
+
gem 'faraday'
|
51
|
+
gem 'httpclient'
|
47
52
|
gem 'memcache-client'
|
48
|
-
gem 'cassandra'
|
49
53
|
gem 'mongo'
|
50
|
-
gem 'resque'
|
51
54
|
gem 'redis'
|
52
|
-
gem '
|
53
|
-
gem 'httpclient'
|
54
|
-
gem 'excon'
|
55
|
-
gem 'typhoeus'
|
55
|
+
gem 'resque'
|
56
56
|
gem 'sequel'
|
57
|
+
gem 'typhoeus'
|
57
58
|
|
58
59
|
# Database adapter gems needed by sequel
|
59
60
|
if defined?(JRUBY_VERSION)
|
data/lib/oboe_metal.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Copyright (c) 2013 AppNeta, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
|
4
|
+
require 'thread'
|
5
|
+
|
4
6
|
# Disable docs and Camelcase warns since we're implementing
|
5
7
|
# an interface here. See OboeBase for details.
|
6
8
|
# rubocop:disable Style/Documentation, Style/MethodName
|
@@ -149,3 +151,4 @@ end
|
|
149
151
|
# rubocop:enable Style/Documentation
|
150
152
|
|
151
153
|
TraceView.loaded = true
|
154
|
+
TraceView.config_lock = Mutex.new
|
@@ -97,6 +97,7 @@ if defined?(TraceView::Config)
|
|
97
97
|
# TraceView::Config[:active_record][:enabled] = true
|
98
98
|
# TraceView::Config[:action_view][:enabled] = true
|
99
99
|
# TraceView::Config[:cassandra][:enabled] = true
|
100
|
+
# TraceView::Config[:curb][:enabled] = true
|
100
101
|
# TraceView::Config[:dalli][:enabled] = true
|
101
102
|
# TraceView::Config[:excon][:enabled] = true
|
102
103
|
# TraceView::Config[:em_http_request][:enabled] = true
|
@@ -126,6 +127,7 @@ if defined?(TraceView::Config)
|
|
126
127
|
# TraceView::Config[:active_record][:collect_backtraces] = true
|
127
128
|
# TraceView::Config[:action_view][:collect_backtraces] = true
|
128
129
|
# TraceView::Config[:cassandra][:collect_backtraces] = true
|
130
|
+
# TraceView::Config[:curb][:collect_backtraces] = true
|
129
131
|
# TraceView::Config[:dalli][:collect_backtraces] = false
|
130
132
|
# TraceView::Config[:excon][:collect_backtraces] = false
|
131
133
|
# TraceView::Config[:em_http_request][:collect_backtraces] = true
|
@@ -143,6 +145,22 @@ if defined?(TraceView::Config)
|
|
143
145
|
# TraceView::Config[:typhoeus][:collect_backtraces] = false
|
144
146
|
#
|
145
147
|
|
148
|
+
# By default, the curb instrumentation will not link
|
149
|
+
# outgoing requests with remotely instrumented
|
150
|
+
# webservers (aka cross host tracing). This is because the
|
151
|
+
# instrumentation can't detect if the independent libcurl
|
152
|
+
# instrumentation is in use or not.
|
153
|
+
#
|
154
|
+
# If you're sure that it's not in use/installed, then you can
|
155
|
+
# enable cross host tracing for the curb HTTP client
|
156
|
+
# here. Set TraceView::Config[:curb][:cross_host] to true
|
157
|
+
# to enable.
|
158
|
+
#
|
159
|
+
# Alternatively, if you would like to install the separate
|
160
|
+
# libcurl instrumentation, see here:
|
161
|
+
# http://docs.appneta.com/installing-libcurl-instrumentation
|
162
|
+
# TraceView::Config[:curb][:cross_host] = false
|
163
|
+
|
146
164
|
#
|
147
165
|
# Resque Options
|
148
166
|
#
|
data/lib/traceview/base.rb
CHANGED
@@ -35,6 +35,9 @@ module TraceViewBase
|
|
35
35
|
thread_local :sample_rate
|
36
36
|
thread_local :layer
|
37
37
|
thread_local :layer_op
|
38
|
+
# Semaphore used during the test suite to test
|
39
|
+
# global config options.
|
40
|
+
thread_local :config_lock
|
38
41
|
|
39
42
|
# The following accessors indicate the incoming tracing state received
|
40
43
|
# by the rack layer. These are primarily used to identify state
|
@@ -191,6 +194,34 @@ module TraceViewBase
|
|
191
194
|
end
|
192
195
|
end
|
193
196
|
|
197
|
+
##
|
198
|
+
# Debugging helper method
|
199
|
+
#
|
200
|
+
def pry!
|
201
|
+
# Only valid for development or test environments
|
202
|
+
env = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
203
|
+
return unless [ "development", "test" ].include? env
|
204
|
+
|
205
|
+
if RUBY_VERSION > '1.8.7'
|
206
|
+
require 'pry-byebug'
|
207
|
+
|
208
|
+
if defined?(PryByebug)
|
209
|
+
Pry.commands.alias_command 'c', 'continue'
|
210
|
+
Pry.commands.alias_command 's', 'step'
|
211
|
+
Pry.commands.alias_command 'n', 'next'
|
212
|
+
Pry.commands.alias_command 'f', 'finish'
|
213
|
+
|
214
|
+
Pry::Commands.command /^$/, "repeat last command" do
|
215
|
+
_pry_.run_command Pry.history.to_a.last
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
binding.pry
|
220
|
+
else
|
221
|
+
require 'ruby-debug'; debugger
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
194
225
|
##
|
195
226
|
# Indicates whether a supported framework is in use
|
196
227
|
# or not
|
@@ -227,3 +258,4 @@ end
|
|
227
258
|
# Setup an alias so we don't bug users
|
228
259
|
# about single letter capitalization
|
229
260
|
Traceview = TraceView
|
261
|
+
TV = TraceView
|
data/lib/traceview/config.rb
CHANGED
@@ -12,13 +12,13 @@ module TraceView
|
|
12
12
|
@@config = {}
|
13
13
|
|
14
14
|
@@instrumentation = [:action_controller, :action_view, :active_record,
|
15
|
-
:cassandra, :dalli, :em_http_request, :excon, :faraday,
|
15
|
+
:cassandra, :curb, :dalli, :em_http_request, :excon, :faraday,
|
16
16
|
:grape, :httpclient, :nethttp, :memcached, :memcache, :mongo,
|
17
17
|
:moped, :rack, :redis, :resque, :rest_client, :sequel,
|
18
18
|
:typhoeus]
|
19
19
|
|
20
20
|
# Subgrouping of instrumentation
|
21
|
-
@@http_clients = [:excon, :faraday, :httpclient, :nethttp, :rest_client, :typhoeus]
|
21
|
+
@@http_clients = [:curb, :excon, :faraday, :httpclient, :nethttp, :rest_client, :typhoeus]
|
22
22
|
|
23
23
|
##
|
24
24
|
# Return the raw nested hash.
|
@@ -44,6 +44,7 @@ module TraceView
|
|
44
44
|
TraceView::Config[:active_record][:collect_backtraces] = true
|
45
45
|
TraceView::Config[:action_view][:collect_backtraces] = true
|
46
46
|
TraceView::Config[:cassandra][:collect_backtraces] = true
|
47
|
+
TraceView::Config[:curb][:collect_backtraces] = true
|
47
48
|
TraceView::Config[:dalli][:collect_backtraces] = false
|
48
49
|
TraceView::Config[:em_http_request][:collect_backtraces] = false
|
49
50
|
TraceView::Config[:excon][:collect_backtraces] = true
|
@@ -146,6 +147,22 @@ module TraceView
|
|
146
147
|
# report all raised exception regardless.
|
147
148
|
@@config[:report_rescued_errors] = false
|
148
149
|
|
150
|
+
# By default, the curb instrumentation will not link
|
151
|
+
# outgoing requests with remotely instrumented
|
152
|
+
# webservers (aka cross host tracing). This is because the
|
153
|
+
# instrumentation can't detect if the independent libcurl
|
154
|
+
# instrumentation is in use or not.
|
155
|
+
#
|
156
|
+
# If you're sure that it's not in use/installed, then you can
|
157
|
+
# enable cross host tracing for the curb HTTP client
|
158
|
+
# here. Set TraceView::Config[:curb][:cross_host] to true
|
159
|
+
# to enable.
|
160
|
+
#
|
161
|
+
# Alternatively, if you would like to install the separate
|
162
|
+
# libcurl instrumentation, see here:
|
163
|
+
# http://docs.appneta.com/installing-libcurl-instrumentation
|
164
|
+
@@config[:curb][:cross_host] = false
|
165
|
+
|
149
166
|
# Environment support for OpenShift.
|
150
167
|
if ENV.key?('OPENSHIFT_TRACEVIEW_TLYZER_IP')
|
151
168
|
# We're running on OpenShift
|
@@ -0,0 +1,281 @@
|
|
1
|
+
# Copyright (c) 2015 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
module TraceView
|
5
|
+
module Inst
|
6
|
+
|
7
|
+
# Curb instrumentation wraps instance and class methods in two classes:
|
8
|
+
# Curl::Easy and Curl::Multi. This CurlUtility module is used as a common module
|
9
|
+
# to be shared among both modules.
|
10
|
+
module CurlUtility
|
11
|
+
|
12
|
+
##
|
13
|
+
# traceview_collect
|
14
|
+
#
|
15
|
+
# Used as a central area to retrieve and return values
|
16
|
+
# that we're interesting in reporting to TraceView
|
17
|
+
#
|
18
|
+
def traceview_collect(verb = nil)
|
19
|
+
kvs = {}
|
20
|
+
|
21
|
+
if TraceView::Config[:curb][:cross_host]
|
22
|
+
kvs['IsService'] = 1
|
23
|
+
|
24
|
+
# Conditionally log query args
|
25
|
+
if TraceView::Config[:curb][:log_args]
|
26
|
+
kvs[:RemoteURL] = url
|
27
|
+
else
|
28
|
+
kvs[:RemoteURL] = url.split('?').first
|
29
|
+
end
|
30
|
+
|
31
|
+
kvs[:HTTPMethod] = verb if verb
|
32
|
+
end
|
33
|
+
|
34
|
+
# Avoid cross host tracing for blacklisted domains
|
35
|
+
kvs[:blacklisted] = TraceView::API.blacklisted?(URI(url).hostname)
|
36
|
+
kvs['Backtrace'] = TraceView::API.backtrace if TraceView::Config[:curb][:collect_backtraces]
|
37
|
+
|
38
|
+
kvs
|
39
|
+
rescue => e
|
40
|
+
TraceView.logger.debug "[traceview/debug] Error capturing curb KVs: #{e.message}"
|
41
|
+
TraceView.logger.debug e.backtrace.join('\n') if ::TraceView::Config[:verbose]
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# profile_curb_method
|
46
|
+
#
|
47
|
+
# An agnostic method that will profile any Curl::Easy method (and optional args and block)
|
48
|
+
# that you throw at it.
|
49
|
+
#
|
50
|
+
def profile_curb_method(kvs, method, args, &block)
|
51
|
+
# If we're not tracing, just do a fast return.
|
52
|
+
return self.send(method, args, &block) if !TraceView.tracing?
|
53
|
+
|
54
|
+
begin
|
55
|
+
response_context = nil
|
56
|
+
req_context = nil
|
57
|
+
handle_cross_host = TraceView::Config[:curb][:cross_host]
|
58
|
+
kvs.merge! traceview_collect
|
59
|
+
|
60
|
+
TraceView::API.log_entry('curb', kvs)
|
61
|
+
kvs.clear
|
62
|
+
|
63
|
+
if handle_cross_host && !kvs[:blacklisted]
|
64
|
+
req_context = TraceView::Context.toString()
|
65
|
+
self.headers['X-Trace'] = req_context
|
66
|
+
end
|
67
|
+
|
68
|
+
# The core curb call
|
69
|
+
response = self.send(method, *args, &block)
|
70
|
+
|
71
|
+
if handle_cross_host
|
72
|
+
kvs['HTTPStatus'] = response_code
|
73
|
+
|
74
|
+
# If we get a redirect, report the location header
|
75
|
+
if ((300..308).to_a.include? response_code) && headers.key?("Location")
|
76
|
+
kvs["Location"] = headers["Location"]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Curb only provides a single long string of all response headers (yuck!). So we are forced
|
80
|
+
# to process that string to pull out the response X-Trace value.
|
81
|
+
# Taken from https://stackoverflow.com/questions/14345805/curb-get-response-headers
|
82
|
+
_, *response_headers = header_str.split(/[\r\n]+/).map(&:strip)
|
83
|
+
response_headers = Hash[response_headers.flat_map{ |s| s.scan(/^(\S+): (.+)/) }]
|
84
|
+
|
85
|
+
response_context = response_headers['X-Trace']
|
86
|
+
if response_context && !kvs[:blacklisted]
|
87
|
+
TraceView::XTrace.continue_service_context(req_context, response_context)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
response
|
92
|
+
rescue => e
|
93
|
+
TraceView::API.log_exception('curb', e)
|
94
|
+
raise e
|
95
|
+
ensure
|
96
|
+
TraceView::API.log_exit('curb', kvs)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end # CurlUtility
|
101
|
+
|
102
|
+
# Instrumentation specific to ::Curl::Easy
|
103
|
+
module CurlEasy
|
104
|
+
# Common methods
|
105
|
+
include TraceView::Inst::CurlUtility
|
106
|
+
|
107
|
+
def self.included(klass)
|
108
|
+
::TraceView::Util.method_alias(klass, :http, ::Curl::Easy)
|
109
|
+
::TraceView::Util.method_alias(klass, :perform, ::Curl::Easy)
|
110
|
+
::TraceView::Util.method_alias(klass, :http_put, ::Curl::Easy)
|
111
|
+
::TraceView::Util.method_alias(klass, :http_post, ::Curl::Easy)
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# http_post_with_traceview
|
116
|
+
#
|
117
|
+
# ::Curl::Easy.new.http_post wrapper
|
118
|
+
#
|
119
|
+
def http_post_with_traceview(*args, &block)
|
120
|
+
# If we're not tracing, just do a fast return.
|
121
|
+
if !TraceView.tracing? || TraceView.tracing_layer?('curb')
|
122
|
+
return http_post_without_traceview(*args)
|
123
|
+
end
|
124
|
+
|
125
|
+
kvs = {}
|
126
|
+
if TraceView::Config[:curb][:cross_host]
|
127
|
+
kvs[:HTTPMethod] = :POST
|
128
|
+
end
|
129
|
+
|
130
|
+
profile_curb_method(kvs, :http_post_without_traceview, args, &block)
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# http_put_with_traceview
|
135
|
+
#
|
136
|
+
# ::Curl::Easy.new.http_put wrapper
|
137
|
+
#
|
138
|
+
def http_put_with_traceview(*args, &block)
|
139
|
+
# If we're not tracing, just do a fast return.
|
140
|
+
if !TraceView.tracing? || TraceView.tracing_layer?('curb')
|
141
|
+
return http_put_without_traceview(data)
|
142
|
+
end
|
143
|
+
|
144
|
+
kvs = {}
|
145
|
+
if TraceView::Config[:curb][:cross_host]
|
146
|
+
kvs[:HTTPMethod] = :PUT
|
147
|
+
end
|
148
|
+
|
149
|
+
profile_curb_method(kvs, :http_post_without_traceview, args, &block)
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# perform_with_traceview
|
154
|
+
#
|
155
|
+
# ::Curl::Easy.new.perform wrapper
|
156
|
+
#
|
157
|
+
def perform_with_traceview(&block)
|
158
|
+
# If we're not tracing, just do a fast return.
|
159
|
+
if !TraceView.tracing? || TraceView.tracing_layer?('curb')
|
160
|
+
return perform_without_traceview(&block)
|
161
|
+
end
|
162
|
+
|
163
|
+
kvs = {}
|
164
|
+
# This perform gets called from two places, ::Curl::Easy.new.perform
|
165
|
+
# and Curl::Easy.new.http_head. In the case of http_head we detect the
|
166
|
+
# HTTP verb via get info.
|
167
|
+
if TraceView::Config[:curb][:cross_host]
|
168
|
+
if self.getinfo(self.sym2curl(:nobody))
|
169
|
+
kvs[:HTTPMethod] = :HEAD
|
170
|
+
else
|
171
|
+
kvs[:HTTPMethod] = :GET
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
return profile_curb_method(kvs, :perform_without_traceview, nil, &block)
|
176
|
+
end
|
177
|
+
|
178
|
+
##
|
179
|
+
# http_with_traceview
|
180
|
+
#
|
181
|
+
# ::Curl::Easy.new.http wrapper
|
182
|
+
#
|
183
|
+
def http_with_traceview(verb, &block)
|
184
|
+
# If we're not tracing, just do a fast return.
|
185
|
+
return http_without_traceview(verb) if !TraceView.tracing?
|
186
|
+
|
187
|
+
kvs = {}
|
188
|
+
if TraceView::Config[:curb][:cross_host]
|
189
|
+
kvs[:HTTPMethod] = verb
|
190
|
+
end
|
191
|
+
|
192
|
+
profile_curb_method(kvs, :http_without_traceview, [verb], &block)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
##
|
197
|
+
# CurlMultiCM
|
198
|
+
#
|
199
|
+
# This module contains the class method wrappers for the CurlMulti class.
|
200
|
+
# This module should be _extended_ by CurlMulti.
|
201
|
+
#
|
202
|
+
module CurlMultiCM
|
203
|
+
def self.extended(klass)
|
204
|
+
::TraceView::Util.class_method_alias(klass, :http, ::Curl::Multi)
|
205
|
+
end
|
206
|
+
|
207
|
+
##
|
208
|
+
# http_with_traceview
|
209
|
+
#
|
210
|
+
# ::Curl::Multi.new.http wrapper
|
211
|
+
#
|
212
|
+
def http_with_traceview(urls_with_config, multi_options={}, &block)
|
213
|
+
# If we're not tracing, just do a fast return.
|
214
|
+
if !TraceView.tracing?
|
215
|
+
return http_without_traceview(urls_with_config, multi_options, &block)
|
216
|
+
end
|
217
|
+
|
218
|
+
begin
|
219
|
+
kvs = {}
|
220
|
+
kvs['Backtrace'] = TraceView::API.backtrace if TraceView::Config[:curb][:collect_backtraces]
|
221
|
+
|
222
|
+
TraceView::API.log_entry('curb_multi', kvs)
|
223
|
+
|
224
|
+
# The core curb call
|
225
|
+
http_without_traceview(urls_with_config, multi_options, &block)
|
226
|
+
rescue => e
|
227
|
+
TraceView::API.log_exception('curb_multi', e)
|
228
|
+
raise e
|
229
|
+
ensure
|
230
|
+
TraceView::API.log_exit('curb_multi')
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
##
|
236
|
+
# CurlMultiIM
|
237
|
+
#
|
238
|
+
# This module contains the instance method wrappers for the CurlMulti class.
|
239
|
+
# This module should be _included_ into CurlMulti.
|
240
|
+
#
|
241
|
+
module CurlMultiIM
|
242
|
+
def self.included(klass)
|
243
|
+
::TraceView::Util.method_alias(klass, :perform, ::Curl::Multi)
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# perform_with_traceview
|
248
|
+
#
|
249
|
+
# ::Curl::Multi.new.perform wrapper
|
250
|
+
#
|
251
|
+
def perform_with_traceview(&block)
|
252
|
+
# If we're not tracing or we're not already tracing curb, just do a fast return.
|
253
|
+
if !TraceView.tracing? || ['curb', 'curb_multi'].include?(TraceView.layer)
|
254
|
+
return perform_without_traceview(&block)
|
255
|
+
end
|
256
|
+
|
257
|
+
begin
|
258
|
+
kvs = {}
|
259
|
+
kvs['Backtrace'] = TraceView::API.backtrace if TraceView::Config[:curb][:collect_backtraces]
|
260
|
+
|
261
|
+
TraceView::API.log_entry('curb_multi', kvs)
|
262
|
+
|
263
|
+
# The core curb call
|
264
|
+
perform_without_traceview(&block)
|
265
|
+
rescue => e
|
266
|
+
TraceView::API.log_exception('curb_multi', e)
|
267
|
+
raise e
|
268
|
+
ensure
|
269
|
+
TraceView::API.log_exit('curb_multi')
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
if TraceView::Config[:curb][:enabled] && defined?(::Curl) && RUBY_VERSION > '1.8.7'
|
277
|
+
::TraceView.logger.info '[traceview/loading] Instrumenting curb' if TraceView::Config[:verbose]
|
278
|
+
::TraceView::Util.send_include(::Curl::Easy, ::TraceView::Inst::CurlEasy)
|
279
|
+
::TraceView::Util.send_extend(::Curl::Multi, ::TraceView::Inst::CurlMultiCM)
|
280
|
+
::TraceView::Util.send_include(::Curl::Multi, ::TraceView::Inst::CurlMultiIM)
|
281
|
+
end
|
data/lib/traceview/util.rb
CHANGED
@@ -205,6 +205,7 @@ module TraceView
|
|
205
205
|
|
206
206
|
# Report the instrumented libraries
|
207
207
|
platform_info['Ruby.Cassandra.Version'] = "Cassandra-#{::Cassandra.VERSION}" if defined?(::Cassandra.VERSION)
|
208
|
+
platform_info['Ruby.Curb.Version'] = "Curb-#{::Curl::VERSION}" if defined?(::Curl::VERSION)
|
208
209
|
platform_info['Ruby.Dalli.Version'] = "Dalli-#{::Dalli::VERSION}" if defined?(::Dalli::VERSION)
|
209
210
|
platform_info['Ruby.Excon.Version'] = "Excon-#{::Excon::VERSION}" if defined?(::Excon::VERSION)
|
210
211
|
platform_info['Ruby.Faraday.Version'] = "Faraday-#{::Faraday::VERSION}" if defined?(::Faraday::VERSION)
|
data/lib/traceview/version.rb
CHANGED
@@ -0,0 +1,542 @@
|
|
1
|
+
# Copyright (c) 2015 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
if RUBY_VERSION > '1.8.7'
|
5
|
+
|
6
|
+
require 'minitest_helper'
|
7
|
+
require 'traceview/inst/rack'
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '../../frameworks/apps/sinatra_simple')
|
9
|
+
|
10
|
+
class CurbTest < Minitest::Test
|
11
|
+
include Rack::Test::Methods
|
12
|
+
|
13
|
+
def setup
|
14
|
+
clear_all_traces
|
15
|
+
TraceView.config_lock.synchronize {
|
16
|
+
@cb = TraceView::Config[:curb][:collect_backtraces]
|
17
|
+
@log_args = TraceView::Config[:curb][:log_args]
|
18
|
+
@tm = TraceView::Config[:tracing_mode]
|
19
|
+
@cross_host = TraceView::Config[:curb][:cross_host]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
TraceView.config_lock.synchronize {
|
25
|
+
TraceView::Config[:curb][:collect_backtraces] = @cb
|
26
|
+
TraceView::Config[:curb][:log_args] = @log_args
|
27
|
+
TraceView::Config[:tracing_mode] = @tm
|
28
|
+
TraceView::Config[:curb][:cross_host] = @cross_host
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def app
|
33
|
+
SinatraSimple
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_reports_version_init
|
37
|
+
init_kvs = ::TraceView::Util.build_init_report
|
38
|
+
assert init_kvs.key?('Ruby.Curb.Version')
|
39
|
+
assert_equal init_kvs['Ruby.Curb.Version'], "Curb-#{::Curl::VERSION}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_class_get_request
|
43
|
+
response = nil
|
44
|
+
|
45
|
+
TraceView::API.start_trace('curb_tests') do
|
46
|
+
response = Curl.get('http://127.0.0.1:8101/')
|
47
|
+
end
|
48
|
+
|
49
|
+
assert response.body_str == "Hello TraceView!"
|
50
|
+
assert response.response_code == 200
|
51
|
+
assert response.header_str =~ /X-Trace/, "X-Trace response header"
|
52
|
+
|
53
|
+
traces = get_all_traces
|
54
|
+
assert_equal 7, traces.count, "Trace count"
|
55
|
+
validate_outer_layers(traces, "curb_tests")
|
56
|
+
|
57
|
+
assert_equal 'curb', traces[1]['Layer']
|
58
|
+
assert_equal 'entry', traces[1]['Label']
|
59
|
+
assert_equal false, traces[1].key?('IsService')
|
60
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
61
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
62
|
+
assert traces[1].key?('Backtrace')
|
63
|
+
|
64
|
+
assert_equal 'curb', traces[5]['Layer']
|
65
|
+
assert_equal 'exit', traces[5]['Label']
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_class_delete_request
|
69
|
+
response = nil
|
70
|
+
|
71
|
+
TraceView::API.start_trace('curb_tests') do
|
72
|
+
response = Curl.delete('http://127.0.0.1:8101/?curb_delete_test', :id => 1)
|
73
|
+
end
|
74
|
+
|
75
|
+
assert response.body_str == "Hello TraceView!"
|
76
|
+
assert response.response_code == 200
|
77
|
+
assert response.header_str =~ /X-Trace/, "X-Trace response header"
|
78
|
+
|
79
|
+
traces = get_all_traces
|
80
|
+
assert_equal 7, traces.count, "Trace count"
|
81
|
+
validate_outer_layers(traces, "curb_tests")
|
82
|
+
|
83
|
+
assert_equal 'curb', traces[1]['Layer']
|
84
|
+
assert_equal 'entry', traces[1]['Label']
|
85
|
+
assert_equal false, traces[1].key?('IsService')
|
86
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
87
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
88
|
+
assert traces[1].key?('Backtrace')
|
89
|
+
|
90
|
+
assert_equal 'curb', traces[5]['Layer']
|
91
|
+
assert_equal 'exit', traces[5]['Label']
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_class_post_request
|
95
|
+
response = nil
|
96
|
+
|
97
|
+
TraceView::API.start_trace('curb_tests') do
|
98
|
+
response = Curl.post('http://127.0.0.1:8101/')
|
99
|
+
end
|
100
|
+
|
101
|
+
assert response.body_str == "Hello TraceView!"
|
102
|
+
assert response.response_code == 200
|
103
|
+
assert response.header_str =~ /X-Trace/, "X-Trace response header"
|
104
|
+
|
105
|
+
traces = get_all_traces
|
106
|
+
assert_equal 7, traces.count, "Trace count"
|
107
|
+
validate_outer_layers(traces, "curb_tests")
|
108
|
+
|
109
|
+
assert_equal 'curb', traces[1]['Layer']
|
110
|
+
assert_equal 'entry', traces[1]['Label']
|
111
|
+
assert_equal false, traces[1].key?('IsService')
|
112
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
113
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
114
|
+
assert traces[1].key?('Backtrace')
|
115
|
+
|
116
|
+
assert_equal 'curb', traces[5]['Layer']
|
117
|
+
assert_equal 'exit', traces[5]['Label']
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_easy_class_perform
|
121
|
+
response = nil
|
122
|
+
|
123
|
+
TraceView::API.start_trace('curb_tests') do
|
124
|
+
response = Curl::Easy.perform("http://127.0.0.1:8101/")
|
125
|
+
end
|
126
|
+
|
127
|
+
assert response.is_a?(::Curl::Easy)
|
128
|
+
assert response.body_str == "Hello TraceView!"
|
129
|
+
assert response.response_code == 200
|
130
|
+
assert response.header_str =~ /X-Trace/, "X-Trace response header"
|
131
|
+
|
132
|
+
traces = get_all_traces
|
133
|
+
assert_equal 7, traces.count, "Trace count"
|
134
|
+
validate_outer_layers(traces, "curb_tests")
|
135
|
+
|
136
|
+
assert_equal 'curb', traces[1]['Layer']
|
137
|
+
assert_equal 'entry', traces[1]['Label']
|
138
|
+
assert_equal false, traces[1].key?('IsService')
|
139
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
140
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
141
|
+
assert traces[1].key?('Backtrace')
|
142
|
+
|
143
|
+
assert_equal 'curb', traces[5]['Layer']
|
144
|
+
assert_equal 'exit', traces[5]['Label']
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_easy_http_head
|
148
|
+
c = nil
|
149
|
+
|
150
|
+
TraceView::API.start_trace('curb_tests') do
|
151
|
+
c = Curl::Easy.new("http://127.0.0.1:8101/")
|
152
|
+
c.http_head
|
153
|
+
end
|
154
|
+
|
155
|
+
assert c.is_a?(::Curl::Easy), "Response type"
|
156
|
+
assert c.response_code == 200
|
157
|
+
assert c.header_str =~ /X-Trace/, "X-Trace response header"
|
158
|
+
|
159
|
+
traces = get_all_traces
|
160
|
+
assert_equal 7, traces.count, "Trace count"
|
161
|
+
validate_outer_layers(traces, "curb_tests")
|
162
|
+
|
163
|
+
assert_equal 'curb', traces[1]['Layer']
|
164
|
+
assert_equal 'entry', traces[1]['Label']
|
165
|
+
assert_equal false, traces[1].key?('IsService')
|
166
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
167
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
168
|
+
assert traces[1].key?('Backtrace')
|
169
|
+
|
170
|
+
assert_equal 'curb', traces[5]['Layer']
|
171
|
+
assert_equal 'exit', traces[5]['Label']
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_easy_http_put
|
175
|
+
c = nil
|
176
|
+
|
177
|
+
TraceView::API.start_trace('curb_tests') do
|
178
|
+
c = Curl::Easy.new("http://127.0.0.1:8101/")
|
179
|
+
c.http_put(:id => 1)
|
180
|
+
end
|
181
|
+
|
182
|
+
assert c.is_a?(::Curl::Easy), "Response type"
|
183
|
+
assert c.response_code == 200
|
184
|
+
assert c.header_str =~ /X-Trace/, "X-Trace response header"
|
185
|
+
|
186
|
+
traces = get_all_traces
|
187
|
+
assert_equal 7, traces.count, "Trace count"
|
188
|
+
validate_outer_layers(traces, "curb_tests")
|
189
|
+
|
190
|
+
assert_equal 'curb', traces[1]['Layer']
|
191
|
+
assert_equal 'entry', traces[1]['Label']
|
192
|
+
assert_equal false, traces[1].key?('IsService')
|
193
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
194
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
195
|
+
assert traces[1].key?('Backtrace')
|
196
|
+
|
197
|
+
assert_equal 'curb', traces[5]['Layer']
|
198
|
+
assert_equal 'exit', traces[5]['Label']
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_easy_http_post
|
202
|
+
c = nil
|
203
|
+
|
204
|
+
TraceView::API.start_trace('curb_tests') do
|
205
|
+
url = "http://127.0.0.1:8101/"
|
206
|
+
c = Curl::Easy.new(url)
|
207
|
+
c.http_post(url, :id => 1)
|
208
|
+
end
|
209
|
+
|
210
|
+
assert c.is_a?(::Curl::Easy), "Response type"
|
211
|
+
assert c.response_code == 200
|
212
|
+
assert c.header_str =~ /X-Trace/, "X-Trace response header"
|
213
|
+
|
214
|
+
traces = get_all_traces
|
215
|
+
assert_equal 7, traces.count, "Trace count"
|
216
|
+
validate_outer_layers(traces, "curb_tests")
|
217
|
+
|
218
|
+
assert_equal 'curb', traces[1]['Layer']
|
219
|
+
assert_equal 'entry', traces[1]['Label']
|
220
|
+
assert_equal false, traces[1].key?('IsService')
|
221
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
222
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
223
|
+
assert traces[1].key?('Backtrace')
|
224
|
+
|
225
|
+
assert_equal 'curb', traces[5]['Layer']
|
226
|
+
assert_equal 'exit', traces[5]['Label']
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_class_fetch_with_block
|
230
|
+
response = nil
|
231
|
+
|
232
|
+
TraceView::API.start_trace('curb_tests') do
|
233
|
+
response = Curl::Easy.perform("http://127.0.0.1:8101/") do |curl|
|
234
|
+
curl.headers["User-Agent"] = "TraceView 2000"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
assert response.is_a?(::Curl::Easy), "Response type"
|
239
|
+
assert response.response_code == 200
|
240
|
+
assert response.header_str =~ /X-Trace/, "X-Trace response header"
|
241
|
+
|
242
|
+
traces = get_all_traces
|
243
|
+
assert_equal 7, traces.count, "Trace count"
|
244
|
+
validate_outer_layers(traces, "curb_tests")
|
245
|
+
|
246
|
+
assert_equal 'curb', traces[1]['Layer']
|
247
|
+
assert_equal 'entry', traces[1]['Label']
|
248
|
+
assert_equal traces[5]['Label'], 'exit'
|
249
|
+
assert_equal false, traces[1].key?('IsService')
|
250
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
251
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
252
|
+
assert traces[1].key?('Backtrace')
|
253
|
+
|
254
|
+
assert_equal 'curb', traces[5]['Layer']
|
255
|
+
assert_equal 'exit', traces[5]['Label']
|
256
|
+
assert_equal false, traces[5].key?('HTTPStatus')
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_cross_app_tracing
|
260
|
+
response = nil
|
261
|
+
|
262
|
+
# When testing global config options, use the config_locak
|
263
|
+
# semaphore to lock between other running tests.
|
264
|
+
TraceView.config_lock.synchronize {
|
265
|
+
TraceView::Config[:curb][:cross_host] = true
|
266
|
+
|
267
|
+
TraceView::API.start_trace('curb_tests') do
|
268
|
+
response = ::Curl.get('http://127.0.0.1:8101/?curb_cross_host=1')
|
269
|
+
end
|
270
|
+
}
|
271
|
+
|
272
|
+
xtrace = response.headers['X-Trace']
|
273
|
+
assert xtrace, "X-Trace response header"
|
274
|
+
assert TraceView::XTrace.valid?(xtrace)
|
275
|
+
assert response.header_str =~ /X-Trace/, "X-Trace response header"
|
276
|
+
|
277
|
+
traces = get_all_traces
|
278
|
+
assert_equal 7, traces.count, "Trace count"
|
279
|
+
validate_outer_layers(traces, "curb_tests")
|
280
|
+
assert valid_edges?(traces), "Trace edge validation"
|
281
|
+
|
282
|
+
assert_equal 'curb', traces[1]['Layer']
|
283
|
+
assert_equal 'entry', traces[1]['Label']
|
284
|
+
assert_equal 1, traces[1]['IsService']
|
285
|
+
assert_equal 'GET', traces[1]['HTTPMethod'], "HTTP Method"
|
286
|
+
assert_equal "http://127.0.0.1:8101/?curb_cross_host=1&", traces[1]['RemoteURL']
|
287
|
+
assert traces[1].key?('Backtrace')
|
288
|
+
|
289
|
+
assert_equal 'curb', traces[5]['Layer']
|
290
|
+
assert_equal 'exit', traces[5]['Label']
|
291
|
+
assert_equal 200, traces[5]['HTTPStatus']
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_multi_basic_get
|
296
|
+
responses = nil
|
297
|
+
easy_options = {:follow_location => true}
|
298
|
+
multi_options = {:pipeline => false}
|
299
|
+
|
300
|
+
urls = []
|
301
|
+
urls << "http://127.0.0.1:8101/?one=1"
|
302
|
+
urls << "http://127.0.0.1:8101/?two=2"
|
303
|
+
urls << "http://127.0.0.1:8101/?three=3"
|
304
|
+
|
305
|
+
TraceView::API.start_trace('curb_tests') do
|
306
|
+
responses = Curl::Multi.get(urls, easy_options, multi_options) do |easy|
|
307
|
+
nil
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
traces = get_all_traces
|
312
|
+
assert_equal 13, traces.count, "Trace count"
|
313
|
+
validate_outer_layers(traces, "curb_tests")
|
314
|
+
|
315
|
+
assert_equal traces[1]['Layer'], 'curb_multi'
|
316
|
+
assert_equal traces[1]['Label'], 'entry'
|
317
|
+
assert_equal traces[11]['Layer'], 'curb_multi'
|
318
|
+
assert_equal traces[11]['Label'], 'exit'
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_multi_basic_post
|
322
|
+
responses = nil
|
323
|
+
easy_options = {:follow_location => true, :multipart_form_post => true}
|
324
|
+
multi_options = {:pipeline => true}
|
325
|
+
|
326
|
+
urls = []
|
327
|
+
urls << { :url => "http://127.0.0.1:8101/1", :post_fields => { :id => 1 } }
|
328
|
+
urls << { :url => "http://127.0.0.1:8101/2", :post_fields => { :id => 2 } }
|
329
|
+
urls << { :url => "http://127.0.0.1:8101/3", :post_fields => { :id => 3 } }
|
330
|
+
|
331
|
+
TraceView::API.start_trace('curb_tests') do
|
332
|
+
responses = Curl::Multi.post(urls, easy_options, multi_options) do |easy|
|
333
|
+
nil
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
traces = get_all_traces
|
338
|
+
assert_equal 13, traces.count, "Trace count"
|
339
|
+
validate_outer_layers(traces, "curb_tests")
|
340
|
+
|
341
|
+
assert_equal traces[1]['Layer'], 'curb_multi'
|
342
|
+
assert_equal traces[1]['Label'], 'entry'
|
343
|
+
assert_equal traces[11]['Layer'], 'curb_multi'
|
344
|
+
assert_equal traces[11]['Label'], 'exit'
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_multi_basic_get_pipeline
|
348
|
+
responses = nil
|
349
|
+
easy_options = {:follow_location => true}
|
350
|
+
multi_options = {:pipeline => true}
|
351
|
+
|
352
|
+
urls = []
|
353
|
+
urls << "http://127.0.0.1:8101/?one=1"
|
354
|
+
urls << "http://127.0.0.1:8101/?two=2"
|
355
|
+
urls << "http://127.0.0.1:8101/?three=3"
|
356
|
+
|
357
|
+
TraceView::API.start_trace('curb_tests') do
|
358
|
+
responses = Curl::Multi.get(urls, easy_options, multi_options) do |easy|
|
359
|
+
nil
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
traces = get_all_traces
|
364
|
+
assert_equal 13, traces.count, "Trace count"
|
365
|
+
validate_outer_layers(traces, "curb_tests")
|
366
|
+
|
367
|
+
assert_equal traces[1]['Layer'], 'curb_multi'
|
368
|
+
assert_equal traces[1]['Label'], 'entry'
|
369
|
+
assert_equal traces[11]['Layer'], 'curb_multi'
|
370
|
+
assert_equal traces[11]['Label'], 'exit'
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_multi_advanced_get
|
374
|
+
responses = {}
|
375
|
+
|
376
|
+
urls = []
|
377
|
+
urls << "http://127.0.0.1:8101/?one=1"
|
378
|
+
urls << "http://127.0.0.1:8101/?two=2"
|
379
|
+
urls << "http://127.0.0.1:8101/?three=3"
|
380
|
+
|
381
|
+
TraceView::API.start_trace('curb_tests') do
|
382
|
+
m = Curl::Multi.new
|
383
|
+
urls.each do |url|
|
384
|
+
responses[url] = ""
|
385
|
+
c = Curl::Easy.new(url) do |curl|
|
386
|
+
curl.follow_location = true
|
387
|
+
end
|
388
|
+
m.add c
|
389
|
+
end
|
390
|
+
|
391
|
+
m.perform do
|
392
|
+
nil
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
traces = get_all_traces
|
397
|
+
assert_equal 13, traces.count, "Trace count"
|
398
|
+
validate_outer_layers(traces, "curb_tests")
|
399
|
+
|
400
|
+
assert_equal traces[1]['Layer'], 'curb_multi'
|
401
|
+
assert_equal traces[1]['Label'], 'entry'
|
402
|
+
assert_equal traces[11]['Layer'], 'curb_multi'
|
403
|
+
assert_equal traces[11]['Label'], 'exit'
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_requests_with_errors
|
407
|
+
begin
|
408
|
+
TraceView::API.start_trace('curb_tests') do
|
409
|
+
Curl.get('http://asfjalkfjlajfljkaljf/')
|
410
|
+
end
|
411
|
+
rescue
|
412
|
+
end
|
413
|
+
|
414
|
+
traces = get_all_traces
|
415
|
+
assert_equal 5, traces.count, "Trace count"
|
416
|
+
validate_outer_layers(traces, "curb_tests")
|
417
|
+
assert valid_edges?(traces), "Trace edge validation"
|
418
|
+
|
419
|
+
assert_equal false, traces[1].key?('IsService')
|
420
|
+
assert_equal false, traces[1].key?('RemoteURL')
|
421
|
+
assert_equal false, traces[1].key?('HTTPMethod')
|
422
|
+
assert traces[1].key?('Backtrace')
|
423
|
+
|
424
|
+
assert_equal 'curb', traces[2]['Layer']
|
425
|
+
assert_equal 'error', traces[2]['Label']
|
426
|
+
assert_equal "Curl::Err::HostResolutionError", traces[2]['ErrorClass']
|
427
|
+
assert traces[2].key?('ErrorMsg')
|
428
|
+
assert traces[2].key?('Backtrace')
|
429
|
+
|
430
|
+
assert_equal 'curb', traces[3]['Layer']
|
431
|
+
assert_equal 'exit', traces[3]['Label']
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_obey_log_args_when_false
|
435
|
+
# When testing global config options, use the config_locak
|
436
|
+
# semaphore to lock between other running tests.
|
437
|
+
TraceView.config_lock.synchronize {
|
438
|
+
TraceView::Config[:curb][:log_args] = false
|
439
|
+
TraceView::Config[:curb][:cross_host] = true
|
440
|
+
|
441
|
+
http = nil
|
442
|
+
|
443
|
+
TraceView::API.start_trace('curb_tests') do
|
444
|
+
http = Curl.get('http://127.0.0.1:8101/?blah=1')
|
445
|
+
end
|
446
|
+
}
|
447
|
+
|
448
|
+
traces = get_all_traces
|
449
|
+
assert_equal 7, traces.count, "Trace count"
|
450
|
+
assert_equal "http://127.0.0.1:8101/", traces[1]['RemoteURL']
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_obey_log_args_when_true
|
454
|
+
# When testing global config options, use the config_locak
|
455
|
+
# semaphore to lock between other running tests.
|
456
|
+
TraceView.config_lock.synchronize {
|
457
|
+
TraceView::Config[:curb][:log_args] = true
|
458
|
+
TraceView::Config[:curb][:cross_host] = true
|
459
|
+
|
460
|
+
http = nil
|
461
|
+
|
462
|
+
TraceView::API.start_trace('curb_tests') do
|
463
|
+
http = ::Curl.get('http://127.0.0.1:8101/?blah=1')
|
464
|
+
end
|
465
|
+
}
|
466
|
+
|
467
|
+
traces = get_all_traces
|
468
|
+
assert_equal 7, traces.count, "Trace count"
|
469
|
+
assert_equal "http://127.0.0.1:8101/?blah=1&", traces[1]['RemoteURL']
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_without_tracing_class_get
|
473
|
+
TraceView::Config[:tracing_mode] = :never
|
474
|
+
|
475
|
+
response = nil
|
476
|
+
|
477
|
+
TraceView::API.start_trace('httpclient_tests') do
|
478
|
+
response = ::Curl.get('http://127.0.0.1:8101/?blah=1')
|
479
|
+
end
|
480
|
+
|
481
|
+
assert response.headers['X-Trace'] == nil
|
482
|
+
assert response.body_str == "Hello TraceView!"
|
483
|
+
assert response.response_code == 200
|
484
|
+
|
485
|
+
traces = get_all_traces
|
486
|
+
assert_equal 0, traces.count, "Trace count"
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_without_tracing_easy_perform
|
490
|
+
response = nil
|
491
|
+
|
492
|
+
# When testing global config options, use the config_locak
|
493
|
+
# semaphore to lock between other running tests.
|
494
|
+
TraceView.config_lock.synchronize {
|
495
|
+
TraceView::Config[:tracing_mode] = :never
|
496
|
+
|
497
|
+
TraceView::API.start_trace('curb_tests') do
|
498
|
+
response = Curl::Easy.perform("http://127.0.0.1:8101/")
|
499
|
+
end
|
500
|
+
}
|
501
|
+
|
502
|
+
assert response.headers['X-Trace'] == nil
|
503
|
+
assert response.body_str == "Hello TraceView!"
|
504
|
+
assert response.response_code == 200
|
505
|
+
|
506
|
+
traces = get_all_traces
|
507
|
+
assert_equal 0, traces.count, "Trace count"
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_obey_collect_backtraces_when_true
|
511
|
+
# When testing global config options, use the config_locak
|
512
|
+
# semaphore to lock between other running tests.
|
513
|
+
TraceView.config_lock.synchronize {
|
514
|
+
TraceView::Config[:curb][:collect_backtraces] = true
|
515
|
+
sleep 1
|
516
|
+
|
517
|
+
TraceView::API.start_trace('curb_test') do
|
518
|
+
Curl.get("http://127.0.0.1:8101/")
|
519
|
+
end
|
520
|
+
}
|
521
|
+
|
522
|
+
traces = get_all_traces
|
523
|
+
layer_has_key(traces, 'curb', 'Backtrace')
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_obey_collect_backtraces_when_false
|
527
|
+
# When testing global config options, use the config_locak
|
528
|
+
# semaphore to lock between other running tests.
|
529
|
+
TraceView.config_lock.synchronize {
|
530
|
+
TraceView::Config[:curb][:collect_backtraces] = false
|
531
|
+
|
532
|
+
TraceView::API.start_trace('curb_test') do
|
533
|
+
Curl.get("http://127.0.0.1:8101/")
|
534
|
+
end
|
535
|
+
}
|
536
|
+
|
537
|
+
traces = get_all_traces
|
538
|
+
layer_doesnt_have_key(traces, 'curb', 'Backtrace')
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
data/test/support/config_test.rb
CHANGED
@@ -30,12 +30,13 @@ describe "TraceView::Config" do
|
|
30
30
|
instrumentation = TraceView::Config.instrumentation
|
31
31
|
|
32
32
|
# Verify the number of individual instrumentations
|
33
|
-
instrumentation.count.must_equal
|
33
|
+
instrumentation.count.must_equal 22
|
34
34
|
|
35
35
|
TraceView::Config[:action_controller][:enabled].must_equal true
|
36
36
|
TraceView::Config[:action_view][:enabled].must_equal true
|
37
37
|
TraceView::Config[:active_record][:enabled].must_equal true
|
38
38
|
TraceView::Config[:cassandra][:enabled].must_equal true
|
39
|
+
TraceView::Config[:curb][:enabled].must_equal true
|
39
40
|
TraceView::Config[:dalli][:enabled].must_equal true
|
40
41
|
TraceView::Config[:em_http_request][:enabled].must_equal false
|
41
42
|
TraceView::Config[:excon][:enabled].must_equal true
|
@@ -58,6 +59,7 @@ describe "TraceView::Config" do
|
|
58
59
|
TraceView::Config[:action_view][:log_args].must_equal true
|
59
60
|
TraceView::Config[:active_record][:log_args].must_equal true
|
60
61
|
TraceView::Config[:cassandra][:log_args].must_equal true
|
62
|
+
TraceView::Config[:curb][:log_args].must_equal true
|
61
63
|
TraceView::Config[:dalli][:log_args].must_equal true
|
62
64
|
TraceView::Config[:em_http_request][:log_args].must_equal true
|
63
65
|
TraceView::Config[:excon][:log_args].must_equal true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traceview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Giacomo Lombardo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb
|
122
122
|
- lib/traceview/frameworks/sinatra.rb
|
123
123
|
- lib/traceview/frameworks/sinatra/templates.rb
|
124
|
+
- lib/traceview/inst/curb.rb
|
124
125
|
- lib/traceview/inst/dalli.rb
|
125
126
|
- lib/traceview/inst/em-http-request.rb
|
126
127
|
- lib/traceview/inst/excon.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- test/frameworks/rails4x_test.rb
|
159
160
|
- test/frameworks/sinatra_test.rb
|
160
161
|
- test/instrumentation/cassandra_test.rb
|
162
|
+
- test/instrumentation/curb_test.rb
|
161
163
|
- test/instrumentation/dalli_test.rb
|
162
164
|
- test/instrumentation/em_http_request_test.rb
|
163
165
|
- test/instrumentation/excon_test.rb
|
@@ -245,6 +247,7 @@ test_files:
|
|
245
247
|
- test/instrumentation/redis_hashes_test.rb
|
246
248
|
- test/instrumentation/mongo_test.rb
|
247
249
|
- test/instrumentation/redis_lists_test.rb
|
250
|
+
- test/instrumentation/curb_test.rb
|
248
251
|
- test/instrumentation/memcached_test.rb
|
249
252
|
- test/instrumentation/em_http_request_test.rb
|
250
253
|
- test/instrumentation/rest-client_test.rb
|