nethttp-instrumentation 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53453b5d5f7a25b9a8d6121b43bd1b3afeda4432
4
- data.tar.gz: 633f2f1db3d990b1d14e76a18215e94a8601492d
3
+ metadata.gz: 64465c0ccfe8cf65d33980af58f6eef1f23df52f
4
+ data.tar.gz: f56cbecb92dd1cbbca5890f786a9d247b2b2109b
5
5
  SHA512:
6
- metadata.gz: 49fe7ec37a4a27239aa63f0becbdb0b952b74a0a0e3d463c5c59636228d1f6af6c94f8eae47129cafa59586ce4c1f793c500a1996f93db17d3e9224f9858720c
7
- data.tar.gz: 2ccab222cbabc3107f1301288db37b9e225ced489a1fae8164cef97c989de44c95c563d15e735e9fa504ad51477f2e4abbef93a9dbaf7ed9845f15f2a7fda085
6
+ metadata.gz: afa8417fe2d57d1c321d16fee9769cf67ad7906ef377c80fb40b8b21f3c66c4d727d4844fafa803ec04b6cb40e4a443eb49d7303d3c85e913edab465a74600ce
7
+ data.tar.gz: f880d7e606c7c5324b8f417aa40d4d57fb5756c4a8109b295c9109668ca0505c863154cf0a4c7d84c89cf29dbbb6aef8a66dd932eb7a83b37499234fa9624972
data/README.md CHANGED
@@ -11,7 +11,7 @@ This gem automatically traces all requests made with Net::HTTP.
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'nethttp-tracer'
14
+ gem 'nethttp-instrumentation'
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -20,7 +20,7 @@ And then execute:
20
20
 
21
21
  Or install it yourself as:
22
22
 
23
- $ gem install nethttp-tracer
23
+ $ gem install nethttp-instrumentation
24
24
 
25
25
  ## Usage
26
26
 
@@ -29,11 +29,33 @@ Set an OpenTracing-compatible tracer, such as ['jaeger-client'](https://github.c
29
29
  Before making any requests, configure the tracer:
30
30
 
31
31
  ```ruby
32
- require 'net/http/tracer'
32
+ require 'net/http/instrumentation'
33
33
 
34
- Net::Http::Tracer.instrument
34
+ Net::Http::Instrumentation.instrument
35
35
  ```
36
36
 
37
+ `instrument` takes two parameters:
38
+ - `tracer`: the OpenTracing tracer to use to trace requests. Default: OpenTracing.global_tracer
39
+ - `ignore_request`: a bool or block to determine whether or not a given request
40
+ should be traced.
41
+
42
+ `ignore_requests` should be configured to avoid tracing requests from the tracer
43
+ if it uses Net::HTTP to send spans. For example:
44
+
45
+ ```ruby
46
+ # in the thread sending spans
47
+ Thread.current[:http_sender_thread] = true
48
+ ...
49
+
50
+ # configure the instrumentation
51
+ Net::Http::Instrumentation.instrument(ignore_request: -> { Thread.current[:http_sender_thread] })
52
+ ```
53
+
54
+ To remove instrumentation:
55
+
56
+ ```ruby
57
+ Net::Http::Instrumentation.remove
58
+
37
59
  The spans will be given a name consisting of the HTTP method and request path.
38
60
 
39
61
  ## Development
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  module Http
3
3
  module Instrumentation
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -7,12 +7,26 @@ module Net
7
7
 
8
8
  class << self
9
9
 
10
- attr_accessor :ignore_request
10
+ attr_accessor :ignore_request, :tracer
11
11
 
12
- def instrument(ignore_request: nil)
12
+ def instrument(tracer: OpenTracing.global_tracer, ignore_request: nil)
13
13
  @ignore_request = ignore_request
14
+ @tracer = tracer
14
15
 
15
- patch_request
16
+ patch_request if !@instrumented
17
+ @instrumented = true
18
+ end
19
+
20
+ def remove
21
+ return if !@instrumented
22
+
23
+ ::Net::HTTP.module_eval do
24
+ remove_method :request
25
+ alias_method :request, :request_original
26
+ remove_method :request_original
27
+ end
28
+
29
+ @instrumented = false
16
30
  end
17
31
 
18
32
  def patch_request
@@ -36,7 +50,7 @@ module Net
36
50
  "peer.host" => @address,
37
51
  "peer.port" => @port,
38
52
  }
39
- OpenTracing.global_tracer.start_active_span("net_http.request", tags: tags) do |scope|
53
+ ::Net::Http::Instrumentation.tracer.start_active_span("net_http.request", tags: tags) do |scope|
40
54
  # inject the trace so it's available to the remote service
41
55
  OpenTracing.inject(scope.span.context, OpenTracing::FORMAT_RACK, req)
42
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nethttp-instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashwin Chandrasekar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-13 00:00:00.000000000 Z
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentracing