rack-tracer 0.4.0 → 0.5.0

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
2
  SHA1:
3
- metadata.gz: 86a3c63d2d6db8aec7973f1cb60369d557b6b9ab
4
- data.tar.gz: 37bf5f4419bf129fe3209dd201569ff287d6fff5
3
+ metadata.gz: fcdf093205910aa4ebbf86106ae6929cb357dea6
4
+ data.tar.gz: 05b02d43b23d13608c6290dca697314c13a389fa
5
5
  SHA512:
6
- metadata.gz: c08bb82015ccd64d96048f380736ee1d4b09014c17c83e03b72ff93be014efa5847dd2987dce4c339a0241db77f69dbe0f75dbe462a4db46facacb9b2cc7f423
7
- data.tar.gz: 53de4aa41e736128324fe05050f71d0473e546313c4fdfabfc168cd82891db182faacb2aa0d581056bb7c5595b4b0b13c3e528813064f30dfa73ed13cd06f48a
6
+ metadata.gz: 4b6ca1127b3e86a814e99dd243c059ba282696dfa878e873c9930a43b036ec0f7ff23df63981248ce3cfacaa622d8ce2895aaaad38c75d3412ed3d9461fe0292
7
+ data.tar.gz: e04d7645b819e853ca9cde4b25dd2121aca8717ef20bc85a9457fb8a05f3724b16cd1987c558633bcea6275b54b3e356a2ec64f62e0aa714d867267b375f0704
data/README.md CHANGED
@@ -23,9 +23,11 @@ You can access the created span using
23
23
  env['rack.span']
24
24
  ```
25
25
 
26
- You can also add a start span callback
26
+ You can also add start and finish span callbacks
27
27
  ```ruby
28
- use Rack::Tracer, on_start_span: Proc.new {|span| do_something(span) }
28
+ use Rack::Tracer,
29
+ on_start_span: ->(span) { Thread.current[:root_span] = span },
30
+ on_finish_span: ->(_span) { Thread.current[:root_span] = nil }
29
31
  ```
30
32
 
31
33
  ## Development
@@ -42,4 +44,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/opentr
42
44
  ## License
43
45
 
44
46
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
-
data/lib/rack/tracer.rb CHANGED
@@ -11,12 +11,14 @@ module Rack
11
11
  # @param tracer [OpenTracing::Tracer] A tracer to be used when start_span, and extract
12
12
  # is called.
13
13
  # @param on_start_span [Proc, nil] A callback evaluated after a new span is created.
14
+ # @param on_finish_span [Proc, nil] A callback evaluated after a span is finished.
14
15
  # @param errors [Array<Class>] An array of error classes to be captured by the tracer
15
16
  # as errors. Errors are **not** muted by the middleware, they're re-raised afterwards.
16
- def initialize(app, tracer: OpenTracing.global_tracer, on_start_span: nil, trust_incoming_span: true, errors: [StandardError])
17
+ def initialize(app, tracer: OpenTracing.global_tracer, on_start_span: nil, on_finish_span: nil, trust_incoming_span: true, errors: [StandardError])
17
18
  @app = app
18
19
  @tracer = tracer
19
20
  @on_start_span = on_start_span
21
+ @on_finish_span = on_finish_span
20
22
  @trust_incoming_span = trust_incoming_span
21
23
  @errors = errors
22
24
  end
@@ -36,9 +38,7 @@ module Rack
36
38
  }
37
39
  )
38
40
 
39
- if @on_start_span
40
- @on_start_span.call(span)
41
- end
41
+ @on_start_span.call(span) if @on_start_span
42
42
 
43
43
  env['rack.span'] = span
44
44
 
@@ -54,7 +54,11 @@ module Rack
54
54
  span.log(event: 'error', :'error.object' => e)
55
55
  raise
56
56
  ensure
57
- span.finish
57
+ begin
58
+ span.finish
59
+ ensure
60
+ @on_finish_span.call(span) if @on_finish_span
61
+ end
58
62
  end
59
63
 
60
64
  private
data/rack-tracer.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'rack-tracer'
7
- spec.version = '0.4.0'
7
+ spec.version = '0.5.0'
8
8
  spec.authors = ['SaleMove TechMovers']
9
9
  spec.email = ['techmovers@salemove.com']
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentracing