opentracing-instrumentation 0.1.7 → 0.1.8
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/GEM_VERSION +1 -1
- data/Gemfile.lock +6 -5
- data/README.md +69 -10
- data/lib/opentracing/instrumentation.rb +19 -7
- data/lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb +1 -1
- data/lib/opentracing/instrumentation/thrift.rb +19 -4
- data/lib/opentracing/instrumentation/thrift/traced_protocol.rb +66 -70
- data/lib/opentracing/instrumentation/thrift/traced_protocol_config.rb +30 -0
- data/lib/opentracing/instrumentation/thrift/traced_protocol_factory.rb +1 -1
- data/lib/opentracing/instrumentation/thrift/traced_protocol_operation_name_builder.rb +43 -0
- data/lib/opentracing/instrumentation/thrift/traced_protocol_tags_builder.rb +66 -0
- data/opentracing-instrumentation.gemspec +3 -2
- metadata +23 -7
- data/lib/opentracing/instrumentation/thrift/config.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b58db3616510f2c097cf2586f113a23c28c0ca8232c828f3577f64e09aecdcce
|
4
|
+
data.tar.gz: 3a32e28eae0e9d698ac5f229453d981ac4ed01c3fc78533c89090615759030fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e46ac60a7008279377c14229b7dc7e61cdd14afb63f340e45de25005f1c5259a122c90d35c7493ef5daed703e113dcdbba45ec1604bcb9129999904df7258d6f
|
7
|
+
data.tar.gz: 442f72513f70e1323ed0a04b1a0e1c35e6d903593aadc11a9997b4da1bd395aedf9378065ce102ba703aa9cfdf8ece29a8ec13bf5703849367543a2ebdf5773b
|
data/GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/Gemfile.lock
CHANGED
@@ -18,7 +18,7 @@ GIT
|
|
18
18
|
PATH
|
19
19
|
remote: .
|
20
20
|
specs:
|
21
|
-
opentracing-instrumentation (0.1.
|
21
|
+
opentracing-instrumentation (0.1.8)
|
22
22
|
json
|
23
23
|
opentracing (~> 0.5.0)
|
24
24
|
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
coderay (1.1.2)
|
42
42
|
concurrent-ruby (1.1.6)
|
43
43
|
diff-lcs (1.3)
|
44
|
-
faraday (0.
|
44
|
+
faraday (1.0.1)
|
45
45
|
multipart-post (>= 1.2, < 3)
|
46
46
|
hutch (0.26.0)
|
47
47
|
activesupport (>= 4.2, < 6)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
pry (~> 0.10)
|
69
69
|
rack (2.2.2)
|
70
70
|
rainbow (3.0.0)
|
71
|
-
rake (
|
71
|
+
rake (13.0.1)
|
72
72
|
redis (3.3.5)
|
73
73
|
rexml (3.2.4)
|
74
74
|
rspec (3.9.0)
|
@@ -105,15 +105,16 @@ PLATFORMS
|
|
105
105
|
ruby
|
106
106
|
|
107
107
|
DEPENDENCIES
|
108
|
+
activesupport (~> 5.2)
|
108
109
|
bson (~> 4.0)
|
109
110
|
bundler (= 2.1.4)
|
110
111
|
bunny (~> 2.0)
|
111
|
-
faraday (~> 0.
|
112
|
+
faraday (~> 1.0.1)
|
112
113
|
hutch (~> 0.26.0)
|
113
114
|
opentracing-instrumentation!
|
114
115
|
pry-byebug (~> 3.8)
|
115
116
|
rack (~> 2.2.2)
|
116
|
-
rake (~>
|
117
|
+
rake (~> 13.0)
|
117
118
|
redis (~> 3.3.5)
|
118
119
|
rspec (~> 3.0)
|
119
120
|
rubocop (~> 0.80.0)
|
data/README.md
CHANGED
@@ -1,38 +1,97 @@
|
|
1
1
|
# Opentracing::Instrumentation
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem provides instrumentation for some popular gems. Its gem not use
|
4
|
+
monkey patching, instrumentation provided only as middleware or wrappers.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
8
|
Add this line to your application's Gemfile:
|
10
9
|
|
11
10
|
```ruby
|
12
|
-
gem 'opentracing-instrumentation'
|
11
|
+
gem 'opentracing-instrumentation', require: 'opentracing/instrumentation'
|
13
12
|
```
|
14
13
|
|
15
14
|
And then execute:
|
16
15
|
|
17
|
-
|
16
|
+
```bash
|
17
|
+
bundle
|
18
|
+
```
|
18
19
|
|
19
20
|
Or install it yourself as:
|
20
21
|
|
21
|
-
|
22
|
+
```bash
|
23
|
+
gem install opentracing-instrumentation
|
24
|
+
```
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
[Documentation](https://rubydoc.info/gems/opentracing-instrumentation/)
|
29
|
+
|
30
|
+
### Gems
|
31
|
+
|
32
|
+
#### [bunny](https://github.com/ruby-amqp/bunny)
|
33
|
+
|
34
|
+
Documentation [OpenTracing::Instrumentation::Bunny](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Bunny)
|
35
|
+
|
36
|
+
Tested versions: `2.14.3`
|
37
|
+
|
38
|
+
#### [faraday](https://github.com/lostisland/faraday)
|
39
|
+
|
40
|
+
Documentation: [OpenTracing::Instrumentation::Faraday](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Faraday)
|
41
|
+
|
42
|
+
Tested versions: `0.9.2`, `1.0.1`
|
43
|
+
|
44
|
+
#### [hutch](https://github.com/gocardless/hutch)
|
45
|
+
|
46
|
+
Documentation: [OpenTracing::Instrumentation::Hutch](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Hutch)
|
47
|
+
|
48
|
+
Tested versions: `0.21`, `0.26`
|
49
|
+
|
50
|
+
#### [mongo](https://github.com/mongodb/mongo-ruby-driver)
|
51
|
+
|
52
|
+
Documentation: [OpenTracing::Instrumentation::Mongo](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Mongo)
|
53
|
+
|
54
|
+
Tested versions: `2.8`
|
55
|
+
|
56
|
+
#### [rack](https://github.com/rack/rack)
|
57
|
+
|
58
|
+
Documentation: [OpenTracing::Instrumentation::Rack](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Rack)
|
59
|
+
|
60
|
+
Tested versions: `2.0`, `2.2`
|
61
|
+
|
62
|
+
#### [redis](https://github.com/redis/redis-rb)
|
63
|
+
|
64
|
+
Documentation: [OpenTracing::Instrumentation::Redis](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Redis)
|
65
|
+
|
66
|
+
Tested versions: `3.3.5`
|
67
|
+
|
68
|
+
#### [sidekiq](https://github.com/mperham/sidekiq)
|
69
|
+
|
70
|
+
Documentation: [OpenTracing::Instrumentation::Sidekiq](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Sidekiq)
|
71
|
+
|
72
|
+
Tested versions `4.2`
|
73
|
+
|
74
|
+
#### [sinatra](https://github.com/sinatra/sinatra)
|
75
|
+
|
76
|
+
Documentation: [OpenTracing::Instrumentation::Sinatra](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Sinatra)
|
77
|
+
|
78
|
+
Tested version: `2.0.8`
|
79
|
+
|
80
|
+
#### [thrift](https://github.com/apache/thrift/tree/master/lib/rb)
|
81
|
+
|
82
|
+
Documentation: [OpenTracing::Instrumentation::Thrift](https://rubydoc.info/gems/opentracing-instrumentation/OpenTracing/Instrumentation/Thrift)
|
83
|
+
|
84
|
+
Tested versions: `0.11.0`
|
26
85
|
|
27
86
|
## Development
|
28
87
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
88
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests and lints. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
89
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `
|
90
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `GEM_VERSION`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
91
|
|
33
92
|
## Contributing
|
34
93
|
|
35
|
-
Bug reports and pull requests are welcome on
|
94
|
+
Bug reports and pull requests are welcome on [GitLab](https://gitlab.com/c0va23/opentracing-instrumentation).
|
36
95
|
|
37
96
|
## License
|
38
97
|
|
@@ -7,19 +7,31 @@ module OpenTracing
|
|
7
7
|
# popular Ruby gems.
|
8
8
|
#
|
9
9
|
# All instrumentations modules is lazy loaded (via autoload).
|
10
|
+
#
|
11
|
+
# {file:README.md}
|
12
|
+
#
|
13
|
+
# @see Bunny
|
14
|
+
# @see Faraday
|
15
|
+
# @see Hutch
|
16
|
+
# @see Mongo
|
17
|
+
# @see Rack
|
18
|
+
# @see Redis
|
19
|
+
# @see Sidekiq
|
20
|
+
# @see Sinatra
|
21
|
+
# @see Thrift
|
10
22
|
module Instrumentation
|
11
23
|
class Error < StandardError; end
|
12
24
|
|
13
|
-
autoload :
|
25
|
+
autoload :Bunny, 'opentracing/instrumentation/bunny'
|
14
26
|
autoload :Common, 'opentracing/instrumentation/common'
|
15
|
-
autoload :Rack, 'opentracing/instrumentation/rack'
|
16
|
-
autoload :Mongo, 'opentracing/instrumentation/mongo'
|
17
27
|
autoload :Faraday, 'opentracing/instrumentation/faraday'
|
18
|
-
autoload :
|
19
|
-
autoload :
|
28
|
+
autoload :Hutch, 'opentracing/instrumentation/hutch'
|
29
|
+
autoload :Mongo, 'opentracing/instrumentation/mongo'
|
30
|
+
autoload :ObjectWrapper, 'opentracing/instrumentation/object_wrapper'
|
31
|
+
autoload :Rack, 'opentracing/instrumentation/rack'
|
20
32
|
autoload :Redis, 'opentracing/instrumentation/redis'
|
21
33
|
autoload :Sidekiq, 'opentracing/instrumentation/sidekiq'
|
22
|
-
autoload :
|
23
|
-
autoload :
|
34
|
+
autoload :Sinatra, 'opentracing/instrumentation/sinatra'
|
35
|
+
autoload :Thrift, 'opentracing/instrumentation/thrift'
|
24
36
|
end
|
25
37
|
end
|
@@ -1,15 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'thrift'
|
4
|
+
|
3
5
|
module OpenTracing
|
4
6
|
module Instrumentation
|
5
7
|
# OpenTracing instrumentation for Thrift client and server
|
6
8
|
module Thrift
|
7
|
-
|
8
|
-
|
9
|
+
module_path = 'opentracing/instrumentation/thrift'
|
10
|
+
|
11
|
+
MESSAGE_TYPES = {
|
12
|
+
::Thrift::MessageTypes::CALL => 'CALL',
|
13
|
+
::Thrift::MessageTypes::REPLY => 'REPLY',
|
14
|
+
::Thrift::MessageTypes::EXCEPTION => 'EXCEPTION',
|
15
|
+
::Thrift::MessageTypes::ONEWAY => 'ONEWAY',
|
16
|
+
}.freeze
|
17
|
+
|
9
18
|
autoload :TracedProtocol,
|
10
|
-
'
|
19
|
+
module_path + '/traced_protocol'
|
20
|
+
autoload :TracedProtocolConfig,
|
21
|
+
module_path + '/traced_protocol_config'
|
11
22
|
autoload :TracedProtocolFactory,
|
12
|
-
'
|
23
|
+
module_path + '/traced_protocol_factory'
|
24
|
+
autoload :TracedProtocolOperationNameBuilder,
|
25
|
+
module_path + '/traced_protocol_operation_name_builder'
|
26
|
+
autoload :TracedProtocolTagsBuilder,
|
27
|
+
module_path + '/traced_protocol_tags_builder'
|
13
28
|
end
|
14
29
|
end
|
15
30
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'thrift'
|
4
|
-
|
5
3
|
module OpenTracing
|
6
4
|
module Instrumentation
|
7
5
|
module Thrift
|
@@ -28,116 +26,114 @@ module OpenTracing
|
|
28
26
|
|
29
27
|
include ::Thrift::ProtocolDecorator
|
30
28
|
|
31
|
-
|
29
|
+
WRITE_DIRECTION = 'write'
|
30
|
+
READ_DIRECTION = 'read'
|
32
31
|
|
33
|
-
def initialize(protocol, config:
|
34
|
-
|
35
|
-
@config = config
|
32
|
+
def initialize(protocol, config: TracedProtocolConfig.new)
|
33
|
+
super(protocol)
|
34
|
+
@config = config.dup
|
35
|
+
yield @config if block_given?
|
36
|
+
@static_tags = config.tags_builder.build_static_tags(protocol)
|
36
37
|
end
|
37
38
|
|
38
39
|
def write_message_begin(name, type, seqid)
|
39
|
-
|
40
|
-
|
41
|
-
write_operation_name,
|
42
|
-
tags: request_tags,
|
43
|
-
)
|
44
|
-
handler_error(write_scope.span, type)
|
40
|
+
self.write_scope = \
|
41
|
+
safe_start_active_span(WRITE_DIRECTION, name, type)
|
45
42
|
|
43
|
+
# Call protocol instaed super, beacaus ProtocolDecorator do not
|
44
|
+
# pass arguments to protocol.write_message_begin
|
46
45
|
protocol.write_message_begin(name, type, seqid)
|
46
|
+
rescue StandardError => e
|
47
|
+
write_error(write_scope&.span, e)
|
48
|
+
safe_close_span(write_scope)
|
49
|
+
raise e
|
47
50
|
end
|
48
51
|
|
49
52
|
def write_message_end
|
50
53
|
super
|
51
|
-
|
54
|
+
ensure
|
55
|
+
safe_close_span(write_scope)
|
52
56
|
end
|
53
57
|
|
54
58
|
def read_message_begin
|
55
|
-
|
59
|
+
start_time = Time.now.utc
|
56
60
|
|
57
61
|
name, type, rseqid = super
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
self.read_scope = \
|
64
|
+
safe_start_active_span(READ_DIRECTION, name, type,
|
65
|
+
start_time: start_time)
|
62
66
|
|
63
67
|
[name, type, rseqid]
|
64
68
|
end
|
65
69
|
|
66
70
|
def read_message_end
|
67
71
|
super
|
68
|
-
|
72
|
+
ensure
|
73
|
+
safe_close_span(read_scope)
|
69
74
|
end
|
70
75
|
|
71
76
|
private
|
72
77
|
|
78
|
+
attr_reader :static_tags
|
79
|
+
attr_reader :protocol
|
80
|
+
|
73
81
|
def_delegators :@config,
|
74
82
|
:tracer,
|
75
|
-
:
|
76
|
-
:
|
83
|
+
:tags_builder,
|
84
|
+
:operation_name_builder,
|
85
|
+
:error_writer,
|
86
|
+
:logger
|
77
87
|
|
78
88
|
attr_accessor :write_scope,
|
79
89
|
:read_scope
|
80
90
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
def write_span_tags(span, tags)
|
99
|
-
tags.each do |tag, value|
|
100
|
-
span.set_tag(tag, value)
|
101
|
-
end
|
91
|
+
def safe_start_active_span(
|
92
|
+
direction,
|
93
|
+
name,
|
94
|
+
type,
|
95
|
+
start_time: Time.now.utc
|
96
|
+
)
|
97
|
+
operation_name = build_operation_name(direction, name, type)
|
98
|
+
request_tags = build_tags(name, type)
|
99
|
+
|
100
|
+
tracer.start_active_span(
|
101
|
+
operation_name,
|
102
|
+
tags: request_tags,
|
103
|
+
start_time: start_time,
|
104
|
+
)
|
105
|
+
rescue StandardError => e
|
106
|
+
logger&.error(e)
|
102
107
|
end
|
103
108
|
|
104
|
-
def
|
105
|
-
|
106
|
-
{
|
107
|
-
'thrift.method' => method,
|
108
|
-
'thrift.service_name' => service_name,
|
109
|
-
'thrift.type' => MESSAGE_TYPES[type],
|
110
|
-
'thrift.multiplexed' => !service_name.nil?,
|
111
|
-
'thrift.protocol' => protocol_name,
|
112
|
-
'thrift.transport' => transport_name,
|
113
|
-
}.compact
|
114
|
-
end
|
109
|
+
def safe_close_span(scope)
|
110
|
+
return if scope.nil?
|
115
111
|
|
116
|
-
|
117
|
-
|
112
|
+
scope.close
|
113
|
+
rescue StandardError => e
|
114
|
+
logger&.error(e)
|
118
115
|
end
|
119
116
|
|
120
|
-
def
|
121
|
-
|
117
|
+
def write_error(span, exception)
|
118
|
+
return if span.nil?
|
122
119
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
else
|
127
|
-
transport.class.to_s
|
128
|
-
end
|
120
|
+
error_writer.write_error(span, exception)
|
121
|
+
rescue StandardError => e
|
122
|
+
logger&.error(e)
|
129
123
|
end
|
130
124
|
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
125
|
+
def build_operation_name(direction, name, type)
|
126
|
+
operation_name_builder.build_operation_name(
|
127
|
+
direction,
|
128
|
+
name,
|
129
|
+
type,
|
130
|
+
)
|
135
131
|
end
|
136
132
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
133
|
+
def build_tags(name, type)
|
134
|
+
static_tags
|
135
|
+
.merge(tags_builder.build_message_tags(name, type))
|
136
|
+
.compact
|
141
137
|
end
|
142
138
|
end
|
143
139
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenTracing
|
4
|
+
module Instrumentation
|
5
|
+
module Thrift
|
6
|
+
# Config for TracedProtocol
|
7
|
+
class TracedProtocolConfig
|
8
|
+
attr_accessor :tracer,
|
9
|
+
:tags_builder,
|
10
|
+
:operation_name_builder,
|
11
|
+
:error_writer,
|
12
|
+
:logger
|
13
|
+
|
14
|
+
def initialize(
|
15
|
+
tracer: OpenTracing.global_tracer,
|
16
|
+
tags_builder: TracedProtocolTagsBuilder.new,
|
17
|
+
operation_name_builder: TracedProtocolOperationNameBuilder.new,
|
18
|
+
error_writer: Common::ErrorWriter.new,
|
19
|
+
logger: nil
|
20
|
+
)
|
21
|
+
@tracer = tracer
|
22
|
+
@tags_builder = tags_builder
|
23
|
+
@operation_name_builder = operation_name_builder
|
24
|
+
@error_writer = error_writer
|
25
|
+
@logger = logger
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -28,7 +28,7 @@ module OpenTracing
|
|
28
28
|
# )
|
29
29
|
# run thrift_app
|
30
30
|
class TracedProtocolFactory < ::Thrift::BaseProtocolFactory
|
31
|
-
def initialize(protocol_factory, config:
|
31
|
+
def initialize(protocol_factory, config: TracedProtocolConfig.new)
|
32
32
|
@protocol_factory = protocol_factory
|
33
33
|
@config = config
|
34
34
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thrift'
|
4
|
+
|
5
|
+
module OpenTracing
|
6
|
+
module Instrumentation
|
7
|
+
module Thrift
|
8
|
+
# Build operation name for TracedProtocol
|
9
|
+
class TracedProtocolOperationNameBuilder
|
10
|
+
DEFAULT_OPERATION_NAME_PATTERN = \
|
11
|
+
'thrift(direction=%<direction>s, name=%<name>s, type=%<type>s)'
|
12
|
+
|
13
|
+
attr_reader :operation_name_pattern
|
14
|
+
|
15
|
+
# @param operation_name_pattern [String]
|
16
|
+
def initialize(
|
17
|
+
operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN
|
18
|
+
)
|
19
|
+
@operation_name_pattern = operation_name_pattern
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param direction [String] should be 'write' or 'read'
|
23
|
+
# @param name [String] method name. Example: 'Service:method'
|
24
|
+
# @param type [Integer] message type, See ::Thrift::MessageTypes
|
25
|
+
# @return [String] formated operation name
|
26
|
+
def build_operation_name(direction, name, type)
|
27
|
+
format_args = build_format_args(direction, name, type)
|
28
|
+
format(operation_name_pattern, **format_args)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def build_format_args(direction, name, type)
|
34
|
+
{
|
35
|
+
direction: direction,
|
36
|
+
name: name,
|
37
|
+
type: MESSAGE_TYPES[type],
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thrift'
|
4
|
+
|
5
|
+
module OpenTracing
|
6
|
+
module Instrumentation
|
7
|
+
module Thrift
|
8
|
+
# TagsBuilder for TracedProtocol
|
9
|
+
class TracedProtocolTagsBuilder
|
10
|
+
def build_message_tags(name, type)
|
11
|
+
service_name, method = parse_message_name(name)
|
12
|
+
{
|
13
|
+
'thrift.method' => method,
|
14
|
+
'thrift.service_name' => service_name,
|
15
|
+
'thrift.multiplexed' => !service_name.nil?,
|
16
|
+
'thrift.type' => MESSAGE_TYPES[type],
|
17
|
+
}.merge(error_tags(type))
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_static_tags(protocol)
|
21
|
+
transport = protocol.trans
|
22
|
+
{
|
23
|
+
'thrift.protocol' => build_protocol_name(protocol),
|
24
|
+
'thrift.transport' => build_transport_name(transport),
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
NAME_PATTER = /((?<service_name>\w+):)?(?<method>\w+)/.freeze
|
31
|
+
SERVICE_NAME_PART = 'service_name'
|
32
|
+
METHOD_PART = 'method'
|
33
|
+
|
34
|
+
def parse_message_name(name)
|
35
|
+
name_matches = NAME_PATTER.match(name)
|
36
|
+
method = name_matches[METHOD_PART]
|
37
|
+
service_name = name_matches[SERVICE_NAME_PART]
|
38
|
+
[service_name, method]
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_protocol_name(protocol)
|
42
|
+
protocol.class.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_transport_name(transport)
|
46
|
+
inner_transport = transport.instance_variable_get(:@transport)
|
47
|
+
|
48
|
+
if inner_transport
|
49
|
+
inner_transport_name = build_transport_name(inner_transport)
|
50
|
+
"#{transport.class}(#{inner_transport_name})"
|
51
|
+
else
|
52
|
+
transport.class.to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def error_tags(type)
|
57
|
+
return {} if type != ::Thrift::MessageTypes::EXCEPTION
|
58
|
+
|
59
|
+
{
|
60
|
+
'error' => true,
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -27,13 +27,14 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_runtime_dependency 'json'
|
28
28
|
spec.add_runtime_dependency 'opentracing', '~> 0.5.0'
|
29
29
|
|
30
|
+
spec.add_development_dependency 'activesupport', '~> 5.2'
|
30
31
|
spec.add_development_dependency 'bson', '~> 4.0'
|
31
32
|
spec.add_development_dependency 'bundler', File.read('.BUNDLER_VERSION').strip
|
32
33
|
spec.add_development_dependency 'bunny', '~> 2.0'
|
33
|
-
spec.add_development_dependency 'faraday', '~> 0.
|
34
|
+
spec.add_development_dependency 'faraday', '~> 1.0.1'
|
34
35
|
spec.add_development_dependency 'hutch', '~> 0.26.0'
|
35
36
|
spec.add_development_dependency 'rack', '~> 2.2.2'
|
36
|
-
spec.add_development_dependency 'rake', '~>
|
37
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
37
38
|
spec.add_development_dependency 'redis', '~> 3.3.5'
|
38
39
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
40
|
spec.add_development_dependency 'rubocop', '~> 0.80.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentracing-instrumentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fedorenko Dmitrij
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.2'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bson
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +100,14 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
103
|
+
version: 1.0.1
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
110
|
+
version: 1.0.1
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: hutch
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +142,14 @@ dependencies:
|
|
128
142
|
requirements:
|
129
143
|
- - "~>"
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '13.0'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '13.0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: redis
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,9 +290,11 @@ files:
|
|
276
290
|
- lib/opentracing/instrumentation/sinatra.rb
|
277
291
|
- lib/opentracing/instrumentation/sinatra/trace_middleware.rb
|
278
292
|
- lib/opentracing/instrumentation/thrift.rb
|
279
|
-
- lib/opentracing/instrumentation/thrift/config.rb
|
280
293
|
- lib/opentracing/instrumentation/thrift/traced_protocol.rb
|
294
|
+
- lib/opentracing/instrumentation/thrift/traced_protocol_config.rb
|
281
295
|
- lib/opentracing/instrumentation/thrift/traced_protocol_factory.rb
|
296
|
+
- lib/opentracing/instrumentation/thrift/traced_protocol_operation_name_builder.rb
|
297
|
+
- lib/opentracing/instrumentation/thrift/traced_protocol_tags_builder.rb
|
282
298
|
- lib/opentracing/instrumentation/version.rb
|
283
299
|
- opentracing-instrumentation.gemspec
|
284
300
|
homepage: https://gitlab.com/c0va23/ruby-opentracing-instrumentation.
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenTracing
|
4
|
-
module Instrumentation
|
5
|
-
module Thrift
|
6
|
-
# Config for TracedProtocol
|
7
|
-
class Config
|
8
|
-
attr_accessor :tracer,
|
9
|
-
:write_operation_name,
|
10
|
-
:read_operation_name
|
11
|
-
|
12
|
-
def initialize(
|
13
|
-
tracer: OpenTracing.global_tracer,
|
14
|
-
write_operation_name: 'thrift_write',
|
15
|
-
read_operation_name: 'thrift_read'
|
16
|
-
)
|
17
|
-
@tracer = tracer
|
18
|
-
@write_operation_name = write_operation_name
|
19
|
-
@read_operation_name = read_operation_name
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|