faraday-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: 64f607d713975def48233f8a8308a896dbce4fd3
4
- data.tar.gz: 0454f69a116f4fdfbe2f74126a5db084c05898f6
3
+ metadata.gz: ebb9960d735ab728eeb7ea97317ac3378a4b7111
4
+ data.tar.gz: b9af0f69baaddb24470e057d34e78fb37d9eaa8d
5
5
  SHA512:
6
- metadata.gz: fcec16b4cc9f6165c7570da33cc12f5fe2cb545b5250c95a3d12ffd1a8e8cd6c0d36763fb9813cecb62e9b94999b00ae5be4cd3a9cfbafd9abcf4f89df6af4d7
7
- data.tar.gz: 796d59ae3ab0758dfca00a98cfec28cee08a90070bc07047edbc4889934832afc8608d88fe0116da06f49b89850c8d0287d8150dcebe28364f416fa49eedd774
6
+ metadata.gz: 30bd6106865461b9fff352d085ed182fc217b1cb9194d9f717bc3cee8cb7f5aa8165cd163cda261d222b6b791e33d7ef5ca2b44540d36affdaab1d8db8f471b3
7
+ data.tar.gz: 27192e04ec6ce63b7cea72c362e9321e74b91b089fc813d86aa7df984b4caf5fabf56ea4fc380cd541d99010f3e6b3c75a44ae55af37c3b9438415d932552794
data/README.md CHANGED
@@ -61,6 +61,11 @@ conn = Faraday.new(url: 'http://localhost:3000/') do |faraday|
61
61
  end
62
62
  ```
63
63
 
64
+
65
+ ### Service name
66
+
67
+ It's possible to define the remote service name by using `:service_name` option.
68
+
64
69
  ## Development
65
70
 
66
71
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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 = 'faraday-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
 
@@ -9,26 +9,24 @@ module Faraday
9
9
  # @param span [Span, SpanContext, Proc, nil] SpanContext that acts as a parent to
10
10
  # the newly-started by the middleware Span. If a Proc is provided, its
11
11
  # evaluated during the call method invocation.
12
+ # @param service_name [String, nil] Remote service name (for some
13
+ # unspecified definition of "service")
12
14
  # @param tracer [OpenTracing::Tracer] A tracer to be used when start_span, and inject
13
15
  # is called.
14
16
  # @param errors [Array<Class>] An array of error classes to be captured by the tracer
15
17
  # as errors. Errors are **not** muted by the middleware.
16
- def initialize(app, span: nil, tracer: OpenTracing.global_tracer, errors: [StandardError])
18
+ def initialize(app, span: nil, service_name: nil, tracer: OpenTracing.global_tracer, errors: [StandardError])
17
19
  super(app)
18
20
  @tracer = tracer
19
21
  @parent_span = span
22
+ @service_name = service_name
20
23
  @errors = errors
21
24
  end
22
25
 
23
26
  def call(env)
24
27
  span = @tracer.start_span(env[:method].to_s.upcase,
25
28
  child_of: parent_span(env),
26
- tags: {
27
- 'component' => 'faraday',
28
- 'span.kind' => 'client',
29
- 'http.method' => env[:method],
30
- 'http.url' => env[:url].to_s
31
- }
29
+ tags: prepare_tags(env)
32
30
  )
33
31
  @tracer.inject(span.context, OpenTracing::FORMAT_RACK, env[:request_headers])
34
32
  @app.call(env).on_complete do |response|
@@ -52,5 +50,25 @@ module Faraday
52
50
  span.respond_to?(:call) ? span.call : span
53
51
  end
54
52
  end
53
+
54
+ def prepare_tags(env)
55
+ tags = {
56
+ 'component' => 'faraday',
57
+ 'span.kind' => 'client',
58
+ 'http.method' => env[:method],
59
+ 'http.url' => env[:url].to_s,
60
+ }
61
+
62
+ if (service_name = peer_service(env))
63
+ tags['peer.service'] = service_name
64
+ end
65
+
66
+ tags
67
+ end
68
+
69
+ def peer_service(env)
70
+ context = env.request.context
71
+ context.is_a?(Hash) && context[:service_name] || @service_name
72
+ end
55
73
  end
56
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-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-06-25 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentracing