faraday-tracer 0.4.0 → 0.5.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/README.md +5 -0
- data/faraday-tracer.gemspec +1 -1
- data/lib/faraday/tracer.rb +25 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb9960d735ab728eeb7ea97317ac3378a4b7111
|
4
|
+
data.tar.gz: b9af0f69baaddb24470e057d34e78fb37d9eaa8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/faraday-tracer.gemspec
CHANGED
data/lib/faraday/tracer.rb
CHANGED
@@ -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
|
+
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-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentracing
|